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