ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
9fc0f6
From f4cad2f52718b386ab8c233d6d702e808acfb844 Mon Sep 17 00:00:00 2001
9fc0f6
From: =?UTF-8?q?V=C3=A1clav=20Pavl=C3=ADn?= <vpavlin@redhat.com>
9fc0f6
Date: Wed, 2 Oct 2013 16:42:42 +0200
9fc0f6
Subject: [PATCH] systemctl: fix name mangling for sysv units
9fc0f6
9fc0f6
---
9fc0f6
 src/systemctl/systemctl.c | 45 ++++++++++++++++++---------------------------
9fc0f6
 1 file changed, 18 insertions(+), 27 deletions(-)
9fc0f6
9fc0f6
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
9fc0f6
index 0d1a487..036828b 100644
9fc0f6
--- a/src/systemctl/systemctl.c
9fc0f6
+++ b/src/systemctl/systemctl.c
9fc0f6
@@ -4218,11 +4218,10 @@ static int set_environment(DBusConnection *bus, char **args) {
9fc0f6
         return 0;
9fc0f6
 }
9fc0f6
 
9fc0f6
-static int enable_sysv_units(char **args) {
9fc0f6
+static int enable_sysv_units(const char *verb, char **args) {
9fc0f6
         int r = 0;
9fc0f6
 
9fc0f6
 #if defined(HAVE_SYSV_COMPAT) && defined(HAVE_CHKCONFIG)
9fc0f6
-        const char *verb = args[0];
9fc0f6
         unsigned f = 1, t = 1;
9fc0f6
         LookupPaths paths = {};
9fc0f6
 
9fc0f6
@@ -4242,7 +4241,7 @@ static int enable_sysv_units(char **args) {
9fc0f6
                 return r;
9fc0f6
 
9fc0f6
         r = 0;
9fc0f6
-        for (f = 1; args[f]; f++) {
9fc0f6
+        for (f = 0; args[f]; f++) {
9fc0f6
                 const char *name;
9fc0f6
                 _cleanup_free_ char *p = NULL, *q = NULL;
9fc0f6
                 bool found_native = false, found_sysv;
9fc0f6
@@ -4365,7 +4364,7 @@ finish:
9fc0f6
         lookup_paths_free(&paths);
9fc0f6
 
9fc0f6
         /* Drop all SysV units */
9fc0f6
-        for (f = 1, t = 1; args[f]; f++) {
9fc0f6
+        for (f = 0, t = 0; args[f]; f++) {
9fc0f6
 
9fc0f6
                 if (isempty(args[f]))
9fc0f6
                         continue;
9fc0f6
@@ -4423,16 +4422,16 @@ static int enable_unit(DBusConnection *bus, char **args) {
9fc0f6
 
9fc0f6
         dbus_error_init(&error);
9fc0f6
 
9fc0f6
-        r = enable_sysv_units(args);
9fc0f6
-        if (r < 0)
9fc0f6
-                return r;
9fc0f6
-
9fc0f6
         if (!args[1])
9fc0f6
                 return 0;
9fc0f6
 
9fc0f6
         r = mangle_names(args+1, &mangled_names);
9fc0f6
         if (r < 0)
9fc0f6
-                goto finish;
9fc0f6
+                return r;
9fc0f6
+
9fc0f6
+        r = enable_sysv_units(verb, mangled_names);
9fc0f6
+        if (r < 0)
9fc0f6
+                return r;
9fc0f6
 
9fc0f6
         if (!bus || avoid_bus()) {
9fc0f6
                 if (streq(verb, "enable")) {
9fc0f6
@@ -4624,11 +4623,15 @@ static int unit_is_enabled(DBusConnection *bus, char **args) {
9fc0f6
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
9fc0f6
         bool enabled;
9fc0f6
         char **name;
9fc0f6
-        char *n;
9fc0f6
+        _cleanup_strv_free_ char **mangled_names = NULL;
9fc0f6
 
9fc0f6
         dbus_error_init(&error);
9fc0f6
 
9fc0f6
-        r = enable_sysv_units(args);
9fc0f6
+        r = mangle_names(args+1, &mangled_names);
9fc0f6
+        if (r < 0)
9fc0f6
+                return r;
9fc0f6
+
9fc0f6
+        r = enable_sysv_units(args[0], mangled_names);
9fc0f6
         if (r < 0)
9fc0f6
                 return r;
9fc0f6
 
9fc0f6
@@ -4636,16 +4639,10 @@ static int unit_is_enabled(DBusConnection *bus, char **args) {
9fc0f6
 
9fc0f6
         if (!bus || avoid_bus()) {
9fc0f6
 
9fc0f6
-                STRV_FOREACH(name, args+1) {
9fc0f6
+                STRV_FOREACH(name, mangled_names) {
9fc0f6
                         UnitFileState state;
9fc0f6
 
9fc0f6
-                        n = unit_name_mangle(*name);
9fc0f6
-                        if (!n)
9fc0f6
-                                return log_oom();
9fc0f6
-
9fc0f6
-                        state = unit_file_get_state(arg_scope, arg_root, n);
9fc0f6
-
9fc0f6
-                        free(n);
9fc0f6
+                        state = unit_file_get_state(arg_scope, arg_root, *name);
9fc0f6
 
9fc0f6
                         if (state < 0)
9fc0f6
                                 return state;
9fc0f6
@@ -4660,13 +4657,9 @@ static int unit_is_enabled(DBusConnection *bus, char **args) {
9fc0f6
                 }
9fc0f6
 
9fc0f6
         } else {
9fc0f6
-                STRV_FOREACH(name, args+1) {
9fc0f6
+                STRV_FOREACH(name, mangled_names) {
9fc0f6
                         const char *s;
9fc0f6
 
9fc0f6
-                        n = unit_name_mangle(*name);
9fc0f6
-                        if (!n)
9fc0f6
-                                return log_oom();
9fc0f6
-
9fc0f6
                         r = bus_method_call_with_reply (
9fc0f6
                                         bus,
9fc0f6
                                         "org.freedesktop.systemd1",
9fc0f6
@@ -4675,11 +4668,9 @@ static int unit_is_enabled(DBusConnection *bus, char **args) {
9fc0f6
                                         "GetUnitFileState",
9fc0f6
                                         &reply,
9fc0f6
                                         NULL,
9fc0f6
-                                        DBUS_TYPE_STRING, &n,
9fc0f6
+                                        DBUS_TYPE_STRING, name,
9fc0f6
                                         DBUS_TYPE_INVALID);
9fc0f6
 
9fc0f6
-                        free(n);
9fc0f6
-
9fc0f6
                         if (r)
9fc0f6
                                 return r;
9fc0f6