chiark / gitweb /
systemd-run: add --quiet mode to suppress informational message on TTY usage
authorLennart Poettering <lennart@poettering.net>
Mon, 22 Dec 2014 19:39:10 +0000 (20:39 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Dec 2014 02:26:24 +0000 (03:26 +0100)
man/systemd-run.xml
src/run/run.c

index 5fb4ee28eb3191388c64fe83c6eab6010a25368a..f57c13b50008c2051826e03c2335b7b922f652ea 100644 (file)
@@ -232,10 +232,20 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
         <listitem><para>When invoking a command as service connects
         its standard input and output to the invoking tty via a
         pseudo TTY device. This allows invoking binaries as services
-        that expect interactive user input, such as an interactive
+        that expect interactive user input, such as interactive
         command shells.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--quiet</option></term>
+        <term><option>-q</option></term>
+
+        <listitem><para>Suppresses additional informational output
+        while running. This is particularly useful in combination with
+        <option>--pty</option> when it will suppress the initial
+        message explaining how to terminate the TTY connection.</para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>--on-active=</option></term>
         <term><option>--on-boot=</option></term>
index 828aa5cf935b4b4dede8467269586d0d1aabe685..242bed0a43ae317b66167fc9df5e88a6a1b34f90 100644 (file)
@@ -59,6 +59,7 @@ static usec_t arg_on_unit_active = 0;
 static usec_t arg_on_unit_inactive = 0;
 static char *arg_on_calendar = NULL;
 static char **arg_timer_property = NULL;
+static bool arg_quiet = false;
 
 static void help(void) {
         printf("%s [OPTIONS...] {COMMAND} [ARGS...]\n\n"
@@ -82,7 +83,8 @@ static void help(void) {
                "     --gid=GROUP                  Run as system group\n"
                "     --nice=NICE                  Nice level\n"
                "     --setenv=NAME=VALUE          Set environment\n"
-               "  -t --pty                        Run service on pseudo tty\n\n"
+               "  -t --pty                        Run service on pseudo tty\n"
+               "  -q --quiet                      Suppress information messages during runtime\n\n"
                "Timer options:\n\n"
                "     --on-active=SEC              Run after seconds\n"
                "     --on-boot=SEC                Run after seconds from machine was booted up\n"
@@ -144,6 +146,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "setenv",            required_argument, NULL, ARG_SETENV           },
                 { "property",          required_argument, NULL, 'p'                  },
                 { "tty",               no_argument,       NULL, 't'                  },
+                { "quiet",             no_argument,       NULL, 'q'                  },
                 { "on-active",         required_argument, NULL, ARG_ON_ACTIVE        },
                 { "on-boot",           required_argument, NULL, ARG_ON_BOOT          },
                 { "on-startup",        required_argument, NULL, ARG_ON_STARTUP       },
@@ -160,7 +163,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "+hrH:M:p:t", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "+hrH:M:p:tq", options, NULL)) >= 0)
 
                 switch (c) {
 
@@ -255,6 +258,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_pty = true;
                         break;
 
+                case 'q':
+                        arg_quiet = true;
+                        break;
+
                 case ARG_ON_ACTIVE:
 
                         r = parse_sec(optarg, &arg_on_active);
@@ -736,7 +743,8 @@ static int start_transient_service(
                 sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
                 sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
 
-                log_info("Running as unit %s.\nPress ^] three times within 1s to disconnect TTY.", service);
+                if (!arg_quiet)
+                        log_info("Running as unit %s.\nPress ^] three times within 1s to disconnect TTY.", service);
 
                 r = pty_forward_new(event, master, false, &forward);
                 if (r < 0)
@@ -750,10 +758,10 @@ static int start_transient_service(
 
                 forward = pty_forward_free(forward);
 
-                if (last_char != '\n')
+                if (!arg_quiet && last_char != '\n')
                         fputc('\n', stdout);
 
-        } else
+        } else if (!arg_quiet)
                 log_info("Running as unit %s.", service);
 
         return 0;
@@ -871,7 +879,8 @@ static int start_transient_scope(
         if (!env)
                 return log_oom();
 
-        log_info("Running as unit %s.", scope);
+        if (!arg_quiet)
+                log_info("Running as unit %s.", scope);
 
         execvpe(argv[0], argv, env);