X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fmain.c;h=a51d1be45bc3de8794fa5e1d13cb70f85d085bf4;hb=b8f8323268ae974288e49a7cc6c1c47531e436c9;hp=be9d0a60e1ce49d11f8eebba2d834b038d406bea;hpb=e564a98237817d8c89f7979856a87d3788988742;p=elogind.git diff --git a/src/core/main.c b/src/core/main.c index be9d0a60e..a51d1be45 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1185,7 +1185,7 @@ static int do_switch_root(const char *switch_root) { } if (chroot(".") < 0) - log_warning("Failed to change root, ignoring: %s", strerror(-r)); + log_warning("Failed to change root, ignoring: %m"); /* FIXME: remove old root */ @@ -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)