keep device nodes during add
PATCH 1/1 keep device nodes during add
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-add.c +15 -23
@@ -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 *userendutent (); } -/* 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 *dfor (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 *dstrfieldcat (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'",
Signature · 14 lines
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 [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel