summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-02-12 16:03:45 +0100
committerKay Sievers <kay@vrfy.org>2013-02-12 16:08:14 +0100
commit38d70045d15d5bc463c097a6983a23502ff8a837 (patch)
treeaa8a38e641e41b1e057e63108e560bb7f2638f1e /src/udev
parenta0ec302b9309bc56f6bed6162e47ad6c27165747 (diff)
udev: use unique names for temporary files created in /dev
On Tue, Feb 12, 2013 at 2:18 PM, Robert Milasan <rmilasan@suse.com> wrote: > Under some circumstances udev mixed with multipath fails: > > udevd-work[1376]: > symlink(../../sdk, /dev/disk/by-id/scsi-36005076305ffc0670000000000002842.udev-tmp) > failed: File exists udevd-work[1432]: > rename(/dev/disk/by-id/scsi-36005076305ffc0850000000000000a88.udev-tmp, /dev/disk/by-id/scsi-36005076305ffc0850000000000000a88) > failed: No such file or directory > > This is non-fatal, but there is no point of created the symlink or > renaming the symlink if it already exists. > > Reference: https://bugzilla.novell.com/show_bug.cgi?id=791503 It looke like this now: stat("/dev/disk/by-id", {st_mode=S_IFDIR|0755, st_size=80, ...}) = 0 symlink("../../sda", "/dev/disk/by-id/ata-INTEL...N.tmp-b8:0") = 0 rename("/dev/disk/by-id/ata-INTEL...N.tmp-b8:0", "/dev/disk/by-id/ata-INTEL...N") = 0
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udev-node.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index bce4cfe433..363cee1d1c 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -31,15 +31,13 @@
#include "udev.h"
-#define TMP_FILE_EXT ".udev-tmp"
-
-static int node_symlink(struct udev *udev, const char *node, const char *slink)
+static int node_symlink(struct udev_device *dev, const char *node, const char *slink)
{
struct stat stats;
char target[UTIL_PATH_SIZE];
char *s;
size_t l;
- char slink_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)];
+ char slink_tmp[UTIL_PATH_SIZE + 32];
int i = 0;
int tail = 0;
int err = 0;
@@ -101,7 +99,7 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink)
}
log_debug("atomically replace '%s'\n", slink);
- strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL);
+ strscpyl(slink_tmp, sizeof(slink_tmp), slink, ".tmp-", udev_device_get_id_filename(dev), NULL);
unlink(slink_tmp);
do {
err = mkdir_parents_label(slink_tmp, 0755);
@@ -204,7 +202,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add)
util_delete_path(udev, slink);
} else {
log_debug("creating link '%s' to '%s'\n", slink, target);
- node_symlink(udev, target, slink);
+ node_symlink(dev, target, slink);
}
if (add) {
@@ -298,7 +296,6 @@ out:
void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, gid_t gid)
{
- struct udev *udev = udev_device_get_udev(dev);
char filename[UTIL_PATH_SIZE];
struct udev_list_entry *list_entry;
@@ -312,7 +309,7 @@ void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid,
snprintf(filename, sizeof(filename), "/dev/%s/%u:%u",
strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char",
major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
- node_symlink(udev, udev_device_get_devnode(dev), filename);
+ node_symlink(dev, udev_device_get_devnode(dev), filename);
/* create/update symlinks, add symlinks to name index */
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev))