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
This commit is contained in:
parent
81fe123040
commit
2a186890ee
@ -61,6 +61,8 @@ static const struct option runparts_long_options[] = {
|
|||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern char **environ;
|
||||||
|
|
||||||
/* run_parts_main */
|
/* run_parts_main */
|
||||||
/* Process options */
|
/* Process options */
|
||||||
int run_parts_main(int argc, char **argv)
|
int run_parts_main(int argc, char **argv)
|
||||||
@ -108,5 +110,5 @@ int run_parts_main(int argc, char **argv)
|
|||||||
args[0] = argv[optind];
|
args[0] = argv[optind];
|
||||||
args[argcount] = 0;
|
args[argcount] = 0;
|
||||||
|
|
||||||
return(run_parts(args, test_mode));
|
return(run_parts(args, test_mode, environ));
|
||||||
}
|
}
|
||||||
|
@ -405,7 +405,7 @@ extern void run_shell ( const char *shell, int loginshell, const char *command,
|
|||||||
, security_id_t sid
|
, security_id_t sid
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
extern int run_parts(char **args, const unsigned char test_mode);
|
extern int run_parts(char **args, const unsigned char test_mode, char **env);
|
||||||
extern int restricted_shell ( const char *shell );
|
extern int restricted_shell ( const char *shell );
|
||||||
extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw );
|
extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw );
|
||||||
extern int correct_password ( const struct passwd *pw );
|
extern int correct_password ( const struct passwd *pw );
|
||||||
|
@ -47,7 +47,7 @@ static int valid_name(const struct dirent *d)
|
|||||||
* test_mode = 2 means to fail siliently on missing directories
|
* test_mode = 2 means to fail siliently on missing directories
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int run_parts(char **args, const unsigned char test_mode)
|
extern int run_parts(char **args, const unsigned char test_mode, char **env)
|
||||||
{
|
{
|
||||||
struct dirent **namelist = 0;
|
struct dirent **namelist = 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -92,7 +92,7 @@ extern int run_parts(char **args, const unsigned char test_mode)
|
|||||||
bb_perror_msg_and_die("failed to fork");
|
bb_perror_msg_and_die("failed to fork");
|
||||||
} else if (!pid) {
|
} else if (!pid) {
|
||||||
args[0] = filename;
|
args[0] = filename;
|
||||||
execv(filename, args);
|
execve(filename, args, env);
|
||||||
exec_errno = errno;
|
exec_errno = errno;
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +1019,7 @@ static int doit(char *str)
|
|||||||
static int execute_all(struct interface_defn_t *ifd, execfn *exec, const char *opt)
|
static int execute_all(struct interface_defn_t *ifd, execfn *exec, const char *opt)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *buf;
|
char *buf[2];
|
||||||
|
|
||||||
for (i = 0; i < ifd->n_options; i++) {
|
for (i = 0; i < ifd->n_options; i++) {
|
||||||
if (strcmp(ifd->option[i].name, opt) == 0) {
|
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
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = xmalloc(bb_strlen(opt) + 19);
|
bb_xasprintf(&buf[0], "/etc/network/if-%s.d", opt);
|
||||||
sprintf(buf, "/etc/network/if-%s.d", opt);
|
buf[1] = NULL;
|
||||||
run_parts(&buf, 2);
|
|
||||||
free(buf);
|
run_parts(&buf, 2, environ);
|
||||||
|
free(buf[0]);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user