diff options
author | Václav Pavlín <vpavlin@redhat.com> | 2013-10-02 16:42:42 +0200 |
---|---|---|
committer | Michal Sekletar <msekleta@redhat.com> | 2013-10-02 16:42:53 +0200 |
commit | cbb13b2a538ece1c7ec3b210e2b36b47df2a13ea (patch) | |
tree | c39934f902ec8c2d31051a21f5f307b2c736901b /src/systemctl/systemctl.c | |
parent | 2c64a8d0caf84254e38f2e76528f2034d37da520 (diff) |
systemctl: fix name mangling for sysv units
Diffstat (limited to 'src/systemctl/systemctl.c')
-rw-r--r-- | src/systemctl/systemctl.c | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index bb7ada9f32..d75281f5f6 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4218,11 +4218,10 @@ static int set_environment(DBusConnection *bus, char **args) { return 0; } -static int enable_sysv_units(char **args) { +static int enable_sysv_units(const char *verb, char **args) { int r = 0; #if defined(HAVE_SYSV_COMPAT) && defined(HAVE_CHKCONFIG) - const char *verb = args[0]; unsigned f = 1, t = 1; LookupPaths paths = {}; @@ -4242,7 +4241,7 @@ static int enable_sysv_units(char **args) { return r; r = 0; - for (f = 1; args[f]; f++) { + for (f = 0; args[f]; f++) { const char *name; _cleanup_free_ char *p = NULL, *q = NULL; bool found_native = false, found_sysv; @@ -4365,7 +4364,7 @@ finish: lookup_paths_free(&paths); /* Drop all SysV units */ - for (f = 1, t = 1; args[f]; f++) { + for (f = 0, t = 0; args[f]; f++) { if (isempty(args[f])) continue; @@ -4423,16 +4422,16 @@ static int enable_unit(DBusConnection *bus, char **args) { dbus_error_init(&error); - r = enable_sysv_units(args); - if (r < 0) - return r; - if (!args[1]) return 0; r = mangle_names(args+1, &mangled_names); if (r < 0) - goto finish; + return r; + + r = enable_sysv_units(verb, mangled_names); + if (r < 0) + return r; if (!bus || avoid_bus()) { if (streq(verb, "enable")) { @@ -4624,11 +4623,15 @@ static int unit_is_enabled(DBusConnection *bus, char **args) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; bool enabled; char **name; - char *n; + _cleanup_strv_free_ char **mangled_names = NULL; dbus_error_init(&error); - r = enable_sysv_units(args); + r = mangle_names(args+1, &mangled_names); + if (r < 0) + return r; + + r = enable_sysv_units(args[0], mangled_names); if (r < 0) return r; @@ -4636,16 +4639,10 @@ static int unit_is_enabled(DBusConnection *bus, char **args) { if (!bus || avoid_bus()) { - STRV_FOREACH(name, args+1) { + STRV_FOREACH(name, mangled_names) { UnitFileState state; - n = unit_name_mangle(*name); - if (!n) - return log_oom(); - - state = unit_file_get_state(arg_scope, arg_root, n); - - free(n); + state = unit_file_get_state(arg_scope, arg_root, *name); if (state < 0) return state; @@ -4660,13 +4657,9 @@ static int unit_is_enabled(DBusConnection *bus, char **args) { } } else { - STRV_FOREACH(name, args+1) { + STRV_FOREACH(name, mangled_names) { const char *s; - n = unit_name_mangle(*name); - if (!n) - return log_oom(); - r = bus_method_call_with_reply ( bus, "org.freedesktop.systemd1", @@ -4675,11 +4668,9 @@ static int unit_is_enabled(DBusConnection *bus, char **args) { "GetUnitFileState", &reply, NULL, - DBUS_TYPE_STRING, &n, + DBUS_TYPE_STRING, name, DBUS_TYPE_INVALID); - free(n); - if (r) return r; |