diff options
author | Kay Sievers <kay.sievers@suse.de> | 2006-06-14 16:32:52 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2006-06-14 16:32:52 +0200 |
commit | fa33d857e2cdd65d3de2f88021ecacf167fc21f0 (patch) | |
tree | 0267347e95dcf04ae57df4baa0054d7502f7cb5b /udev_node.c | |
parent | afb66e32335d7bea55b015855089df4779916829 (diff) |
don't remove symlinks if they are already there
Consecutive "add" events will not remove and recreate the same symlinks
anymore. No longer valid links, like after changing a filesystem label,
will still be removed.
Diffstat (limited to 'udev_node.c')
-rw-r--r-- | udev_node.c | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/udev_node.c b/udev_node.c index 2a30fe3222..ee59d4ae7c 100644 --- a/udev_node.c +++ b/udev_node.c @@ -90,6 +90,36 @@ exit: return retval; } +static int udev_node_symlink(struct udevice *udev, const char *linktarget, const char *filename) +{ + char target[PATH_SIZE]; + int len; + + /* look if symlink already exists */ + len = readlink(filename, target, sizeof(target)); + if (len > 0) { + target[len] = '\0'; + if (strcmp(linktarget, target) == 0) { + info("preserving symlink '%s' to '%s'", filename, linktarget); + selinux_setfilecon(filename, NULL, S_IFLNK); + goto exit; + } else { + info("link '%s' points to different target '%s', delete it", filename, target); + unlink(filename); + } + } + + /* create link */ + info("creating symlink '%s' to '%s'", filename, linktarget); + selinux_setfscreatecon(filename, NULL, S_IFLNK); + if (symlink(linktarget, filename) != 0) + err("symlink(%s, %s) failed: %s", linktarget, filename, strerror(errno)); + selinux_resetfscreatecon(); + +exit: + return 0; +} + int udev_node_add(struct udevice *udev, struct udevice *udev_old) { char filename[PATH_SIZE]; @@ -205,13 +235,8 @@ int udev_node_add(struct udevice *udev, struct udevice *udev_old) strlcat(linktarget, &udev->name[tail], sizeof(linktarget)); info("creating symlink '%s' to '%s'", filename, linktarget); - if (!udev->test_run) { - unlink(filename); - selinux_setfscreatecon(filename, NULL, S_IFLNK); - if (symlink(linktarget, filename) != 0) - err("symlink(%s, %s) failed: %s", linktarget, filename, strerror(errno)); - selinux_resetfscreatecon(); - } + if (!udev->test_run) + udev_node_symlink(udev, linktarget, filename); strlcat(symlinks, filename, sizeof(symlinks)); strlcat(symlinks, " ", sizeof(symlinks)); |