[systemd-devel] [PATCH] udev: don't create symlink or rename if it already exists
Robert Milasan
rmilasan at suse.com
Tue Feb 12 05:18:03 PST 2013
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
---
src/udev/udev-node.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index bce4cfe..a92d727 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -107,6 +107,10 @@ static int node_symlink(struct udev *udev, const
char *node, const char *slink) err = mkdir_parents_label(slink_tmp,
0755); if (err != 0 && err != -ENOENT)
break;
+ if (lstat(slink_tmp, &stats) == 0) {
+ err = 0;
+ break;
+ }
label_context_set(slink_tmp, S_IFLNK);
err = symlink(target, slink_tmp);
if (err != 0)
@@ -117,10 +121,12 @@ static int node_symlink(struct udev *udev, const
char *node, const char *slink) log_error("symlink '%s' '%s' failed:
%m\n", target, slink_tmp); goto exit;
}
- err = rename(slink_tmp, slink);
- if (err != 0) {
- log_error("rename '%s' '%s' failed: %m\n", slink_tmp,
slink);
- unlink(slink_tmp);
+ if (lstat(slink_tmp, &stats) == 0) {
+ err = rename(slink_tmp, slink);
+ if (err != 0) {
+ log_error("rename '%s' '%s' failed: %m\n",
slink_tmp, slink);
+ unlink(slink_tmp);
+ }
}
exit:
return err;
--
1.7.7
--
Robert Milasan
L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmilasan at suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402 6FE7 2F64 167C 1909 6D1A
More information about the systemd-devel
mailing list