]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
update-utmp: swap q <-> r
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 Apr 2023 19:31:21 +0000 (04:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 24 May 2023 11:06:10 +0000 (20:06 +0900)
We usually use 'r' for general purpose.

No functional change, just refactoring.

src/update-utmp/update-utmp.c

index 7121f304c759e939e946fa2b73d6825967205cce..e6739db1c32ed704ea4ebcadc0f12c92b46dc847 100644 (file)
@@ -110,7 +110,7 @@ static int get_current_runlevel(Context *c) {
 static int on_reboot(int argc, char *argv[], void *userdata) {
         Context *c = ASSERT_PTR(userdata);
         usec_t t = 0, boottime;
-        int r = 0, q;
+        int r, q = 0;
 
         /* We finished start-up, so let's write the utmp record and send the audit msg. */
 
@@ -118,7 +118,7 @@ static int on_reboot(int argc, char *argv[], void *userdata) {
         if (c->audit_fd >= 0)
                 if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
                     errno != EPERM)
-                        r = log_error_errno(errno, "Failed to send audit message: %m");
+                        q = log_error_errno(errno, "Failed to send audit message: %m");
 #endif
 
         /* If this call fails, then utmp_put_reboot() will fix to the current time. */
@@ -129,15 +129,15 @@ static int on_reboot(int argc, char *argv[], void *userdata) {
          * system clock wasn't set right during early boot. By manually converting the monotonic clock to the
          * system clock here we can compensate for incorrectly set clocks during early boot. */
 
-        q = utmp_put_reboot(boottime);
-        if (q < 0)
-                r = log_error_errno(q, "Failed to write utmp record: %m");
+        r = utmp_put_reboot(boottime);
+        if (r < 0)
+                return log_error_errno(r, "Failed to write utmp record: %m");
 
-        return r;
+        return q;
 }
 
 static int on_shutdown(int argc, char *argv[], void *userdata) {
-        int r = 0, q;
+        int r, q = 0;
 
         /* We started shut-down, so let's write the utmp record and send the audit msg. */
 
@@ -147,28 +147,28 @@ static int on_shutdown(int argc, char *argv[], void *userdata) {
         if (c->audit_fd >= 0)
                 if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
                     errno != EPERM)
-                        r = log_error_errno(errno, "Failed to send audit message: %m");
+                        q = log_error_errno(errno, "Failed to send audit message: %m");
 #endif
 
-        q = utmp_put_shutdown();
-        if (q < 0)
-                r = log_error_errno(q, "Failed to write utmp record: %m");
+        r = utmp_put_shutdown();
+        if (r < 0)
+                return log_error_errno(r, "Failed to write utmp record: %m");
 
-        return r;
+        return q;
 }
 
 static int on_runlevel(int argc, char *argv[], void *userdata) {
         Context *c = ASSERT_PTR(userdata);
-        int r = 0, q, previous, runlevel;
+        int r, q = 0, previous, runlevel;
 
         /* We finished changing runlevel, so let's write the utmp record and send the audit msg. */
 
         /* First, get last runlevel */
-        q = utmp_get_runlevel(&previous, NULL);
+        r = utmp_get_runlevel(&previous, NULL);
 
-        if (q < 0) {
-                if (!IN_SET(q, -ESRCH, -ENOENT))
-                        return log_error_errno(q, "Failed to get current runlevel: %m");
+        if (r < 0) {
+                if (!IN_SET(r, -ESRCH, -ENOENT))
+                        return log_error_errno(r, "Failed to get current runlevel: %m");
 
                 previous = 0;
         }
@@ -195,15 +195,15 @@ static int on_runlevel(int argc, char *argv[], void *userdata) {
 
                 if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s,
                                                 "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM)
-                        r = log_error_errno(errno, "Failed to send audit message: %m");
+                        q = log_error_errno(errno, "Failed to send audit message: %m");
         }
 #endif
 
-        q = utmp_put_runlevel(runlevel, previous);
-        if (q < 0 && !IN_SET(q, -ESRCH, -ENOENT))
-                return log_error_errno(q, "Failed to write utmp record: %m");
+        r = utmp_put_runlevel(runlevel, previous);
+        if (r < 0 && !IN_SET(r, -ESRCH, -ENOENT))
+                return log_error_errno(r, "Failed to write utmp record: %m");
 
-        return r;
+        return q;
 }
 
 static int run(int argc, char *argv[]) {