]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/login/inhibit.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / login / inhibit.c
index 508c539044a8225414f575106f986093d44a7774..f574d429f49f8d0e1d87d331859dddc5d5391816 100644 (file)
 #include "format-util.h"
 #include "main-func.h"
 #include "pager.h"
+#include "pretty-print.h"
 #include "process-util.h"
 #include "signal-util.h"
 #include "strv.h"
-#include "terminal-util.h"
 #include "user-util.h"
 #include "util.h"
 
@@ -83,7 +83,7 @@ static int print_inhibitors(sd_bus *bus) {
         if (r < 0)
                 return log_error_errno(r, "Could not get active inhibitors: %s", bus_error_message(&error, r));
 
-        table = table_new("WHO", "UID", "USER", "PID", "COMM", "WHAT", "WHY", "MODE");
+        table = table_new("who", "uid", "user", "pid", "comm", "what", "why", "mode");
         if (!table)
                 return log_oom();
 
@@ -259,10 +259,9 @@ static int parse_argv(int argc, char *argv[]) {
         if (arg_action == ACTION_INHIBIT && optind == argc)
                 arg_action = ACTION_LIST;
 
-        else if (arg_action == ACTION_INHIBIT && optind >= argc) {
-                log_error("Missing command line to execute.");
-                return -EINVAL;
-        }
+        else if (arg_action == ACTION_INHIBIT && optind >= argc)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Missing command line to execute.");
 
         return 1;
 }
@@ -282,12 +281,10 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 return log_error_errno(r, "Failed to connect to bus: %m");
 
-        if (arg_action == ACTION_LIST) {
-                r = print_inhibitors(bus);
-                pager_close();
-                return r;
+        if (arg_action == ACTION_LIST)
+                return print_inhibitors(bus);
 
-        else {
+        else {
                 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
                 _cleanup_close_ int fd = -1;
                 _cleanup_free_ char *w = NULL;
@@ -304,9 +301,9 @@ static int run(int argc, char *argv[]) {
 
                 fd = inhibit(bus, &error);
                 if (fd < 0)
-                        return log_error("Failed to inhibit: %s", bus_error_message(&error, fd));
+                        return log_error_errno(fd, "Failed to inhibit: %s", bus_error_message(&error, fd));
 
-                r = safe_fork("(inhibit)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_LOG, &pid);
+                r = safe_fork("(inhibit)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pid);
                 if (r < 0)
                         return r;
                 if (r == 0) {