X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fmain.c;h=fcb6e8f9db8d88807084d008f517669b558d5b7c;hb=efb3237ee69bc593b11bc828791ee48ba6cc4f5c;hp=35ee1c73e1bfb0bf550851c37fbaccee4bffb449;hpb=a9c501a5902a64d4ec21cf0e87d16ec8c0c1e169;p=elogind.git diff --git a/src/main.c b/src/main.c index 35ee1c73e..fcb6e8f9d 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,7 @@ #include "hostname-setup.h" #include "loopback-setup.h" #include "kmod-setup.h" +#include "locale-setup.h" #include "load-fragment.h" #include "fdset.h" #include "special.h" @@ -64,6 +65,9 @@ static int arg_crash_chvt = -1; static bool arg_confirm_spawn = false; static bool arg_show_status = true; static bool arg_sysv_console = true; +static bool arg_mount_auto = true; +static bool arg_swap_auto = true; +static char *arg_console = NULL; static FILE* serialization = NULL; @@ -116,12 +120,13 @@ _noreturn_ static void crash(int sig) { _exit(1); } else { - int status; + siginfo_t status; + int r; /* Order things nicely. */ - if (waitpid(pid, &status, 0) < 0) - log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(errno)); - else if (!WCOREDUMP(status)) + if ((r = wait_for_terminate(pid, &status)) < 0) + log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(-r)); + else if (status.si_code != CLD_DUMPED) log_error("Caught <%s>, core dump failed.", signal_to_string(sig)); else log_error("Caught <%s>, dumped core as pid %lu.", signal_to_string(sig), (unsigned long) pid); @@ -231,15 +236,16 @@ static int set_default_unit(const char *u) { static int parse_proc_cmdline_word(const char *word) { static const char * const rlmap[] = { - "single", SPECIAL_RESCUE_TARGET, - "-s", SPECIAL_RESCUE_TARGET, - "s", SPECIAL_RESCUE_TARGET, - "S", SPECIAL_RESCUE_TARGET, - "1", SPECIAL_RESCUE_TARGET, - "2", SPECIAL_RUNLEVEL2_TARGET, - "3", SPECIAL_RUNLEVEL3_TARGET, - "4", SPECIAL_RUNLEVEL4_TARGET, - "5", SPECIAL_RUNLEVEL5_TARGET + "emergency", SPECIAL_EMERGENCY_TARGET, + "single", SPECIAL_RESCUE_TARGET, + "-s", SPECIAL_RESCUE_TARGET, + "s", SPECIAL_RESCUE_TARGET, + "S", SPECIAL_RESCUE_TARGET, + "1", SPECIAL_RESCUE_TARGET, + "2", SPECIAL_RUNLEVEL2_TARGET, + "3", SPECIAL_RUNLEVEL3_TARGET, + "4", SPECIAL_RUNLEVEL4_TARGET, + "5", SPECIAL_RUNLEVEL5_TARGET, }; assert(word); @@ -333,6 +339,26 @@ static int parse_proc_cmdline_word(const char *word) { "systemd.log_color=0|1 Highlight important log messages\n" "systemd.log_location=0|1 Include code location in log messages\n"); + } else if (startswith(word, "console=")) { + const char *k; + size_t l; + char *w = NULL; + + k = word + 8; + l = strcspn(k, ","); + + /* Ignore the console setting if set to a VT */ + if (l < 4 || + !startswith(k, "tty") || + k[3+strspn(k+3, "0123456789")] != 0) { + + if (!(w = strndup(k, l))) + return -ENOMEM; + } + + free(arg_console); + arg_console = w; + } else if (streq(word, "quiet")) { arg_show_status = false; arg_sysv_console = false; @@ -472,16 +498,18 @@ static int config_parse_cpu_affinity( static int parse_config_file(void) { const ConfigItem items[] = { - { "LogLevel", config_parse_level, NULL, "Manager" }, - { "LogTarget", config_parse_target, NULL, "Manager" }, - { "LogColor", config_parse_color, NULL, "Manager" }, - { "LogLocation", config_parse_location, NULL, "Manager" }, - { "DumpCore", config_parse_bool, &arg_dump_core, "Manager" }, - { "CrashShell", config_parse_bool, &arg_crash_shell, "Manager" }, - { "ShowStatus", config_parse_bool, &arg_show_status, "Manager" }, - { "SysVConsole", config_parse_bool, &arg_sysv_console,"Manager" }, - { "CrashChVT", config_parse_int, &arg_crash_chvt, "Manager" }, - { "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" }, + { "LogLevel", config_parse_level, NULL, "Manager" }, + { "LogTarget", config_parse_target, NULL, "Manager" }, + { "LogColor", config_parse_color, NULL, "Manager" }, + { "LogLocation", config_parse_location, NULL, "Manager" }, + { "DumpCore", config_parse_bool, &arg_dump_core, "Manager" }, + { "CrashShell", config_parse_bool, &arg_crash_shell, "Manager" }, + { "ShowStatus", config_parse_bool, &arg_show_status, "Manager" }, + { "SysVConsole", config_parse_bool, &arg_sysv_console, "Manager" }, + { "CrashChVT", config_parse_int, &arg_crash_chvt, "Manager" }, + { "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" }, + { "MountAuto", config_parse_bool, &arg_mount_auto, "Manager" }, + { "SwapAuto", config_parse_bool, &arg_swap_auto, "Manager" }, { NULL, NULL, NULL, NULL } }; @@ -851,7 +879,7 @@ fail: int main(int argc, char *argv[]) { Manager *m = NULL; - int r, retval = 1; + int r, retval = EXIT_FAILURE; FDSet *fds = NULL; bool reexecute = false; @@ -912,10 +940,10 @@ int main(int argc, char *argv[]) { goto finish; } else if (arg_action == ACTION_DUMP_CONFIGURATION_ITEMS) { unit_dump_config_items(stdout); - retval = 0; + retval = EXIT_SUCCESS; goto finish; } else if (arg_action == ACTION_DONE) { - retval = 0; + retval = EXIT_SUCCESS; goto finish; } @@ -967,15 +995,19 @@ int main(int argc, char *argv[]) { install_crash_handler(); log_full(arg_running_as == MANAGER_SYSTEM ? LOG_INFO : LOG_DEBUG, - PACKAGE_STRING " running in %s mode. (" SYSTEMD_FEATURES ")", manager_running_as_to_string(arg_running_as)); + PACKAGE_STRING " running in %s mode. (" SYSTEMD_FEATURES "; " DISTRIBUTION ")", manager_running_as_to_string(arg_running_as)); if (arg_running_as == MANAGER_SYSTEM && !serialization) { + locale_setup(); + if (arg_show_status) status_welcome(); kmod_setup(); hostname_setup(); loopback_setup(); + + mkdir_p("/dev/.systemd/ask-password/", 0755); } if ((r = manager_new(arg_running_as, &m)) < 0) { @@ -986,6 +1018,11 @@ int main(int argc, char *argv[]) { m->confirm_spawn = arg_confirm_spawn; m->show_status = arg_show_status; m->sysv_console = arg_sysv_console; + m->mount_auto = arg_mount_auto; + m->swap_auto = arg_swap_auto; + + if (arg_console) + manager_set_console(m, arg_console); if ((r = manager_startup(m, serialization, fds)) < 0) log_error("Failed to fully start up daemon: %s", strerror(-r)); @@ -1042,7 +1079,7 @@ int main(int argc, char *argv[]) { if (arg_action == ACTION_TEST) { printf("-> By jobs:\n"); manager_dump_jobs(m, stdout, "\t"); - retval = 0; + retval = EXIT_SUCCESS; goto finish; } } @@ -1056,7 +1093,7 @@ int main(int argc, char *argv[]) { switch (m->exit_code) { case MANAGER_EXIT: - retval = 0; + retval = EXIT_SUCCESS; log_debug("Exit."); goto finish; @@ -1084,9 +1121,12 @@ finish: manager_free(m); free(arg_default_unit); + free(arg_console); dbus_shutdown(); + label_finish(); + if (reexecute) { const char *args[15]; unsigned i = 0; @@ -1151,7 +1191,5 @@ finish: if (getpid() == 1) freeze(); - label_finish(); - return retval; }