anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone
Blob Blame History Raw
From 8588ecf209ae4f8a198614b3786c58e584528f98 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 6 Nov 2013 17:31:20 +0100
Subject: [PATCH] run: support --system to match other commands, even if
 redundant

Conflicts:
	man/systemd-run.xml
	src/run/run.c
---
 man/systemd-run.xml |  9 +++++++++
 src/run/run.c       | 20 +++++++++++++-------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/man/systemd-run.xml b/man/systemd-run.xml
index 252335b..48a0715 100644
--- a/man/systemd-run.xml
+++ b/man/systemd-run.xml
@@ -113,6 +113,15 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
       </varlistentry>
 
       <varlistentry>
+        <term><option>--system</option></term>
+
+        <listitem>
+          <para>Talk to the service manager of the system. This is the
+          implied default.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
         <term><option>--scope</option></term>
 
         <listitem>
diff --git a/src/run/run.c b/src/run/run.c
index 18a4920..a6abead 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -61,6 +61,7 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_USER,
+                ARG_SYSTEM,
                 ARG_SCOPE,
                 ARG_UNIT,
                 ARG_DESCRIPTION,
@@ -72,6 +73,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "help",              no_argument,       NULL, 'h'             },
                 { "version",           no_argument,       NULL, ARG_VERSION     },
                 { "user",              no_argument,       NULL, ARG_USER        },
+                { "system",            no_argument,       NULL, ARG_SYSTEM      },
                 { "scope",             no_argument,       NULL, ARG_SCOPE       },
                 { "unit",              required_argument, NULL, ARG_UNIT        },
                 { "description",       required_argument, NULL, ARG_DESCRIPTION },
@@ -103,6 +105,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_user = true;
                         break;
 
+                case ARG_SYSTEM:
+                        arg_user = false;
+                        break;
+
                 case ARG_SCOPE:
                         arg_scope = true;
                         break;
@@ -333,12 +339,12 @@ int main(int argc, char* argv[]) {
 
         r = parse_argv(argc, argv);
         if (r <= 0)
-                goto fail;
+                goto finish;
 
         r = find_binary(argv[optind], &command);
         if (r < 0) {
                 log_error("Failed to find executable %s: %s", argv[optind], strerror(-r));
-                goto fail;
+                goto finish;
         }
         argv[optind] = command;
 
@@ -346,7 +352,7 @@ int main(int argc, char* argv[]) {
                 description = strv_join(argv + optind, " ");
                 if (!description) {
                         r = log_oom();
-                        goto fail;
+                        goto finish;
                 }
 
                 arg_description = description;
@@ -357,8 +363,8 @@ int main(int argc, char* argv[]) {
         else
                 r = sd_bus_open_system(&bus);
         if (r < 0) {
-                log_error("Failed to create new bus connection: %s", strerror(-r));
-                goto fail;
+                log_error("Failed to create bus connection: %s", strerror(-r));
+                goto finish;
         }
 
         if (arg_scope)
@@ -368,9 +374,9 @@ int main(int argc, char* argv[]) {
         if (r < 0) {
                 log_error("Failed start transient unit: %s", error.message ? error.message : strerror(-r));
                 sd_bus_error_free(&error);
-                goto fail;
+                goto finish;
         }
 
-fail:
+finish:
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }