All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olh@suse.de>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] keep device nodes during add
Date: Wed, 31 Mar 2004 19:59:38 +0000	[thread overview]
Message-ID: <20040331195938.GA24269@suse.de> (raw)

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

                 reply	other threads:[~2004-03-31 19:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040331195938.GA24269@suse.de \
    --to=olh@suse.de \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.