[BusyBox] run-parts bug report

Vladimir N. Oleynik dzo at simtreas.ru
Thu Nov 21 07:24:05 UTC 2002


Nick,

> To solve my problem, I made a few debug changes to the
> libbb/run_parts.c:

Thanks!
I can`t test it, I don`t use run_part applet ;)

 
> extern int run_parts(char **args, const unsigned char test_mode)
> {
> ...
>         for (i = 0; i < entries; i++) {
>                 printf("concat args[0]=%s and namelist[%d]->d_name=%s\n",
>                         args[0], i, namelist[i]->d_name);
> ...
>         if ((pid = vfork()) < 0) {
>                perror_msg_and_die("failed to fork");
>         } else {
>                 if (!pid) {
>                         args[0] = filename;
>                         j=0;
>                          while (args[j]!=NULL) {
>                                 printf("vfork child: args[%d]=%s\n", j, args[j]);
>                                 j++;
>                          };
>                          execv(filename, args);
>                          exec_errno = errno;
>                          _exit(1);
>                  }
>         }
> ...
> 
> Then recompile busybox, and reinstall, etc...
> 
> Here is output:
> ~ # run-parts -a start /etc/rc.d
> concat args[0]=/etc/rc.d and namelist[0]->d_name=00_ifconfig
> vfork child: args[0]=/etc/rc.d/00_ifconfig
> vfork child: args[1]=start
> Starting network interfaces: inside dmz1 dmz2 dmz3 dmz4 outside done
> concat args[0]=/etc/rc.d/00_ifconfig and namelist[1]->d_name=01_bridge
> run-parts: failed to stat component ХE.@ХE. at d/00_ifconfig/01_bridge: No
> such file or directory
> ~ #
> 
> As I seen, parent's args[0] was changed by child.
> So at the second loop turn:
> filename = concat_path_file("/etc/rc.d/00_ifconfig", "01_bridge");
> 
> How? and why?
> Is it invalid vfork() here?

Not. vfork child and parent have common stack :)
Please test it:



--w
vodz
-------------- next part --------------
diff -rbu busybox.orig/libbb/run_parts.c busybox/libbb/run_parts.c
--- busybox.orig/libbb/run_parts.c	Thu Nov 21 17:18:34 2002
+++ busybox/libbb/run_parts.c	Thu Nov 21 17:20:00 2002
@@ -50,6 +50,7 @@
 	struct dirent **namelist = 0;
 	struct stat st;
 	char *filename;
+	char *arg0 = args[0];
 	int entries;
 	int i;
 	int exitstatus = 0;
@@ -60,7 +61,7 @@
 	(void) &exitstatus;
 #endif
 	/* scandir() isn't POSIX, but it makes things easy. */
-	entries = scandir(args[0], &namelist, valid_name, alphasort);
+	entries = scandir(arg0, &namelist, valid_name, alphasort);
 
 	if (entries == -1) {
 		perror_msg_and_die("failed to open directory %s", args[0]);
@@ -68,7 +69,7 @@
 
 	for (i = 0; i < entries; i++) {
 
-		filename = concat_path_file(args[0], namelist[i]->d_name);
+		filename = concat_path_file(arg0, namelist[i]->d_name);
 
 		if (stat(filename, &st) < 0) {
 			perror_msg_and_die("failed to stat component %s", filename);


More information about the busybox mailing list