]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
manager: simplify manager_get_confirm_spawn() a bit
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Aug 2019 15:34:16 +0000 (17:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Aug 2019 15:34:19 +0000 (17:34 +0200)
Let's use our usual way of storing error codes.

Let's remove a redundant temporary variable we never change

src/core/manager.c

index dfe8997f9d12c1049c7a3f74baea8555a29489a3..8d691a19c3d3d45bbb058938665368a8570ced19 100644 (file)
@@ -4072,10 +4072,11 @@ static bool manager_get_show_status(Manager *m, StatusType type) {
 
 const char *manager_get_confirm_spawn(Manager *m) {
         static int last_errno = 0;
-        const char *vc = m->confirm_spawn;
         struct stat st;
         int r;
 
+        assert(m);
+
         /* Here's the deal: we want to test the validity of the console but don't want
          * PID1 to go through the whole console process which might block. But we also
          * want to warn the user only once if something is wrong with the console so we
@@ -4091,25 +4092,26 @@ const char *manager_get_confirm_spawn(Manager *m) {
          * reason the configured console is not ready, we fallback to the default
          * console. */
 
-        if (!vc || path_equal(vc, "/dev/console"))
-                return vc;
+        if (!m->confirm_spawn || path_equal(m->confirm_spawn, "/dev/console"))
+                return m->confirm_spawn;
 
-        r = stat(vc, &st);
-        if (r < 0)
+        if (stat(m->confirm_spawn, &st) < 0) {
+                r = -errno;
                 goto fail;
+        }
 
         if (!S_ISCHR(st.st_mode)) {
-                errno = ENOTTY;
+                r = -ENOTTY;
                 goto fail;
         }
 
         last_errno = 0;
-        return vc;
+        return m->confirm_spawn;
+
 fail:
-        if (last_errno != errno) {
-                last_errno = errno;
-                log_warning_errno(errno, "Failed to open %s: %m, using default console", vc);
-        }
+        if (last_errno != r)
+                last_errno = log_warning_errno(r, "Failed to open %s, using default console: %m", m->confirm_spawn);
+
         return "/dev/console";
 }