From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jim Gifford" Date: Tue, 22 Jun 2004 08:30:12 +0000 Subject: Re: Strange udev problem - (Better Fix) - Message-Id: <006101c45833$2363dca0$d100a8c0@W2RZ8L4S02> MIME-Version: 1 Content-Type: multipart/mixed; boundary="----=_NextPart_000_005E_01C457F8.7693F350" List-Id: To: linux-hotplug@vger.kernel.org This is a multi-part message in MIME format. ------=_NextPart_000_005E_01C457F8.7693F350 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I attached the same patch I sent before, here is the correct patched ------=_NextPart_000_005E_01C457F8.7693F350 Content-Type: application/octet-stream; name="udev-027-permissions-1[2].patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="udev-027-permissions-1[2].patch" Submitted By: Jim Gifford (jim at linuxfromscratch dot org)=0A= Date: 2004-06-21=0A= Initial Package Version: 027=0A= Origin: Jim Gifford and Zack Winkles=0A= Upstream Status: N/A=0A= Description: Reverts tweak node unlink handling=0A= = http://linuxusb.bkbits.net:8080/udev/cset@1.759?nav=3Dindex.html|tags|Cha= ngeSet@..1.7601=0A= =0A= Symptons of problem: When cron executes a bash script, /dev/null = changes from the=0A= permissions lists in udev.rules to 600. This patch seems to correct the = issue,=0A= I am submitting it as a temporary fix util a better fix can be found.=0A= =0A= diff -Naur udev-027.orig/udev-add.c udev-027/udev-add.c=0A= --- udev-027.orig/udev-add.c 2004-06-14 16:38:35.000000000 -0400=0A= +++ udev-027/udev-add.c 2004-06-21 12:44:15.422138488 -0400=0A= @@ -105,46 +105,29 @@=0A= return 0;=0A= }=0A= =0A= -static int make_node(char *file, int major, int minor, unsigned int = mode, uid_t uid, gid_t gid)=0A= +static int make_node(char *filename, int major, int minor, unsigned int = mode, uid_t uid, gid_t gid)=0A= {=0A= - struct stat stats;=0A= - int retval =3D 0;=0A= -=0A= - if (stat(file, &stats) !=3D 0)=0A= - goto create;=0A= -=0A= - /* preserve node with already correct numbers, to not change the inode = number */=0A= - if (((stats.st_mode & S_IFMT) =3D=3D S_IFBLK || (stats.st_mode & = S_IFMT) =3D=3D S_IFCHR) &&=0A= - (stats.st_rdev =3D=3D makedev(major, minor))) {=0A= - dbg("preserve file '%s', cause it has correct dev_t", file);=0A= - goto perms;=0A= - }=0A= -=0A= - if (unlink(file) !=3D 0)=0A= - dbg("unlink(%s) failed with error '%s'", file, strerror(errno));=0A= - else=0A= - dbg("already present file '%s' unlinked", file);=0A= + int retval;=0A= =0A= -create:=0A= - retval =3D mknod(file, mode, makedev(major, minor));=0A= + retval =3D mknod(filename, mode, makedev(major, minor));=0A= if (retval !=3D 0) {=0A= dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",=0A= - file, mode, major, minor, strerror(errno));=0A= + filename, mode, major, minor, strerror(errno));=0A= goto exit;=0A= }=0A= =0A= -perms:=0A= - dbg("chmod(%s, %#o)", file, mode);=0A= - if (chmod(file, mode) !=3D 0) {=0A= - dbg("chmod(%s, %#o) failed with error '%s'", file, mode, = strerror(errno));=0A= + dbg("chmod(%s, %#o)", filename, mode);=0A= + if (chmod(filename, mode) !=3D 0) {=0A= + dbg("chmod(%s, %#o) failed with error '%s'",=0A= + filename, mode, strerror(errno));=0A= goto exit;=0A= }=0A= =0A= if (uid !=3D 0 || gid !=3D 0) {=0A= - dbg("chown(%s, %u, %u)", file, uid, gid);=0A= - if (chown(file, uid, gid) !=3D 0) {=0A= + dbg("chown(%s, %u, %u)", filename, uid, gid);=0A= + if (chown(filename, uid, gid) !=3D 0) {=0A= dbg("chown(%s, %u, %u) failed with error '%s'",=0A= - file, uid, gid, strerror(errno));=0A= + filename, uid, gid, strerror(errno));=0A= goto exit;=0A= }=0A= }=0A= @@ -184,6 +167,23 @@=0A= endutent();=0A= }=0A= =0A= +static int unlink_entry(char *filename)=0A= +{=0A= + struct stat stats;=0A= + int retval =3D 0;=0A= + =0A= + if (lstat(filename, &stats) =3D=3D 0) {=0A= + if ((stats.st_mode & S_IFMT) !=3D S_IFDIR) {=0A= + retval =3D unlink(filename);=0A= + if (retval) {=0A= + dbg("unlink(%s) failed with error '%s'",=0A= + filename, strerror(errno));=0A= + }=0A= + }=0A= + }=0A= + return retval;=0A= +}=0A= +=0A= static int create_node(struct udevice *dev, int fake)=0A= {=0A= char filename[NAME_SIZE];=0A= @@ -253,6 +253,7 @@=0A= }=0A= =0A= if (!fake) {=0A= + unlink_entry(filename);=0A= info("creating device node '%s'", filename);=0A= if (make_node(filename, dev->major, dev->minor, dev->mode, uid, gid) = !=3D 0)=0A= goto error;=0A= @@ -269,6 +270,7 @@=0A= for (i =3D 1; i <=3D dev->partitions; i++) {=0A= strfieldcpy(partitionname, filename);=0A= strintcat(partitionname, i);=0A= + unlink_entry(partitionname);=0A= make_node(partitionname, dev->major,=0A= dev->minor + i, dev->mode, uid, gid);=0A= }=0A= @@ -302,9 +304,11 @@=0A= =0A= strfieldcat(linktarget, &dev->name[tail]);=0A= =0A= + if (!fake)=0A= + unlink_entry(filename);=0A= +=0A= dbg("symlink(%s, %s)", linktarget, filename);=0A= if (!fake) {=0A= - unlink(filename);=0A= if (symlink(linktarget, filename) !=3D 0)=0A= dbg("symlink(%s, %s) failed with error '%s'",=0A= linktarget, filename, strerror(errno));=0A= ------=_NextPart_000_005E_01C457F8.7693F350-- ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ 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