]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: add --verbose mode
authorLennart Poettering <lennart@poettering.net>
Sun, 23 Mar 2025 22:38:06 +0000 (18:38 -0400)
committerLennart Poettering <lennart@poettering.net>
Tue, 13 May 2025 13:39:57 +0000 (15:39 +0200)
man/systemctl.xml
src/systemctl/systemctl-start-unit.c
src/systemctl/systemctl.c
src/systemctl/systemctl.h

index b1fb6cec8c0c71de42066c10d5a291f6a781052b..a966e3ea7a3e77c9439f820fa6d6d68fbb623bc2 100644 (file)
@@ -2348,6 +2348,17 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>-v</option></term>
+        <term><option>--verbose</option></term>
+
+        <listitem>
+          <para>Display unit log output while executing unit operations.</para>
+
+          <xi:include href="version-info.xml" xpointer="v258"/>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>--no-warn</option></term>
 
index 7ea2cf8998699cf1a97fa8fe0d140785ef381447..7e81afae0053c05933caff15d1a5e6f1b2914303 100644 (file)
@@ -10,6 +10,7 @@
 #include "bus-util.h"
 #include "bus-wait-for-jobs.h"
 #include "bus-wait-for-units.h"
+#include "fork-journal.h"
 #include "macro.h"
 #include "special.h"
 #include "string-util.h"
@@ -388,9 +389,13 @@ int verb_start(int argc, char *argv[], void *userdata) {
                         return log_error_errno(r, "Failed to allocate unit watch context: %m");
         }
 
+        _cleanup_(journal_terminate) PidRef journal_pid = PIDREF_NULL;
         if (arg_marked)
                 ret = enqueue_marked_jobs(bus, w);
-        else
+        else {
+                if (arg_verbose)
+                        (void) journal_fork(arg_runtime_scope, (const char**) names, &journal_pid);
+
                 STRV_FOREACH(name, names) {
                         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
 
@@ -404,6 +409,7 @@ int verb_start(int argc, char *argv[], void *userdata) {
                                         return log_oom();
                         }
                 }
+        }
 
         if (!arg_no_block) {
                 const char *extra_args[4];
index fdbde7dc5e771e1caf4b1e481a3ead85e9182d85..3c691c5deeca90e9baea0e046760563451a51d2e 100644 (file)
@@ -90,6 +90,7 @@ bool arg_show_types = false;
 int arg_check_inhibitors = -1;
 bool arg_dry_run = false;
 bool arg_quiet = false;
+bool arg_verbose = false;
 bool arg_no_warn = false;
 bool arg_full = false;
 bool arg_recursive = false;
@@ -304,6 +305,7 @@ static int systemctl_help(void) {
                "                             suspend-then-hibernate, hybrid-sleep, default,\n"
                "                             rescue, emergency, and exit.\n"
                "  -q --quiet             Suppress output\n"
+               "  -v --verbose           Show unit logs while executing operation\n"
                "     --no-warn           Suppress several warnings shown by default\n"
                "     --wait              For (re)start, wait until service stopped again\n"
                "                         For is-system-running, wait until startup is completed\n"
@@ -510,6 +512,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                 { "no-wall",             no_argument,       NULL, ARG_NO_WALL             },
                 { "dry-run",             no_argument,       NULL, ARG_DRY_RUN             },
                 { "quiet",               no_argument,       NULL, 'q'                     },
+                { "verbose",             no_argument,       NULL, 'v'                     },
                 { "no-warn",             no_argument,       NULL, ARG_NO_WARN             },
                 { "root",                required_argument, NULL, ARG_ROOT                },
                 { "image",               required_argument, NULL, ARG_IMAGE               },
@@ -556,7 +559,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
         /* We default to allowing interactive authorization only in systemctl (not in the legacy commands) */
         arg_ask_password = true;
 
-        while ((c = getopt_long(argc, argv, "hC:t:p:P:alqfs:H:M:n:o:iTr.::", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "hC:t:p:P:alqvfs:H:M:n:o:iTr.::", options, NULL)) >= 0)
 
                 switch (c) {
 
@@ -770,6 +773,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
 
                         break;
 
+                case 'v':
+                        arg_verbose = true;
+                        break;
+
                 case 'f':
                         arg_force++;
                         break;
index 00405f4705770d7fabb76ba86fa257e4efacbf39..e28238032393cc9dbdece1eeb87cf13a004bd6d9 100644 (file)
@@ -68,6 +68,7 @@ extern bool arg_show_types;
 extern int arg_check_inhibitors;
 extern bool arg_dry_run;
 extern bool arg_quiet;
+extern bool arg_verbose;
 extern bool arg_no_warn;
 extern bool arg_full;
 extern bool arg_recursive;