diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-07-29 07:05:40 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-07-29 07:05:40 +0000 |
commit | 2a186890ee664be41b8f9ea572a9ae3498f06eca (patch) | |
tree | 13ec20ed6ec7dd51ab4ffe84530d9dd37b77b091 | |
parent | 81fe123040b53490b239b3d2abc8cc93d6d462ae (diff) | |
download | busybox-w32-2a186890ee664be41b8f9ea572a9ae3498f06eca.tar.gz busybox-w32-2a186890ee664be41b8f9ea572a9ae3498f06eca.tar.bz2 busybox-w32-2a186890ee664be41b8f9ea572a9ae3498f06eca.zip |
Bruno Randolf writes:
this patch fixes run_parts when it's called by ifupdown. 1) argv has to be a
NULL terminated char* array, not just a string. 2) run_parts now explicitly
sets the environment. this environment is populated from the
/etc/network/interfaces config file and is needed by the scripts in
/etc/network/if-pre-up.d/. when run-parts is called from the command line the
environment is taken from the current process.
Vladimir Oleynik then wrote:
You can simplify this if use:
+ bb_xasprintf(&buf[0], "/etc/network/if-%s.d", opt);
+ buf[1] = NULL;
+
+ run_parts(&buf, 2, environ);
+ free(buf[0]);
--w
vodz
-rw-r--r-- | debianutils/run_parts.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/run_parts.c | 4 | ||||
-rw-r--r-- | networking/ifupdown.c | 11 |
4 files changed, 12 insertions, 9 deletions
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 98fd58887..53d33cec5 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -61,6 +61,8 @@ static const struct option runparts_long_options[] = { | |||
61 | { 0, 0, 0, 0 } | 61 | { 0, 0, 0, 0 } |
62 | }; | 62 | }; |
63 | 63 | ||
64 | extern char **environ; | ||
65 | |||
64 | /* run_parts_main */ | 66 | /* run_parts_main */ |
65 | /* Process options */ | 67 | /* Process options */ |
66 | int run_parts_main(int argc, char **argv) | 68 | int run_parts_main(int argc, char **argv) |
@@ -108,5 +110,5 @@ int run_parts_main(int argc, char **argv) | |||
108 | args[0] = argv[optind]; | 110 | args[0] = argv[optind]; |
109 | args[argcount] = 0; | 111 | args[argcount] = 0; |
110 | 112 | ||
111 | return(run_parts(args, test_mode)); | 113 | return(run_parts(args, test_mode, environ)); |
112 | } | 114 | } |
diff --git a/include/libbb.h b/include/libbb.h index 6b75b8a89..ddc93c183 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -405,7 +405,7 @@ extern void run_shell ( const char *shell, int loginshell, const char *command, | |||
405 | , security_id_t sid | 405 | , security_id_t sid |
406 | #endif | 406 | #endif |
407 | ); | 407 | ); |
408 | extern int run_parts(char **args, const unsigned char test_mode); | 408 | extern int run_parts(char **args, const unsigned char test_mode, char **env); |
409 | extern int restricted_shell ( const char *shell ); | 409 | extern int restricted_shell ( const char *shell ); |
410 | extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ); | 410 | extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ); |
411 | extern int correct_password ( const struct passwd *pw ); | 411 | extern int correct_password ( const struct passwd *pw ); |
diff --git a/libbb/run_parts.c b/libbb/run_parts.c index 58645660b..171d93793 100644 --- a/libbb/run_parts.c +++ b/libbb/run_parts.c | |||
@@ -47,7 +47,7 @@ static int valid_name(const struct dirent *d) | |||
47 | * test_mode = 2 means to fail siliently on missing directories | 47 | * test_mode = 2 means to fail siliently on missing directories |
48 | */ | 48 | */ |
49 | 49 | ||
50 | extern int run_parts(char **args, const unsigned char test_mode) | 50 | extern int run_parts(char **args, const unsigned char test_mode, char **env) |
51 | { | 51 | { |
52 | struct dirent **namelist = 0; | 52 | struct dirent **namelist = 0; |
53 | struct stat st; | 53 | struct stat st; |
@@ -92,7 +92,7 @@ extern int run_parts(char **args, const unsigned char test_mode) | |||
92 | bb_perror_msg_and_die("failed to fork"); | 92 | bb_perror_msg_and_die("failed to fork"); |
93 | } else if (!pid) { | 93 | } else if (!pid) { |
94 | args[0] = filename; | 94 | args[0] = filename; |
95 | execv(filename, args); | 95 | execve(filename, args, env); |
96 | exec_errno = errno; | 96 | exec_errno = errno; |
97 | _exit(1); | 97 | _exit(1); |
98 | } | 98 | } |
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 818bec2d6..f91eddae8 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -1019,7 +1019,7 @@ static int doit(char *str) | |||
1019 | static int execute_all(struct interface_defn_t *ifd, execfn *exec, const char *opt) | 1019 | static int execute_all(struct interface_defn_t *ifd, execfn *exec, const char *opt) |
1020 | { | 1020 | { |
1021 | int i; | 1021 | int i; |
1022 | char *buf; | 1022 | char *buf[2]; |
1023 | 1023 | ||
1024 | for (i = 0; i < ifd->n_options; i++) { | 1024 | for (i = 0; i < ifd->n_options; i++) { |
1025 | if (strcmp(ifd->option[i].name, opt) == 0) { | 1025 | if (strcmp(ifd->option[i].name, opt) == 0) { |
@@ -1029,10 +1029,11 @@ static int execute_all(struct interface_defn_t *ifd, execfn *exec, const char *o | |||
1029 | } | 1029 | } |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | buf = xmalloc(bb_strlen(opt) + 19); | 1032 | bb_xasprintf(&buf[0], "/etc/network/if-%s.d", opt); |
1033 | sprintf(buf, "/etc/network/if-%s.d", opt); | 1033 | buf[1] = NULL; |
1034 | run_parts(&buf, 2); | 1034 | |
1035 | free(buf); | 1035 | run_parts(&buf, 2, environ); |
1036 | free(buf[0]); | ||
1036 | return (1); | 1037 | return (1); |
1037 | } | 1038 | } |
1038 | 1039 | ||