* [PATCH] tweak node unlink handling
@ 2004-04-02 22:04 Kay Sievers
2004-04-02 22:17 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Kay Sievers @ 2004-04-02 22:04 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 712 bytes --]
Based on a patch from Olaf Hering we remove the node now only if the
requested dev_t is different from the already existing node, so any
run of udevstart should preserve the inode number of the node file.
syslog while the right node is already there:
creating device node '/udev/hda'
make_node: preserve file '/udev/hda', cause it has correct dev_t
make_node: chmod(/udev/hda, 060600)
syslog for wrong file already there:
creating device node '/udev/hda'
make_node: already present file '/udev/hda' unlinked
make_node: chmod(/udev/hda, 060600)
syslog for directory with same name already there:
creating device node '/udev/hda'
make_node: unlink(/udev/hda) failed with error '21'
thanks,
Kay
[-- Attachment #2: 01-unlink-tweak.patch --]
[-- Type: text/plain, Size: 3252 bytes --]
===== udev-add.c 1.70 vs edited =====
--- 1.70/udev-add.c Thu Apr 1 23:52:46 2004
+++ edited/udev-add.c Fri Apr 2 23:50:16 2004
@@ -105,29 +105,46 @@
return 0;
}
-static int make_node(char *filename, int major, int minor, unsigned int mode, uid_t uid, gid_t gid)
+static int make_node(char *file, int major, int minor, unsigned int mode, uid_t uid, gid_t gid)
{
- int retval;
+ struct stat stats;
+ int retval = 0;
+
+ if (stat(file, &stats) != 0)
+ goto create;
+
+ /* preserve node with already correct numbers, to not change the inode number */
+ if (((stats.st_mode & S_IFMT) == S_IFBLK || (stats.st_mode & S_IFMT) == S_IFCHR) &&
+ (stats.st_rdev == makedev(major, minor))) {
+ dbg("preserve file '%s', cause it has correct dev_t", file);
+ goto perms;
+ }
+
+ if (unlink(file) != 0)
+ dbg("unlink(%s) failed with error '%s'", file, strerror(errno));
+ else
+ dbg("already present file '%s' unlinked", file);
- retval = mknod(filename, mode, makedev(major, minor));
+create:
+ retval = mknod(file, mode, makedev(major, minor));
if (retval != 0) {
dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
- filename, mode, major, minor, strerror(errno));
+ file, mode, major, minor, strerror(errno));
goto exit;
}
- dbg("chmod(%s, %#o)", filename, mode);
- if (chmod(filename, mode) != 0) {
- dbg("chmod(%s, %#o) failed with error '%s'",
- filename, mode, strerror(errno));
+perms:
+ dbg("chmod(%s, %#o)", file, mode);
+ if (chmod(file, mode) != 0) {
+ dbg("chmod(%s, %#o) failed with error '%s'", file, mode, strerror(errno));
goto exit;
}
if (uid != 0 || gid != 0) {
- dbg("chown(%s, %u, %u)", filename, uid, gid);
- if (chown(filename, uid, gid) != 0) {
+ dbg("chown(%s, %u, %u)", file, uid, gid);
+ if (chown(file, uid, gid) != 0) {
dbg("chown(%s, %u, %u) failed with error '%s'",
- filename, uid, gid, strerror(errno));
+ file, uid, gid, strerror(errno));
goto exit;
}
}
@@ -167,23 +184,6 @@
endutent();
}
-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];
@@ -253,7 +253,6 @@
}
if (!fake) {
- unlink_entry(filename);
info("creating device node '%s'", filename);
if (make_node(filename, dev->major, dev->minor, dev->mode, uid, gid) != 0)
goto error;
@@ -270,7 +269,6 @@
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);
}
@@ -304,11 +302,9 @@
strfieldcat(linktarget, &dev->name[tail]);
- if (!fake)
- unlink_entry(filename);
-
dbg("symlink(%s, %s)", linktarget, filename);
if (!fake) {
+ unlink(filename);
if (symlink(linktarget, filename) != 0)
dbg("symlink(%s, %s) failed with error '%s'",
linktarget, filename, strerror(errno));
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tweak node unlink handling
2004-04-02 22:04 [PATCH] tweak node unlink handling Kay Sievers
@ 2004-04-02 22:17 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2004-04-02 22:17 UTC (permalink / raw)
To: linux-hotplug
On Sat, Apr 03, 2004 at 12:04:52AM +0200, Kay Sievers wrote:
> Based on a patch from Olaf Hering we remove the node now only if the
> requested dev_t is different from the already existing node, so any
> run of udevstart should preserve the inode number of the node file.
>
> syslog while the right node is already there:
> creating device node '/udev/hda'
> make_node: preserve file '/udev/hda', cause it has correct dev_t
> make_node: chmod(/udev/hda, 060600)
>
> syslog for wrong file already there:
> creating device node '/udev/hda'
> make_node: already present file '/udev/hda' unlinked
> make_node: chmod(/udev/hda, 060600)
>
> syslog for directory with same name already there:
> creating device node '/udev/hda'
> make_node: unlink(/udev/hda) failed with error '21'
Nice, thanks for cleaning up the patch and getting it to apply.
greg k-h
-------------------------------------------------------
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=click
_______________________________________________
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] 2+ messages in thread
end of thread, other threads:[~2004-04-02 22:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-02 22:04 [PATCH] tweak node unlink handling Kay Sievers
2004-04-02 22:17 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).