[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: mdev accidently erases previously created nodes while trying to
From:       Jean Wolter <jw5 () os ! inf ! tu-dresden ! de>
Date:       2009-06-22 14:27:53
Message-ID: 86vdmo2viu.fsf () erwin ! inf ! tu-dresden ! de
[Download RAW message or body]

Denys Vlasenko <vda.linux@googlemail.com> writes:

> AHA. Thanks for your diagnosis and patch.
>
> Please try this patch. After build, go to testsuite/*
> and run "runtest [-v] mdev".

I used the git version which already contains this patch and booted it
in my qemu test environment. It worked correctly.

I have one more suggestion and one more question about mdev, first the
suggestion: Currently mdev is not able to show any error messages,
since stdout is closed at the beginning using
bb_sanitize_stdio(). Maybe it would be a good idea to leave it
untouched if invoked on the command line and redirect it to syslog
when invoked as a hotplug helper. The attached path does this.

And there is another potential problem in the same scenario we
discussed so far. If someone uses '>' to create an additional symlink
then it might happen, that there is already a node with the same name
(/cev/capi20 in this case; /dev/capi20.20 is created and the creation
of the symlink fails). I am not sure how to handle this so I added an
error message in the patch.

Regards,
jean


["mdev-error.patch" (text/x-diff)]

diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index c68c0a5..86e5b82 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -9,6 +9,7 @@
  */
 #include "libbb.h"
 #include "xregex.h"
+#include <syslog.h>
 
 /* "mdev -s" scans /sys/class/xxx, looking for directories which have dev
  * file (it is of the form "M:m\n"). Example: /sys/class/tty/tty0/dev
@@ -332,7 +333,8 @@ static void make_device(char *path, int delete)
 			}
 			if (ENABLE_FEATURE_MDEV_RENAME && alias) {
 				if (aliaslink == '>')
-					symlink(node_name, device_name);
+					if (symlink(node_name, device_name) < 0)
+						bb_perror_msg("symlink %s", device_name);
 				free(alias);
 			}
 		}
@@ -477,16 +479,23 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
 {
 	RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
 
-	/* We can be called as hotplug helper */
-	/* Kernel cannot provide suitable stdio fds for us, do it ourself */
-	bb_sanitize_stdio();
+	bool cmdline = argv[1] && strcmp(argv[1], "-s") == 0;
+
+	if (!cmdline) {
+		/* We can be called as hotplug helper */
+		/* Kernel cannot provide suitable stdio fds for us, do
+		 * it ourself */
+		bb_sanitize_stdio();
+		openlog(applet_name, LOG_CONS | LOG_PID, LOG_DAEMON);
+		logmode = LOGMODE_SYSLOG;
+	}                
 
 	/* Force the configuration file settings exactly */
 	umask(0);
 
 	xchdir("/dev");
 
-	if (argv[1] && strcmp(argv[1], "-s") == 0) {
+	if (cmdline) {
 		/* Scan:
 		 * mdev -s
 		 */


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic