manager: get rid of destinction between running_as=system and running_as=init, as there is little value in it and we cannot really test this

This commit is contained in:
Lennart Poettering 2010-06-19 03:15:59 +02:00
parent 5e8d1c9a9f
commit a3d4e06dfa
11 changed files with 32 additions and 38 deletions

View File

@ -608,7 +608,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) { } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
if (m->running_as == MANAGER_INIT) if (m->running_as == MANAGER_SYSTEM)
return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP); return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP);
if (!(reply = dbus_message_new_method_return(message))) if (!(reply = dbus_message_new_method_return(message)))

View File

@ -761,7 +761,7 @@ static int bus_init_system(Manager *m) {
if (m->system_bus) if (m->system_bus)
return 0; return 0;
if (m->running_as != MANAGER_SESSION && m->api_bus) if (m->running_as == MANAGER_SYSTEM && m->api_bus)
m->system_bus = m->api_bus; m->system_bus = m->api_bus;
else { else {
if (!(m->system_bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) { if (!(m->system_bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
@ -819,7 +819,7 @@ static int bus_init_api(Manager *m) {
if (m->api_bus) if (m->api_bus)
return 0; return 0;
if (m->running_as != MANAGER_SESSION && m->system_bus) if (m->running_as == MANAGER_SYSTEM && m->system_bus)
m->api_bus = m->system_bus; m->api_bus = m->system_bus;
else { else {
if (!(m->api_bus = dbus_bus_get_private(m->running_as == MANAGER_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error))) { if (!(m->api_bus = dbus_bus_get_private(m->running_as == MANAGER_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error))) {
@ -914,7 +914,7 @@ static int bus_init_private(Manager *m) {
return 0; return 0;
/* We want the private bus only when running as init */ /* We want the private bus only when running as init */
if (m->running_as != MANAGER_INIT) if (m->running_as != MANAGER_SYSTEM)
return 0; return 0;
if (!(m->private_bus = dbus_server_listen("unix:abstract=/org/freedesktop/systemd1/private", &error))) { if (!(m->private_bus = dbus_server_listen("unix:abstract=/org/freedesktop/systemd1/private", &error))) {
@ -1348,11 +1348,11 @@ int bus_broadcast(Manager *m, DBusMessage *message) {
assert(message); assert(message);
SET_FOREACH(c, m->bus_connections_for_dispatch, i) SET_FOREACH(c, m->bus_connections_for_dispatch, i)
if (c != m->system_bus || m->running_as != MANAGER_SESSION) if (c != m->system_bus || m->running_as == MANAGER_SYSTEM)
oom = !dbus_connection_send(c, message, NULL); oom = !dbus_connection_send(c, message, NULL);
SET_FOREACH(c, m->bus_connections, i) SET_FOREACH(c, m->bus_connections, i)
if (c != m->system_bus || m->running_as != MANAGER_SESSION) if (c != m->system_bus || m->running_as == MANAGER_SYSTEM)
oom = !dbus_connection_send(c, message, NULL); oom = !dbus_connection_send(c, message, NULL);
return oom ? -ENOMEM : 0; return oom ? -ENOMEM : 0;

View File

@ -535,7 +535,7 @@ int main(int argc, char *argv[]) {
goto finish; goto finish;
} }
if ((r = lookup_paths_init(&paths, arg_where == WHERE_SYSTEM ? MANAGER_INIT : MANAGER_SESSION)) < 0) { if ((r = lookup_paths_init(&paths, arg_where == WHERE_SYSTEM ? MANAGER_SYSTEM : MANAGER_SESSION)) < 0) {
log_error("Failed to determine lookup paths: %s", strerror(-r)); log_error("Failed to determine lookup paths: %s", strerror(-r));
goto finish; goto finish;
} }

View File

@ -526,7 +526,7 @@ static int parse_argv(int argc, char *argv[]) {
* ignore and unconditionally read from * ignore and unconditionally read from
* /proc/cmdline. However, we need to ignore those arguments * /proc/cmdline. However, we need to ignore those arguments
* here. */ * here. */
if (running_as != MANAGER_INIT && optind < argc) { if (running_as != MANAGER_SYSTEM && optind < argc) {
log_error("Excess arguments."); log_error("Excess arguments.");
return -EINVAL; return -EINVAL;
} }
@ -540,7 +540,7 @@ static int help(void) {
"Starts up and maintains the system or a session.\n\n" "Starts up and maintains the system or a session.\n\n"
" -h --help Show this help\n" " -h --help Show this help\n"
" --unit=UNIT Set default unit\n" " --unit=UNIT Set default unit\n"
" --running-as=AS Set running as (init, system, session)\n" " --running-as=AS Set running as (system, session)\n"
" --test Determine startup sequence, dump it and exit\n" " --test Determine startup sequence, dump it and exit\n"
" --dump-configuration-items Dump understood unit configuration items\n" " --dump-configuration-items Dump understood unit configuration items\n"
" --confirm-spawn Ask for confirmation when spawning processes\n" " --confirm-spawn Ask for confirmation when spawning processes\n"
@ -631,7 +631,7 @@ int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG); log_set_max_level(LOG_DEBUG);
if (getpid() == 1) { if (getpid() == 1) {
running_as = MANAGER_INIT; running_as = MANAGER_SYSTEM;
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG); log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
} else { } else {
running_as = MANAGER_SESSION; running_as = MANAGER_SESSION;
@ -653,7 +653,7 @@ int main(int argc, char *argv[]) {
/* If we are init, we can block sigkill. Yay. */ /* If we are init, we can block sigkill. Yay. */
ignore_signals(SIGNALS_IGNORE, -1); ignore_signals(SIGNALS_IGNORE, -1);
if (running_as != MANAGER_SESSION) if (running_as == MANAGER_SYSTEM)
if (parse_proc_cmdline() < 0) if (parse_proc_cmdline() < 0)
goto finish; goto finish;
@ -690,12 +690,12 @@ int main(int argc, char *argv[]) {
/* Set up PATH unless it is already set */ /* Set up PATH unless it is already set */
setenv("PATH", setenv("PATH",
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
running_as == MANAGER_INIT); running_as == MANAGER_SYSTEM);
/* Move out of the way, so that we won't block unmounts */ /* Move out of the way, so that we won't block unmounts */
assert_se(chdir("/") == 0); assert_se(chdir("/") == 0);
if (running_as != MANAGER_SESSION) { if (running_as == MANAGER_SYSTEM) {
/* Become a session leader if we aren't one yet. */ /* Become a session leader if we aren't one yet. */
setsid(); setsid();
@ -708,7 +708,7 @@ int main(int argc, char *argv[]) {
/* Reset the console, but only if this is really init and we /* Reset the console, but only if this is really init and we
* are freshly booted */ * are freshly booted */
if (running_as != MANAGER_SESSION && action == ACTION_RUN) { if (running_as == MANAGER_SYSTEM && action == ACTION_RUN) {
console_setup(getpid() == 1 && !serialization); console_setup(getpid() == 1 && !serialization);
make_null_stdio(); make_null_stdio();
} }
@ -723,7 +723,7 @@ int main(int argc, char *argv[]) {
log_debug("systemd running in %s mode.", manager_running_as_to_string(running_as)); log_debug("systemd running in %s mode.", manager_running_as_to_string(running_as));
if (running_as == MANAGER_INIT) { if (running_as == MANAGER_SYSTEM) {
kmod_setup(); kmod_setup();
hostname_setup(); hostname_setup();
loopback_setup(); loopback_setup();

View File

@ -177,7 +177,7 @@ static int manager_setup_signals(Manager *m) {
if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->signal_watch.fd, &ev) < 0) if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->signal_watch.fd, &ev) < 0)
return -errno; return -errno;
if (m->running_as == MANAGER_INIT) if (m->running_as == MANAGER_SYSTEM)
return enable_special_signals(m); return enable_special_signals(m);
return 0; return 0;
@ -1780,7 +1780,7 @@ static int manager_process_signal_fd(Manager *m) {
break; break;
case SIGTERM: case SIGTERM:
if (m->running_as == MANAGER_INIT) { if (m->running_as == MANAGER_SYSTEM) {
/* This is for compatibility with the /* This is for compatibility with the
* original sysvinit */ * original sysvinit */
m->exit_code = MANAGER_REEXECUTE; m->exit_code = MANAGER_REEXECUTE;
@ -1790,7 +1790,7 @@ static int manager_process_signal_fd(Manager *m) {
/* Fall through */ /* Fall through */
case SIGINT: case SIGINT:
if (m->running_as == MANAGER_INIT) { if (m->running_as == MANAGER_SYSTEM) {
manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE); manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE);
break; break;
} }
@ -1804,14 +1804,14 @@ static int manager_process_signal_fd(Manager *m) {
break; break;
case SIGWINCH: case SIGWINCH:
if (m->running_as == MANAGER_INIT) if (m->running_as == MANAGER_SYSTEM)
manager_start_target(m, SPECIAL_KBREQUEST_TARGET, JOB_REPLACE); manager_start_target(m, SPECIAL_KBREQUEST_TARGET, JOB_REPLACE);
/* This is a nop on non-init */ /* This is a nop on non-init */
break; break;
case SIGPWR: case SIGPWR:
if (m->running_as == MANAGER_INIT) if (m->running_as == MANAGER_SYSTEM)
manager_start_target(m, SPECIAL_SIGPWR_TARGET, JOB_REPLACE); manager_start_target(m, SPECIAL_SIGPWR_TARGET, JOB_REPLACE);
/* This is a nop on non-init */ /* This is a nop on non-init */
@ -2105,7 +2105,7 @@ void manager_write_utmp_reboot(Manager *m) {
if (m->utmp_reboot_written) if (m->utmp_reboot_written)
return; return;
if (m->running_as != MANAGER_INIT) if (m->running_as != MANAGER_SYSTEM)
return; return;
if (!manager_utmp_good(m)) if (!manager_utmp_good(m))
@ -2131,7 +2131,7 @@ void manager_write_utmp_runlevel(Manager *m, Unit *u) {
if (u->meta.type != UNIT_TARGET) if (u->meta.type != UNIT_TARGET)
return; return;
if (m->running_as != MANAGER_INIT) if (m->running_as != MANAGER_SYSTEM)
return; return;
if (!manager_utmp_good(m)) if (!manager_utmp_good(m))
@ -2337,7 +2337,6 @@ finish:
} }
static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = { static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
[MANAGER_INIT] = "init",
[MANAGER_SYSTEM] = "system", [MANAGER_SYSTEM] = "system",
[MANAGER_SESSION] = "session" [MANAGER_SESSION] = "session"
}; };

View File

@ -46,9 +46,8 @@ typedef enum ManagerExitCode {
} ManagerExitCode; } ManagerExitCode;
typedef enum ManagerRunningAs { typedef enum ManagerRunningAs {
MANAGER_INIT, /* root and pid=1 */ MANAGER_SYSTEM,
MANAGER_SYSTEM, /* root and pid!=1 */ MANAGER_SESSION,
MANAGER_SESSION, /* non-root, for a session */
_MANAGER_RUNNING_AS_MAX, _MANAGER_RUNNING_AS_MAX,
_MANAGER_RUNNING_AS_INVALID = -1 _MANAGER_RUNNING_AS_INVALID = -1
} ManagerRunningAs; } ManagerRunningAs;

View File

@ -254,7 +254,7 @@ static int mount_add_target_links(Mount *m) {
if ((r = manager_load_unit(UNIT(m)->meta.manager, target, NULL, &tu)) < 0) if ((r = manager_load_unit(UNIT(m)->meta.manager, target, NULL, &tu)) < 0)
return r; return r;
if (automount && m->meta.manager->running_as != MANAGER_SESSION) { if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
Unit *am; Unit *am;
if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0) if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0)
@ -268,7 +268,7 @@ static int mount_add_target_links(Mount *m) {
} else { } else {
if (!noauto && handle) if (!noauto && handle)
if (user || m->meta.manager->running_as != MANAGER_SESSION) if (user || m->meta.manager->running_as == MANAGER_SYSTEM)
if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true)) < 0) if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true)) < 0)
return r; return r;
@ -341,9 +341,7 @@ static int mount_load(Unit *u) {
what = m->parameters_proc_self_mountinfo.what; what = m->parameters_proc_self_mountinfo.what;
if (what) if (what)
if ((r = unit_add_node_link(u, what, if ((r = unit_add_node_link(u, what, u->meta.manager->running_as == MANAGER_SYSTEM)) < 0)
(u->meta.manager->running_as == MANAGER_INIT ||
u->meta.manager->running_as == MANAGER_SYSTEM))) < 0)
return r; return r;
if ((r = mount_add_mount_links(m)) < 0) if ((r = mount_add_mount_links(m)) < 0)

View File

@ -187,7 +187,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) {
return -ENOMEM; return -ENOMEM;
} }
if (running_as == MANAGER_INIT) { if (running_as == MANAGER_SYSTEM) {
/* /etc/init.d/ compatibility does not matter to users */ /* /etc/init.d/ compatibility does not matter to users */
if ((e = getenv("SYSTEMD_SYSVINIT_PATH"))) if ((e = getenv("SYSTEMD_SYSVINIT_PATH")))

View File

@ -116,7 +116,7 @@ static int swap_add_target_links(Swap *s) {
if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, &tu)) < 0) if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, &tu)) < 0)
return r; return r;
if (!p->noauto && p->handle && s->meta.manager->running_as != MANAGER_SESSION) if (!p->noauto && p->handle && s->meta.manager->running_as == MANAGER_SYSTEM)
if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(s), true)) < 0) if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(s), true)) < 0)
return r; return r;
@ -180,9 +180,7 @@ static int swap_load(Unit *u) {
if ((r = unit_set_description(u, s->what)) < 0) if ((r = unit_set_description(u, s->what)) < 0)
return r; return r;
if ((r = unit_add_node_link(u, s->what, if ((r = unit_add_node_link(u, s->what, u->meta.manager->running_as == MANAGER_SYSTEM)) < 0)
(u->meta.manager->running_as == MANAGER_INIT ||
u->meta.manager->running_as == MANAGER_SYSTEM))) < 0)
return r; return r;
if ((r = swap_add_mount_links(s)) < 0) if ((r = swap_add_mount_links(s)) < 0)

View File

@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
assert_se(set_unit_path("test2") >= 0); assert_se(set_unit_path("test2") >= 0);
assert_se(manager_new(MANAGER_INIT, false, &m) >= 0); assert_se(manager_new(MANAGER_SYSTEM, false, &m) >= 0);
printf("Load1:\n"); printf("Load1:\n");
assert_se(manager_load_unit(m, "a.service", NULL, &a) >= 0); assert_se(manager_load_unit(m, "a.service", NULL, &a) >= 0);

View File

@ -542,7 +542,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
if ((r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0) if ((r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0)
return r; return r;
if (u->meta.manager->running_as != MANAGER_SESSION) if (u->meta.manager->running_as == MANAGER_SYSTEM)
if ((r = unit_add_dependency_by_name(u, UNIT_REQUIRES, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0) if ((r = unit_add_dependency_by_name(u, UNIT_REQUIRES, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0)
return r; return r;