summaryrefslogtreecommitdiff
path: root/udev-add.c
diff options
context:
space:
mode:
authorgreg@kroah.com <greg@kroah.com>2004-03-01 23:31:06 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:35:06 -0700
commit97853b4f40708d2fdcde3da7e78138c683d9d66b (patch)
tree1160029f1bad2ef0e9ac325fca6366eced5a77d8 /udev-add.c
parentaebef544cb4417bcf1dbc6d9d0ad795e5525e41c (diff)
[PATCH] unlink the file before we try to create it.
Based on the patch in the Gentoo repo.
Diffstat (limited to 'udev-add.c')
-rw-r--r--udev-add.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/udev-add.c b/udev-add.c
index 19196bec54..776b542f08 100644
--- a/udev-add.c
+++ b/udev-add.c
@@ -166,9 +166,26 @@ static void set_to_local_user(char *user)
endutent();
}
-static int create_node(struct udevice *dev, int fake)
+/* Used to unlink existing files to ensure that our new file/symlink is created */
+static int unlink_entry(char *filename)
{
struct stat stats;
+ int retval = 0;
+
+ if (lstat(filename, &stats) == 0) {
+ if ((stats.st_mode & S_IFMT) != S_IFDIR) {
+ retval = unlink(filename);
+ if (retval) {
+ dbg("unlink(%s) failed with error '%s', "
+ filename, strerror(errno));
+ }
+ }
+ }
+ return retval;
+}
+
+static int create_node(struct udevice *dev, int fake)
+{
char filename[255];
char linktarget[255];
char partitionname[255];
@@ -235,6 +252,7 @@ static int create_node(struct udevice *dev, int fake)
}
if (!fake) {
+ unlink_entry(filename);
info("creating device node '%s'", filename);
make_node(filename, dev->major, dev->minor, dev->mode, uid, gid);
} else {
@@ -250,6 +268,7 @@ static int create_node(struct udevice *dev, int fake)
for (i = 1; i <= dev->partitions; i++) {
strfieldcpy(partitionname, filename);
strintcat(partitionname, i);
+ unlink_entry(partitionname);
make_node(partitionname, dev->major,
dev->minor + i, dev->mode, uid, gid);
}
@@ -291,14 +310,8 @@ static int create_node(struct udevice *dev, int fake)
strfieldcat(linktarget, &dev->name[tail]);
- /* unlink existing files to ensure that our symlink is created */
- if (!fake && (lstat(filename, &stats) == 0)) {
- if ((stats.st_mode & S_IFMT) != S_IFDIR) {
- if (unlink(filename))
- dbg("unlink(%s) failed with error '%s'",
- filename, strerror(errno));
- }
- }
+ if (!fake)
+ unlink_entry(filename);
dbg("symlink(%s, %s)", linktarget, filename);
if (!fake) {