diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2009-09-10 02:08:05 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2009-09-10 02:08:05 +0200 |
commit | b6a2637524e4b94ba51abcf5ee42f3676c9755ed (patch) | |
tree | 99bf9c78ad5309db49f95eb4aa2650f8af56e393 | |
parent | 676d294c23cf999ac7d192b058476f91242550c0 (diff) |
put util_create_path() and file creastion in a retry loop
On 8/29/09, Florian Zumbiehl <florz@florz.de> wrote:
> Could it happen that > util_create_path() and util_delete_path()
> do run in parallel for > the same directory? After all, util_create_path()
> does handle > the case where creation of the directory happens in parallel
> to it running, so it doesn't seem all that unlikely to me ...
-rw-r--r-- | libudev/libudev-queue-private.c | 15 | ||||
-rw-r--r-- | udev/udev-node.c | 42 |
2 files changed, 38 insertions, 19 deletions
diff --git a/libudev/libudev-queue-private.c b/libudev/libudev-queue-private.c index d9f7a67d18..4e67a1f9d0 100644 --- a/libudev/libudev-queue-private.c +++ b/libudev/libudev-queue-private.c @@ -45,9 +45,9 @@ #include <fcntl.h> #include <dirent.h> #include <limits.h> +#include <errno.h> #include <sys/stat.h> #include <sys/types.h> -#include <assert.h> #include "libudev.h" #include "libudev-private.h" @@ -396,6 +396,7 @@ static void update_failed(struct udev_queue_export *udev_queue_export, { struct udev *udev = udev_device_get_udev(udev_device); char filename[UTIL_PATH_SIZE]; + int err; if (state != DEVICE_FAILED && udev_queue_export->failed_count == 0) return; @@ -408,10 +409,14 @@ static void update_failed(struct udev_queue_export *udev_queue_export, case DEVICE_FAILED: /* record event in the failed directory */ udev_queue_export->failed_count++; - util_create_path(udev, filename); - udev_selinux_setfscreatecon(udev, filename, S_IFLNK); - symlink(udev_device_get_devpath(udev_device), filename); - udev_selinux_resetfscreatecon(udev); + do { + util_create_path(udev, filename); + udev_selinux_setfscreatecon(udev, filename, S_IFLNK); + err = symlink(udev_device_get_devpath(udev_device), filename); + if (err != 0) + err = errno; + udev_selinux_resetfscreatecon(udev); + } while (err == ENOENT); break; case DEVICE_QUEUED: diff --git a/udev/udev-node.c b/udev/udev-node.c index 3685485eb1..39bec3e166 100644 --- a/udev/udev-node.c +++ b/udev/udev-node.c @@ -77,10 +77,14 @@ int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mod } } else { info(udev, "mknod(%s, %#o, (%u,%u))\n", file, mode, major(devnum), minor(devnum)); - util_create_path(udev, file); - udev_selinux_setfscreatecon(udev, file, mode); - err = mknod(file, mode, devnum); - udev_selinux_resetfscreatecon(udev); + do { + util_create_path(udev, file); + udev_selinux_setfscreatecon(udev, file, mode); + err = mknod(file, mode, devnum); + if (err != 0) + err = errno; + udev_selinux_resetfscreatecon(udev); + } while (err == ENOENT); if (err != 0) { err(udev, "mknod(%s, %#o, (%u,%u) failed: %m\n", file, mode, major(devnum), minor(devnum)); goto exit; @@ -175,10 +179,14 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink) } } else { info(udev, "creating symlink '%s' to '%s'\n", slink, target); - util_create_path(udev, slink); - udev_selinux_setfscreatecon(udev, slink, S_IFLNK); - err = symlink(target, slink); - udev_selinux_resetfscreatecon(udev); + do { + util_create_path(udev, slink); + udev_selinux_setfscreatecon(udev, slink, S_IFLNK); + err = symlink(target, slink); + if (err != 0) + err = errno; + udev_selinux_resetfscreatecon(udev); + } while (err == ENOENT); if (err == 0) goto exit; } @@ -186,10 +194,14 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink) info(udev, "atomically replace '%s'\n", slink); util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL); unlink(slink_tmp); - util_create_path(udev, slink); - udev_selinux_setfscreatecon(udev, slink, S_IFLNK); - err = symlink(target, slink_tmp); - udev_selinux_resetfscreatecon(udev); + do { + util_create_path(udev, slink); + udev_selinux_setfscreatecon(udev, slink, S_IFLNK); + err = symlink(target, slink_tmp); + if (err != 0) + err = errno; + udev_selinux_resetfscreatecon(udev); + } while (err == ENOENT); if (err != 0) { err(udev, "symlink(%s, %s) failed: %m\n", target, slink_tmp); goto exit; @@ -302,8 +314,10 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) if (add) { dbg(udev, "creating index: '%s'\n", filename); - util_create_path(udev, filename); - symlink(udev_device_get_devpath(dev), filename); + do { + util_create_path(udev, filename); + symlink(udev_device_get_devpath(dev), filename); + } while (errno == ENOENT); } } |