]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
main: simplify things a bit by moving container check into fixup_environment()
authorLennart Poettering <lennart@poettering.net>
Tue, 19 Jul 2016 15:00:36 +0000 (17:00 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 22 Jul 2016 13:33:12 +0000 (15:33 +0200)
src/core/main.c

index fc04fb8051795e17ad4af8b9e765a84ea616b204..4c767a3c9d5aabad6a81fe8a2d05e9e86b81fe6e 100644 (file)
@@ -1298,6 +1298,11 @@ static int fixup_environment(void) {
         _cleanup_free_ char *term = NULL;
         int r;
 
+        /* We expect the environment to be set correctly
+         * if run inside a container. */
+        if (detect_container() > 0)
+                return 0;
+
         /* When started as PID1, the kernel uses /dev/console
          * for our stdios and uses TERM=linux whatever the
          * backend device used by the console. We try to make
@@ -1314,7 +1319,7 @@ static int fixup_environment(void) {
         if (r == 0) {
                 term = strdup(default_term_for_tty("/dev/console") + 5);
                 if (!term)
-                        return -errno;
+                        return -ENOMEM;
         }
 
         if (setenv("TERM", term, 1) < 0)
@@ -1508,13 +1513,10 @@ int main(int argc, char *argv[]) {
         }
 
         if (arg_system) {
-                /* We expect the environment to be set correctly
-                 * if run inside a container. */
-                if (detect_container() <= 0)
-                        if (fixup_environment() < 0) {
-                                error_message = "Failed to fix up PID1 environment";
-                                goto finish;
-                        }
+                if (fixup_environment() < 0) {
+                        error_message = "Failed to fix up PID1 environment";
+                        goto finish;
+                }
 
                 /* Try to figure out if we can use colors with the console. No
                  * need to do that for user instances since they never log