]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
busctl: rename --num-matches= → --limit-messages=
authorLennart Poettering <lennart@poettering.net>
Mon, 28 Oct 2024 12:48:30 +0000 (13:48 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 29 Oct 2024 15:50:06 +0000 (16:50 +0100)
We should avoid unnecessary abbreviations for such messages, and this
puts a maximum limit on things, hence it should indicate this in the
name.

Moreover, matches is a bit confusing, since most people will probably
call "busctl monitor" without any match specification, i.e. zero
matches, but that's not what was meant here at all.

Also, add a brief switch for this (-N) since I figure in particular
"-N1" might be a frequent operation people might want to use.

Follow-up for: 989e843e7543b21b91de4368da44692d674722a5
See: #34048

man/busctl.xml
shell-completion/bash/busctl
shell-completion/zsh/_busctl
src/busctl/busctl.c
test/units/TEST-74-AUX-UTILS.busctl.sh

index 5cf6058dc3e2dcd36102394f1fe370620d0e8a9d..3733d523e5ffc2bf38792303940f2c4642b20c25 100644 (file)
       </varlistentry>
 
       <varlistentry>
-        <term><option>--num-matches=<replaceable>NUMBER</replaceable></option></term>
+        <term><option>--limit-messages=<replaceable>NUMBER</replaceable></option></term>
+        <term><option>-N <replaceable>NUMBER</replaceable></option></term>
 
         <listitem>
           <para>When used with the <command>monitor</command> command, if enabled will make
index 441b2c7d4355f876c0ba83857b676a3056281139..dc2714aaaef3c3df2a3aef3dbd2e533e44643ea5 100644 (file)
@@ -89,7 +89,7 @@ _busctl() {
                       --allow-interactive-authorization=no --augment-creds=no
                       --watch-bind=yes -j -l --full --xml-interface'
         [ARG]='--address -H --host -M --machine --match --timeout --size --json
-                      --destination --num-matches'
+                      --destination -N --limit-messages'
     )
 
     if __contains_word "--user" ${COMP_WORDS[*]}; then
index 5e16d0f1a1450394b4ee2e8c4aa67e9d1ed51f50..296afd1e24d43797d0ab08949f5d25580b5137d0 100644 (file)
@@ -310,5 +310,5 @@ _arguments \
     '--allow-interactive-authorization=[Allow interactive authorization for operation]:boolean:(1 0)' \
     '--timeout=[Maximum time to wait for method call completion and monitoring]:timeout (seconds)' \
     '--augment-creds=[Extend credential data with data read from /proc/$PID]:boolean:(1 0)' \
-    '--num-matches=[Exit after receiving a number of matches while monitoring]:integer' \
+    '(-M --limit-messages)'{-M,--limit-messages}'[Exit after receiving a number of messages while monitoring]:integer' \
     '*::busctl command:_busctl_commands'
index 2abf73010281b35d21e2907b5a69fa28ac2a7b39..1cbe07be112b5a596af7897125c9443342fc82d0 100644 (file)
@@ -65,7 +65,7 @@ static bool arg_augment_creds = true;
 static bool arg_watch_bind = false;
 static usec_t arg_timeout = 0;
 static const char *arg_destination = NULL;
-static uint64_t arg_num_matches = UINT64_MAX;
+static uint64_t arg_limit_messages = UINT64_MAX;
 
 STATIC_DESTRUCTOR_REGISTER(arg_matches, strv_freep);
 
@@ -1367,10 +1367,14 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
                         dump(m, stdout);
                         fflush(stdout);
 
-                        if (arg_num_matches != UINT64_MAX && --arg_num_matches == 0) {
-                                if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
-                                        log_info("Received requested number of matching messages, exiting.");
-                                return 0;
+                        if (arg_limit_messages != UINT64_MAX) {
+                                arg_limit_messages--;
+
+                                if (arg_limit_messages == 0) {
+                                        if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
+                                                log_info("Received requested maximum number of messages, exiting.");
+                                        return 0;
+                                }
                         }
 
                         if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected") > 0) {
@@ -2503,7 +2507,8 @@ static int help(void) {
                "     --watch-bind=BOOL     Wait for bus AF_UNIX socket to be bound in the file\n"
                "                           system\n"
                "     --destination=SERVICE Destination service of a signal\n"
-               "     --num-matches=NUMBER  Exit after receiving a number of matches while\n"
+               "  -N --limit-messages=NUMBER\n"
+               "                           Exit after receiving a number of matches while\n"
                "                           monitoring\n"
                "\nSee the %s for details.\n",
                program_invocation_short_name,
@@ -2544,7 +2549,6 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_WATCH_BIND,
                 ARG_JSON,
                 ARG_DESTINATION,
-                ARG_NUM_MATCHES,
         };
 
         static const struct option options[] = {
@@ -2577,7 +2581,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "watch-bind",                      required_argument, NULL, ARG_WATCH_BIND                      },
                 { "json",                            required_argument, NULL, ARG_JSON                            },
                 { "destination",                     required_argument, NULL, ARG_DESTINATION                     },
-                { "num-matches",                     required_argument, NULL, ARG_NUM_MATCHES                     },
+                { "limit-messages",                  required_argument, NULL, 'N'                                 },
                 {},
         };
 
@@ -2586,7 +2590,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hH:M:C:J:qjl", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "hH:M:C:J:qjlN:", options, NULL)) >= 0)
 
                 switch (c) {
 
@@ -2746,12 +2750,12 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_destination = optarg;
                         break;
 
-                case ARG_NUM_MATCHES:
-                        r = safe_atou64(optarg, &arg_num_matches);
+                case 'N':
+                        r = safe_atou64(optarg, &arg_limit_messages);
                         if (r < 0)
-                                return log_error_errno(r, "Failed to parse --num-matches= parameter '%s': %m", optarg);
-                        if (arg_num_matches == 0)
-                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--num-matches= parameter cannot be 0");
+                                return log_error_errno(r, "Failed to parse --limit-messages= parameter: %s", optarg);
+                        if (arg_limit_messages == 0)
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--limit-messages= parameter cannot be 0");
 
                         break;
 
index 4949f4bac77392e86f9db1f8a670ae4d483a9895..d83f0941f51ae45999e04c86cd6701750974745d 100755 (executable)
@@ -117,4 +117,4 @@ busctl get-property -j \
 (! busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                        KExecWatchdogUSec t "foo")
 
-busctl --quiet --timeout 1 --num-matches 1 --match "interface=org.freedesktop.systemd1.Manager" monitor >/dev/null
+busctl --quiet --timeout 1 --limit-messages 1 --match "interface=org.freedesktop.systemd1.Manager" monitor >/dev/null