chiark / gitweb /
main: don't segfault when --log-color is passed without parameter
[elogind.git] / src / main.c
index 99f6bdd71212ac33010c381ce0678666f169e1cd..21b4174a87d6b602bb2cf8ca81010c3f8adeb501 100644 (file)
@@ -412,19 +412,25 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case ARG_LOG_COLOR:
 
-                        if ((r = log_show_color_from_string(optarg)) < 0) {
-                                log_error("Failed to parse log color setting %s.", optarg);
-                                return r;
-                        }
+                        if (optarg) {
+                                if ((r = log_show_color_from_string(optarg)) < 0) {
+                                        log_error("Failed to parse log color setting %s.", optarg);
+                                        return r;
+                                }
+                        } else
+                                log_show_color(true);
 
                         break;
 
                 case ARG_LOG_LOCATION:
 
-                        if ((r = log_show_location_from_string(optarg)) < 0) {
-                                log_error("Failed to parse log location setting %s.", optarg);
-                                return r;
-                        }
+                        if (optarg) {
+                                if ((r = log_show_location_from_string(optarg)) < 0) {
+                                        log_error("Failed to parse log location setting %s.", optarg);
+                                        return r;
+                                }
+                        } else
+                                log_show_location(true);
 
                         break;
 
@@ -610,6 +616,16 @@ int main(int argc, char *argv[]) {
         FDSet *fds = NULL;
         bool reexecute = false;
 
+        if (getpid() != 1 && strstr(program_invocation_short_name, "init")) {
+                /* This is compatbility support for SysV, where
+                 * calling init as a user is identical to telinit. */
+
+                errno = -ENOENT;
+                execv(SYSTEMCTL_BINARY_PATH, argv);
+                log_error("Failed to exec " SYSTEMCTL_BINARY_PATH ": %m");
+                return 1;
+        }
+
         log_show_color(true);
         log_show_location(false);
         log_set_max_level(LOG_DEBUG);