diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-09-22 23:59:21 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-09-22 23:59:21 +0200 |
commit | 0931a9f15e7436346e33c66129f3ff822c33f52a (patch) | |
tree | 08a72115434dc3316b4d7237fa9e145d53cd10f5 | |
parent | 8da984cc1e47b2bb7ff6361a81b59593a51a3513 (diff) | |
download | hurd-0931a9f15e7436346e33c66129f3ff822c33f52a.tar.gz hurd-0931a9f15e7436346e33c66129f3ff822c33f52a.tar.bz2 hurd-0931a9f15e7436346e33c66129f3ff822c33f52a.zip |
Check that runsystem script exists before trying it.
* init/init.c (launch_something): Check with file_name_lookup that runsystem
script exists before calling start_child.
* daemons/console-run.c (main): Check with file_name_lookup that runsystem
script exists before opening a console for it.
-rw-r--r-- | daemons/console-run.c | 7 | ||||
-rw-r--r-- | init/init.c | 23 |
2 files changed, 26 insertions, 4 deletions
diff --git a/daemons/console-run.c b/daemons/console-run.c index aaa1159b..fb879e53 100644 --- a/daemons/console-run.c +++ b/daemons/console-run.c @@ -49,6 +49,7 @@ int main (int argc, char **argv) { mach_port_t consdev = get_console (); + mach_port_t runsystem; char *consname; if (consdev == MACH_PORT_NULL) @@ -62,6 +63,12 @@ main (int argc, char **argv) if (argc < 2) error (1, 0, "Usage: %s PROGRAM [ARG...]", program_invocation_short_name); + /* Check whether runsystem exists before opening a console for it. */ + runsystem = file_name_lookup (argv[1], O_RDONLY, 0); + if (runsystem == MACH_PORT_NULL) + error (127, errno, "cannot open file `%s' for execution", argv[1]); + mach_port_deallocate (mach_task_self (), runsystem); + if (open_console (&consname)) setenv ("FALLBACK_CONSOLE", consname, 1); diff --git a/init/init.c b/init/init.c index d66bee0b..edfe1236 100644 --- a/init/init.c +++ b/init/init.c @@ -1082,6 +1082,7 @@ start_child (const char *prog, char **progargs) static void launch_something (const char *why) { + file_t something; static unsigned int try; static const char *const tries[] = { @@ -1093,12 +1094,26 @@ launch_something (const char *why) if (why) error (0, 0, "%s %s", tries[try - 1], why); - if (try == 0 && start_child (tries[try++], &global_argv[1]) == 0) - return; + something = file_name_lookup (tries[try], O_EXEC, 0); + if (something != MACH_PORT_NULL) + { + mach_port_deallocate (mach_task_self (), something); + if (try == 0 && start_child (tries[try++], &global_argv[1]) == 0) + return; + } + else + try++; while (try < sizeof tries / sizeof tries[0]) - if (start_child (tries[try++], NULL) == 0) - return; + { + something = file_name_lookup (tries[try], O_EXEC, 0); + if (something != MACH_PORT_NULL) + { + mach_port_deallocate (mach_task_self (), something); + if (start_child (tries[try++], NULL) == 0) + return; + } + } crash_system (); } |