[systemd-devel] [PATCH 3/7] systemctl: honour !HAVE_UTMP

Emil Renner Berthing systemd at esmil.dk
Wed Sep 24 08:25:02 PDT 2014


---
 src/systemctl/systemctl.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 9012128..b9e165c 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -47,7 +47,6 @@
 #include "util.h"
 #include "macro.h"
 #include "set.h"
-#include "utmp-wtmp.h"
 #include "special.h"
 #include "initreq.h"
 #include "path-util.h"
@@ -73,6 +72,10 @@
 #include "bus-error.h"
 #include "bus-errors.h"
 
+#ifdef HAVE_UTMP
+#include "utmp-wtmp.h"
+#endif
+
 static char **arg_types = NULL;
 static char **arg_states = NULL;
 static char **arg_properties = NULL;
@@ -237,6 +240,7 @@ static int translate_bus_error_to_exit_status(int r, const sd_bus_error *error)
 }
 
 static void warn_wall(enum action a) {
+#ifdef HAVE_UTMP
         static const char *table[_ACTION_MAX] = {
                 [ACTION_HALT]            = "The system is going down for system halt NOW!",
                 [ACTION_REBOOT]          = "The system is going down for reboot NOW!",
@@ -269,6 +273,7 @@ static void warn_wall(enum action a) {
                 return;
 
         utmp_wall(table[a], NULL, NULL);
+#endif
 }
 
 static bool avoid_bus(void) {
@@ -6020,14 +6025,16 @@ static int halt_parse_argv(int argc, char *argv[]) {
                 {}
         };
 
-        int c, r, runlevel;
+        int c, r;
 
         assert(argc >= 0);
         assert(argv);
 
-        if (utmp_get_runlevel(&runlevel, NULL) >= 0)
-                if (runlevel == '0' || runlevel == '6')
+#ifdef HAVE_UTMP
+        if (utmp_get_runlevel(&r, NULL) >= 0)
+                if (r == '0' || r == '6')
                         arg_force = 2;
+#endif
 
         while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0)
                 switch (c) {
@@ -6803,6 +6810,7 @@ static int halt_main(sd_bus *bus) {
         if (!arg_dry && !arg_force)
                 return start_with_fallback(bus);
 
+#ifdef HAVE_UTMP
         if (!arg_no_wtmp) {
                 if (sd_booted() > 0)
                         log_debug("Not writing utmp record, assuming that systemd-update-utmp is used.");
@@ -6812,6 +6820,7 @@ static int halt_main(sd_bus *bus) {
                                 log_warning("Failed to write utmp record: %s", strerror(-r));
                 }
         }
+#endif
 
         if (arg_dry)
                 return 0;
@@ -6823,6 +6832,7 @@ static int halt_main(sd_bus *bus) {
 }
 
 static int runlevel_main(void) {
+#ifdef HAVE_UTMP
         int r, runlevel, previous;
 
         r = utmp_get_runlevel(&runlevel, &previous);
@@ -6835,6 +6845,9 @@ static int runlevel_main(void) {
                previous <= 0 ? 'N' : previous,
                runlevel <= 0 ? 'N' : runlevel);
 
+#else
+        puts("unknown");
+#endif
         return 0;
 }
 
-- 
2.1.0



More information about the systemd-devel mailing list