chiark / gitweb /
manager: get rid of destinction between running_as=system and running_as=init, as...
authorLennart Poettering <lennart@poettering.net>
Sat, 19 Jun 2010 01:15:59 +0000 (03:15 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 19 Jun 2010 01:15:59 +0000 (03:15 +0200)
src/dbus-manager.c
src/dbus.c
src/install.c
src/main.c
src/manager.c
src/manager.h
src/mount.c
src/path-lookup.c
src/swap.c
src/test-engine.c
src/unit.c

index 7818257..b3e42fc 100644 (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")) {
 
-                if (m->running_as == MANAGER_INIT)
+                if (m->running_as == MANAGER_SYSTEM)
                         return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP);
 
                 if (!(reply = dbus_message_new_method_return(message)))
index a34c7dc..74b1c37 100644 (file)
@@ -761,7 +761,7 @@ static int bus_init_system(Manager *m) {
         if (m->system_bus)
                 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;
         else {
                 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)
                 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;
         else {
                 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;
 
         /* We want the private bus only when running as init */
-        if (m->running_as != MANAGER_INIT)
+        if (m->running_as != MANAGER_SYSTEM)
                 return 0;
 
         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);
 
         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);
 
         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);
 
         return oom ? -ENOMEM : 0;
index e30f623..e59e108 100644 (file)
@@ -535,7 +535,7 @@ int main(int argc, char *argv[]) {
                 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));
                 goto finish;
         }
index 21b4174..f00d43a 100644 (file)
@@ -526,7 +526,7 @@ static int parse_argv(int argc, char *argv[]) {
          * ignore and unconditionally read from
          * /proc/cmdline. However, we need to ignore those arguments
          * here. */
-        if (running_as != MANAGER_INIT && optind < argc) {
+        if (running_as != MANAGER_SYSTEM && optind < argc) {
                 log_error("Excess arguments.");
                 return -EINVAL;
         }
@@ -540,7 +540,7 @@ static int help(void) {
                "Starts up and maintains the system or a session.\n\n"
                "  -h --help                      Show this help\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"
                "     --dump-configuration-items  Dump understood unit configuration items\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);
 
         if (getpid() == 1) {
-                running_as = MANAGER_INIT;
+                running_as = MANAGER_SYSTEM;
                 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         } else {
                 running_as = MANAGER_SESSION;
@@ -653,7 +653,7 @@ int main(int argc, char *argv[]) {
         /* If we are init, we can block sigkill. Yay. */
         ignore_signals(SIGNALS_IGNORE, -1);
 
-        if (running_as != MANAGER_SESSION)
+        if (running_as == MANAGER_SYSTEM)
                 if (parse_proc_cmdline() < 0)
                         goto finish;
 
@@ -690,12 +690,12 @@ int main(int argc, char *argv[]) {
         /* Set up PATH unless it is already set */
         setenv("PATH",
                "/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 */
         assert_se(chdir("/")  == 0);
 
-        if (running_as != MANAGER_SESSION) {
+        if (running_as == MANAGER_SYSTEM) {
                 /* Become a session leader if we aren't one yet. */
                 setsid();
 
@@ -708,7 +708,7 @@ int main(int argc, char *argv[]) {
 
         /* Reset the console, but only if this is really init and we
          * are freshly booted */
-        if (running_as != MANAGER_SESSION && action == ACTION_RUN) {
+        if (running_as == MANAGER_SYSTEM && action == ACTION_RUN) {
                 console_setup(getpid() == 1 && !serialization);
                 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));
 
-        if (running_as == MANAGER_INIT) {
+        if (running_as == MANAGER_SYSTEM) {
                 kmod_setup();
                 hostname_setup();
                 loopback_setup();
index 456241f..e211eca 100644 (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)
                 return -errno;
 
-        if (m->running_as == MANAGER_INIT)
+        if (m->running_as == MANAGER_SYSTEM)
                 return enable_special_signals(m);
 
         return 0;
@@ -1780,7 +1780,7 @@ static int manager_process_signal_fd(Manager *m) {
                         break;
 
                 case SIGTERM:
-                        if (m->running_as == MANAGER_INIT) {
+                        if (m->running_as == MANAGER_SYSTEM) {
                                 /* This is for compatibility with the
                                  * original sysvinit */
                                 m->exit_code = MANAGER_REEXECUTE;
@@ -1790,7 +1790,7 @@ static int manager_process_signal_fd(Manager *m) {
                         /* Fall through */
 
                 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);
                                 break;
                         }
@@ -1804,14 +1804,14 @@ static int manager_process_signal_fd(Manager *m) {
                         break;
 
                 case SIGWINCH:
-                        if (m->running_as == MANAGER_INIT)
+                        if (m->running_as == MANAGER_SYSTEM)
                                 manager_start_target(m, SPECIAL_KBREQUEST_TARGET, JOB_REPLACE);
 
                         /* This is a nop on non-init */
                         break;
 
                 case SIGPWR:
-                        if (m->running_as == MANAGER_INIT)
+                        if (m->running_as == MANAGER_SYSTEM)
                                 manager_start_target(m, SPECIAL_SIGPWR_TARGET, JOB_REPLACE);
 
                         /* This is a nop on non-init */
@@ -2105,7 +2105,7 @@ void manager_write_utmp_reboot(Manager *m) {
         if (m->utmp_reboot_written)
                 return;
 
-        if (m->running_as != MANAGER_INIT)
+        if (m->running_as != MANAGER_SYSTEM)
                 return;
 
         if (!manager_utmp_good(m))
@@ -2131,7 +2131,7 @@ void manager_write_utmp_runlevel(Manager *m, Unit *u) {
         if (u->meta.type != UNIT_TARGET)
                 return;
 
-        if (m->running_as != MANAGER_INIT)
+        if (m->running_as != MANAGER_SYSTEM)
                 return;
 
         if (!manager_utmp_good(m))
@@ -2337,7 +2337,6 @@ finish:
 }
 
 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
-        [MANAGER_INIT] = "init",
         [MANAGER_SYSTEM] = "system",
         [MANAGER_SESSION] = "session"
 };
index 2a04bc7..6e74773 100644 (file)
@@ -46,9 +46,8 @@ typedef enum ManagerExitCode {
 } ManagerExitCode;
 
 typedef enum ManagerRunningAs {
-        MANAGER_INIT,      /* root and pid=1 */
-        MANAGER_SYSTEM,    /* root and pid!=1 */
-        MANAGER_SESSION,   /* non-root, for a session */
+        MANAGER_SYSTEM,
+        MANAGER_SESSION,
         _MANAGER_RUNNING_AS_MAX,
         _MANAGER_RUNNING_AS_INVALID = -1
 } ManagerRunningAs;
index 94f1929..c95581f 100644 (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)
                 return r;
 
-        if (automount && m->meta.manager->running_as != MANAGER_SESSION) {
+        if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
                 Unit *am;
 
                 if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0)
@@ -268,7 +268,7 @@ static int mount_add_target_links(Mount *m) {
         } else {
 
                 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)
                                         return r;
 
@@ -341,9 +341,7 @@ static int mount_load(Unit *u) {
                         what = m->parameters_proc_self_mountinfo.what;
 
                 if (what)
-                        if ((r = unit_add_node_link(u, what,
-                                                    (u->meta.manager->running_as == MANAGER_INIT ||
-                                                     u->meta.manager->running_as == MANAGER_SYSTEM))) < 0)
+                        if ((r = unit_add_node_link(u, what, u->meta.manager->running_as == MANAGER_SYSTEM)) < 0)
                                 return r;
 
                 if ((r = mount_add_mount_links(m)) < 0)
index 093e04d..4160d55 100644 (file)
@@ -187,7 +187,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) {
                                 return -ENOMEM;
         }
 
-        if (running_as == MANAGER_INIT) {
+        if (running_as == MANAGER_SYSTEM) {
                 /* /etc/init.d/ compatibility does not matter to users */
 
                 if ((e = getenv("SYSTEMD_SYSVINIT_PATH")))
index 5b3073b..501a1d9 100644 (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)
                 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)
                         return r;
 
@@ -180,9 +180,7 @@ static int swap_load(Unit *u) {
                         if ((r = unit_set_description(u, s->what)) < 0)
                                 return r;
 
-                if ((r = unit_add_node_link(u, s->what,
-                                            (u->meta.manager->running_as == MANAGER_INIT ||
-                                             u->meta.manager->running_as == MANAGER_SYSTEM))) < 0)
+                if ((r = unit_add_node_link(u, s->what, u->meta.manager->running_as == MANAGER_SYSTEM)) < 0)
                         return r;
 
                 if ((r = swap_add_mount_links(s)) < 0)
index eb17f58..60c6aa2 100644 (file)
@@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
 
         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");
         assert_se(manager_load_unit(m, "a.service", NULL, &a) >= 0);
index c12c2a7..c546035 100644 (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)
                 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)
                         return r;