chiark / gitweb /
busctl: add "tree" command to explore object trees
[elogind.git] / src / login / inhibit.c
index 02b6b257511197b3506983d58a27229b649bd427..8c9d1165d2577a52b9e23e171bad8efd2c8ec72f 100644 (file)
@@ -36,7 +36,7 @@
 static const char* arg_what = "idle:sleep:shutdown";
 static const char* arg_who = NULL;
 static const char* arg_why = "Unknown reason";
-static const char* arg_mode = "block";
+static const char* arg_mode = NULL;
 
 static enum {
         ACTION_INHIBIT,
@@ -97,6 +97,9 @@ static int print_inhibitors(sd_bus *bus, sd_bus_error *error) {
         while ((r = sd_bus_message_read(reply, "(ssssuu)", &what, &who, &why, &mode, &uid, &pid)) > 0) {
                 _cleanup_free_ char *comm = NULL, *u = NULL;
 
+                if (arg_mode && !streq(mode, arg_mode))
+                        continue;
+
                 get_process_comm(pid, &comm);
                 u = uid_to_name(uid);
 
@@ -205,7 +208,7 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached("Unhandled option");
                 }
 
-        if (arg_action == ACTION_INHIBIT && argc == 1)
+        if (arg_action == ACTION_INHIBIT && optind == argc)
                 arg_action = ACTION_LIST;
 
         else if (arg_action == ACTION_INHIBIT && optind >= argc) {
@@ -218,7 +221,7 @@ static int parse_argv(int argc, char *argv[]) {
 
 int main(int argc, char *argv[]) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-        _cleanup_bus_unref_ sd_bus *bus = NULL;
+        _cleanup_bus_close_unref_ sd_bus *bus = NULL;
         int r;
 
         log_parse_environment();
@@ -252,6 +255,9 @@ int main(int argc, char *argv[]) {
                 if (!arg_who)
                         arg_who = w = strv_join(argv + optind, " ");
 
+                if (!arg_mode)
+                        arg_mode = "block";
+
                 fd = inhibit(bus, &error);
                 if (fd < 0) {
                         log_error("Failed to inhibit: %s", bus_error_message(&error, -r));