[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-hotplug
Subject:    [PATCH] keep device nodes during add
From:       Olaf Hering <olh () suse ! de>
Date:       2004-03-31 19:59:38
Message-ID: 20040331195938.GA24269 () suse ! de
[Download RAW message or body]

This patch checks if the node does already exist. If so, keep it and run
just a chmod on it.
running udevstart will unlink all existing nodes (at least it does that
here). This breaks applications that follow /proc/<pid>/fd/*, because
the inode has changed.

I'm not sure why udev made such a big deal about the unlink, just do it?

--- udev-glibc-debug/udev-add.c	2004-03-22 16:52:46.000000000 +0000
+++ udev-glibc/udev-add.c	2004-03-28 19:06:18.000000000 +0000
@@ -105,8 +105,22 @@ static int create_path(char *file)
 
 static int make_node(char *filename, int major, int minor, unsigned int mode, uid_t uid, gid_t gid)
 {
+	struct stat stats;
 	int retval;
 
+	/* Used to unlink existing files to ensure that our new file/symlink is created */
+	if (lstat(filename, &stats) == 0) {
+		if ( (((stats.st_mode & S_IFMT) == S_IFBLK || (stats.st_mode & S_IFMT) == S_IFCHR) &&
+			(stats.st_rdev != makedev(major, minor))) &&
+			(stats.st_mode & S_IFMT) != S_IFDIR) {
+				retval = unlink(filename);
+				if (retval) {
+					dbg("unlink(%s) failed with error '%s'",
+					    filename, strerror(errno));
+				}
+		}
+	}
+
 	retval = mknod(filename, mode, makedev(major, minor));
 	if (retval != 0) {
 		dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
@@ -166,24 +180,6 @@ static void set_to_local_user(char *user
 	endutent();
 }
 
-/* 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[NAME_SIZE];
@@ -254,7 +250,6 @@ static int create_node(struct udevice *d
 	}
 
 	if (!fake) {
-		unlink_entry(filename);
 		info("creating device node '%s'", filename);
 		make_node(filename, dev->major, dev->minor, dev->mode, uid, gid);
 	} else {
@@ -270,7 +265,6 @@ static int create_node(struct udevice *d
 			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);
 			}
@@ -307,11 +301,9 @@ static int create_node(struct udevice *d
 
 		strfieldcat(linktarget, &dev->name[tail]);
 
-		if (!fake)
-			unlink_entry(filename);
-
 		dbg("symlink(%s, %s)", linktarget, filename);
 		if (!fake) {
+			unlink(filename);
 			retval = symlink(linktarget, filename);
 			if (retval != 0)
 				dbg("symlink(%s, %s) failed with error '%s'",

-- 
USB is for mice, FireWire is for men!

sUse lINUX ag, nÜRNBERG


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&opĖk
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic