chiark / gitweb /
sysv: drop warning about missing chkconfig header
[elogind.git] / main.c
diff --git a/main.c b/main.c
index 29be801125616f773878129a17af20735ca291f7..b0b3cfb580cff56f29f93f399b09236717633a8a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -36,6 +36,7 @@
 #include "log.h"
 #include "mount-setup.h"
 #include "hostname-setup.h"
+#include "loopback-setup.h"
 #include "load-fragment.h"
 #include "fdset.h"
 
@@ -164,7 +165,7 @@ static void install_crash_handler(void) {
         assert_se(sigaction(SIGABRT, &sa, NULL) == 0);
 }
 
-static int console_setup(void) {
+static int console_setup(bool do_reset) {
         int tty_fd = -1, null_fd = -1, r = 0;
 
         /* If we are init, we connect stdout/stderr to /dev/console
@@ -188,8 +189,9 @@ static int console_setup(void) {
         assert(tty_fd >= 3);
         assert(null_fd >= 3);
 
-        if (reset_terminal(tty_fd) < 0)
-                log_error("Failed to reset /dev/console: %m");
+        if (do_reset)
+                if (reset_terminal(tty_fd) < 0)
+                        log_error("Failed to reset /dev/console: %m");
 
         if (dup2(tty_fd, STDOUT_FILENO) < 0 ||
             dup2(tty_fd, STDERR_FILENO) < 0 ||
@@ -462,6 +464,15 @@ static int parse_argv(int argc, char *argv[]) {
                         return -EINVAL;
                 }
 
+        /* PID 1 will get the kernel arguments as parameters, which we
+         * ignore and unconditionally read from
+         * /proc/cmdline. However, we need to ignore those arguments
+         * here. */
+        if (running_as != MANAGER_INIT && optind < argc) {
+                log_error("Excess arguments.");
+                return -EINVAL;
+        }
+
         return 0;
 }
 
@@ -612,8 +623,10 @@ int main(int argc, char *argv[]) {
                 umask(0);
         }
 
-        if (running_as == MANAGER_INIT)
-                console_setup();
+        /* Reset the console, but only if this is really init and we
+         * are freshly booted */
+        if (running_as == MANAGER_INIT && action == ACTION_RUN)
+                console_setup(getpid() == 1 && !serialization);
 
         /* Make sure D-Bus doesn't fiddle with the SIGPIPE handlers */
         dbus_connection_set_change_sigpipe(FALSE);
@@ -629,8 +642,10 @@ 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_INIT) {
                 hostname_setup();
+                loopback_setup();
+        }
 
         if ((r = manager_new(running_as, confirm_spawn, &m)) < 0) {
                 log_error("Failed to allocate manager object: %s", strerror(-r));
@@ -638,7 +653,7 @@ int main(int argc, char *argv[]) {
         }
 
         if ((r = manager_startup(m, serialization, fds)) < 0)
-                log_error("Failed to fully startup daemon: %s", strerror(-r));
+                log_error("Failed to fully start up daemon: %s", strerror(-r));
 
         if (fds) {
                 /* This will close all file descriptors that were opened, but
@@ -665,7 +680,7 @@ int main(int argc, char *argv[]) {
                 }
 
                 if (action == ACTION_TEST) {
-                        printf(" By units:\n");
+                        printf("-> By units:\n");
                         manager_dump_units(m, stdout, "\t");
                 }
 
@@ -675,7 +690,7 @@ int main(int argc, char *argv[]) {
                 }
 
                 if (action == ACTION_TEST) {
-                        printf(" By jobs:\n");
+                        printf("-> By jobs:\n");
                         manager_dump_jobs(m, stdout, "\t");
                         retval = 0;
                         goto finish;
@@ -701,7 +716,6 @@ int main(int argc, char *argv[]) {
                         break;
 
                 case MANAGER_REEXECUTE:
-
                         if (prepare_reexecute(m, &serialization, &fds) < 0)
                                 goto finish;