X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fmain.c;h=99e277c67b9fd290bd4095425344c852e62e529e;hb=550c4dcc4184d5c4d55d3786b66797e5fb99c30a;hp=cd73ee2cffd4d6f0a26f85fadde37182b1fac78d;hpb=e9ddabc246ced239cbce436e16792dc4c3d1b52d;p=elogind.git diff --git a/src/main.c b/src/main.c index cd73ee2cf..99e277c67 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "manager.h" #include "log.h" @@ -48,6 +49,7 @@ #include "missing.h" #include "label.h" #include "build.h" +#include "strv.h" static enum { ACTION_RUN, @@ -71,6 +73,7 @@ static bool arg_sysv_console = true; static bool arg_mount_auto = true; static bool arg_swap_auto = true; static char *arg_console = NULL; +static char **arg_default_controllers = NULL; static FILE* serialization = NULL; @@ -501,6 +504,7 @@ static int parse_config_file(void) { { "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" }, { "MountAuto", config_parse_bool, &arg_mount_auto, "Manager" }, { "SwapAuto", config_parse_bool, &arg_swap_auto, "Manager" }, + { "DefaultControllers", config_parse_strv, &arg_default_controllers, "Manager" }, { NULL, NULL, NULL, NULL } }; @@ -513,7 +517,7 @@ static int parse_config_file(void) { const char *fn; int r; - fn = arg_running_as == MANAGER_SYSTEM ? SYSTEM_CONFIG_FILE : SESSION_CONFIG_FILE; + fn = arg_running_as == MANAGER_SYSTEM ? SYSTEM_CONFIG_FILE : USER_CONFIG_FILE; if (!(f = fopen(fn, "re"))) { if (errno == ENOENT) @@ -572,7 +576,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_LOG_LOCATION, ARG_UNIT, ARG_SYSTEM, - ARG_SESSION, + ARG_USER, ARG_TEST, ARG_DUMP_CONFIGURATION_ITEMS, ARG_DUMP_CORE, @@ -591,7 +595,7 @@ static int parse_argv(int argc, char *argv[]) { { "log-location", optional_argument, NULL, ARG_LOG_LOCATION }, { "unit", required_argument, NULL, ARG_UNIT }, { "system", no_argument, NULL, ARG_SYSTEM }, - { "session", no_argument, NULL, ARG_SESSION }, + { "user", no_argument, NULL, ARG_USER }, { "test", no_argument, NULL, ARG_TEST }, { "help", no_argument, NULL, 'h' }, { "dump-configuration-items", no_argument, NULL, ARG_DUMP_CONFIGURATION_ITEMS }, @@ -670,8 +674,8 @@ static int parse_argv(int argc, char *argv[]) { arg_running_as = MANAGER_SYSTEM; break; - case ARG_SESSION: - arg_running_as = MANAGER_SESSION; + case ARG_USER: + arg_running_as = MANAGER_USER; break; case ARG_TEST: @@ -793,14 +797,14 @@ static int parse_argv(int argc, char *argv[]) { static int help(void) { printf("%s [OPTIONS...]\n\n" - "Starts up and maintains the system or a session.\n\n" + "Starts up and maintains the system or user services.\n\n" " -h --help Show this help\n" " --test Determine startup sequence, dump it and exit\n" " --dump-configuration-items Dump understood unit configuration items\n" " --introspect[=INTERFACE] Extract D-Bus interface data\n" " --unit=UNIT Set default unit\n" " --system Run a system instance, even if PID != 1\n" - " --session Run a session instance\n" + " --user Run a user instance\n" " --dump-core Dump core on crash\n" " --crash-shell Run shell on crash\n" " --confirm-spawn Ask for confirmation when spawning processes\n" @@ -889,6 +893,24 @@ static struct dual_timestamp* parse_initrd_timestamp(struct dual_timestamp *t) { return t; } +static void test_mtab(void) { + char *p; + + if (readlink_malloc("/etc/mtab", &p) >= 0) { + bool b; + + b = streq(p, "/proc/self/mounts"); + free(p); + + if (b) + return; + } + + log_error("/etc/mtab is not a symlink or not pointing to /proc/self/mounts. " + "This is not supported anymore. " + "Please make sure to replace this file by a symlink to avoid incorrect or misleading mount(8) output."); +} + int main(int argc, char *argv[]) { Manager *m = NULL; int r, retval = EXIT_FAILURE; @@ -896,6 +918,7 @@ int main(int argc, char *argv[]) { bool reexecute = false; const char *shutdown_verb = NULL; dual_timestamp initrd_timestamp = { 0ULL, 0ULL }; + char systemd[] = "systemd"; if (getpid() != 1 && strstr(program_invocation_short_name, "init")) { /* This is compatbility support for SysV, where @@ -907,6 +930,14 @@ int main(int argc, char *argv[]) { return 1; } + /* If we get started via the /sbin/init symlink then we are + called 'init'. After a subsequent reexecution we are then + called 'systemd'. That is confusing, hence let's call us + systemd right-away. */ + + program_invocation_short_name = systemd; + prctl(PR_SET_NAME, systemd); + log_show_color(isatty(STDERR_FILENO) > 0); log_show_location(false); log_set_max_level(LOG_INFO); @@ -923,7 +954,7 @@ int main(int argc, char *argv[]) { if (label_init() < 0) goto finish; } else { - arg_running_as = MANAGER_SESSION; + arg_running_as = MANAGER_USER; log_set_target(LOG_TARGET_CONSOLE); } @@ -1038,6 +1069,8 @@ int main(int argc, char *argv[]) { loopback_setup(); mkdir_p("/dev/.systemd/ask-password/", 0755); + + test_mtab(); } if ((r = manager_new(arg_running_as, &m)) < 0) { @@ -1059,6 +1092,9 @@ int main(int argc, char *argv[]) { if (arg_console) manager_set_console(m, arg_console); + if (arg_default_controllers) + manager_set_default_controllers(m, arg_default_controllers); + if ((r = manager_startup(m, serialization, fds)) < 0) log_error("Failed to fully start up daemon: %s", strerror(-r)); @@ -1181,6 +1217,7 @@ finish: free(arg_default_unit); free(arg_console); + strv_free(arg_default_controllers); dbus_shutdown(); @@ -1205,7 +1242,7 @@ finish: if (arg_running_as == MANAGER_SYSTEM) args[i++] = "--system"; else - args[i++] = "--session"; + args[i++] = "--user"; if (arg_dump_core) args[i++] = "--dump-core";