anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0060-systemctl-fix-name-mangling-for-sysv-units.patch

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