[PATCH] was: mdev doesn't remove devices
Natanael Copa
natanael.copa at gmail.com
Mon Aug 28 22:16:20 UTC 2006
On Mon, 2006-08-28 at 16:21 -0500, Jason Schoon wrote:
> Since we're on the topic of mdev already, I have a patch I had to
> create today that I thought I would run by the list.
>
> I am using mdev with a mdev.conf to launch a script file in certain
> cases (basically it enables hotplugging on USB flash devices for me).
>
> In that script, I happened to add a line that sends its output
> to /dev/null (i.e. 2>/dev/null). Well, this just so happens to create
> an empty file, which then causes mknod of /dev/null to fail with an
> "already exists."
Happened to me too.
>
> So, my solution was to either make sure that my hotplug script never,
> ever talks to a dev file (a poor assumption I feel),
You could also create /dev/null manually as first thing after /dev is
mounted.
> or to patch mdev to check if something is a regular file, and delete
> it. Attached is a patch that accomplishes just that. If someone else
> thinks that is a sane thing to do, please apply.
Wouldn't this open for strange race conditions?
if [ -e /dev/mydev ] ; then
# right here the hotplug syste deletes the /dev/mydev
# and before it reaches to recreate it do_something opens it
do_something /dev/mydev
fi
Sure, you could unplug a device but there might be some devices you
expect to never be unplugged (like /dev/null)
> --- busybox/util-linux/mdev.c 2006-08-28 15:15:47.000000000 -0500
> +++ busybox/util-linux/mdev.c.mine 2006-08-28 15:15:35.000000000
> -0500
> @@ -165,6 +165,9 @@
>
> umask(0);
> if (!delete) {
> + struct stat st;
> + if (!lstat(device_name, &st) && S_ISREG(st.st_mode))
> unlink(device_name);
> +
> if (sscanf(temp, "%d:%d", &major, &minor) != 2) return;
> if (mknod(device_name, mode | type, makedev(major, minor)) &&
> errno != EEXIST)
> bb_perror_msg_and_die("mknod %s failed", device_name);
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://busybox.net/cgi-bin/mailman/listinfo/busybox
More information about the busybox
mailing list