* [PATCH] keep device nodes during add
@ 2004-03-31 19:59 Olaf Hering
0 siblings, 0 replies; only message in thread
From: Olaf Hering @ 2004-03-31 19:59 UTC (permalink / raw)
To: linux-hotplug
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_id\x1470&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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-03-31 19:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-31 19:59 [PATCH] keep device nodes during add Olaf Hering
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.