summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-05-21 17:26:19 +0200
committerLennart Poettering <lennart@poettering.net>2012-05-21 17:26:19 +0200
commitb8f8323268ae974288e49a7cc6c1c47531e436c9 (patch)
tree2daff89175330d564146aa32967c102e588a7484 /src
parent36140842612803d71fe771ce03f3dee7732284f0 (diff)
main: try a bit harder to find an init process to execute after reexec/switch-root
Diffstat (limited to 'src')
-rw-r--r--src/core/main.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/core/main.c b/src/core/main.c
index 8c25819a12..a51d1be45b 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1684,22 +1684,36 @@ finish:
* getopt() in argv[], and some cleanups in envp[],
* but let's hope that doesn't matter.) */
- if (serialization)
+ if (serialization) {
fclose(serialization);
+ serialization = NULL;
+ }
- if (fds)
+ if (fds) {
fdset_free(fds);
+ fds = NULL;
+ }
- i = 0;
- args[i++] = switch_root_init ? switch_root_init : "/sbin/init";
- for (j = 1; j < argc; j++)
+ for (j = 1, i = 1; j < argc; j++)
args[i++] = argv[j];
args[i++] = NULL;
-
assert(i <= args_size);
+
+ if (switch_root_init) {
+ args[0] = switch_root_init;
+ execv(args[0], (char* const*) args);
+ log_warning("Failed to execute configured init, trying fallback: %m");
+ }
+
+ args[0] = "/sbin/init";
execv(args[0], (char* const*) args);
- log_error("Failed to reexecute: %m");
+ log_warning("Failed to execute /sbin/init, trying fallback: %m");
+
+ args[0] = "/bin/sh";
+ args[1] = NULL;
+ execv(args[0], (char* const*) args);
+ log_error("Failed to execute /bin/sh, giving up: %m");
}
if (serialization)