diff options
Diffstat (limited to 'src/systemctl/systemctl.c')
-rw-r--r-- | src/systemctl/systemctl.c | 135 |
1 files changed, 14 insertions, 121 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 70871cf3e6..51b82d57db 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1335,7 +1335,7 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { UNIT_FILE_MASKED, UNIT_FILE_MASKED_RUNTIME, UNIT_FILE_DISABLED, - UNIT_FILE_INVALID)) { + UNIT_FILE_BAD)) { on = ansi_highlight_red(); off = ansi_normal(); } else if (u->state == UNIT_FILE_ENABLED) { @@ -1503,16 +1503,12 @@ static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, cha static const char *dependencies[_DEPENDENCY_MAX] = { [DEPENDENCY_FORWARD] = "Requires\0" - "RequiresOverridable\0" "Requisite\0" - "RequisiteOverridable\0" "Wants\0" "ConsistsOf\0" "BindsTo\0", [DEPENDENCY_REVERSE] = "RequiredBy\0" - "RequiredByOverridable\0" "RequisiteOf\0" - "RequisiteOfOverridable\0" "WantedBy\0" "PartOf\0" "BoundBy\0", @@ -2186,7 +2182,7 @@ static int list_jobs(int argc, char *argv[], void *userdata) { return bus_log_parse_error(r); output_jobs_list(jobs, c, skipped); - return r; + return 0; } static int cancel_job(int argc, char *argv[], void *userdata) { @@ -4905,102 +4901,6 @@ static int set_property(int argc, char *argv[], void *userdata) { return 0; } -static int snapshot(int argc, char *argv[], void *userdata) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - _cleanup_free_ char *n = NULL, *id = NULL; - const char *path; - sd_bus *bus; - int r; - - polkit_agent_open_if_enabled(); - - if (argc > 1) { - r = unit_name_mangle_with_suffix(argv[1], UNIT_NAME_NOGLOB, ".snapshot", &n); - if (r < 0) - return log_error_errno(r, "Failed to generate unit name: %m"); - } else { - n = strdup(""); - if (!n) - return log_oom(); - } - - r = acquire_bus(BUS_MANAGER, &bus); - if (r < 0) - return r; - - r = sd_bus_call_method( - bus, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "CreateSnapshot", - &error, - &reply, - "sb", n, false); - if (r < 0) - return log_error_errno(r, "Failed to create snapshot: %s", bus_error_message(&error, r)); - - r = sd_bus_message_read(reply, "o", &path); - if (r < 0) - return bus_log_parse_error(r); - - r = sd_bus_get_property_string( - bus, - "org.freedesktop.systemd1", - path, - "org.freedesktop.systemd1.Unit", - "Id", - &error, - &id); - if (r < 0) - return log_error_errno(r, "Failed to get ID of snapshot: %s", bus_error_message(&error, r)); - - if (!arg_quiet) - puts(id); - - return 0; -} - -static int delete_snapshot(int argc, char *argv[], void *userdata) { - _cleanup_strv_free_ char **names = NULL; - sd_bus *bus; - char **name; - int r; - - polkit_agent_open_if_enabled(); - - r = acquire_bus(BUS_MANAGER, &bus); - if (r < 0) - return r; - - r = expand_names(bus, strv_skip(argv, 1), ".snapshot", &names); - if (r < 0) - return log_error_errno(r, "Failed to expand names: %m"); - - STRV_FOREACH(name, names) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - int q; - - q = sd_bus_call_method( - bus, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "RemoveSnapshot", - &error, - NULL, - "s", *name); - if (q < 0) { - log_error_errno(q, "Failed to remove snapshot %s: %s", *name, bus_error_message(&error, q)); - if (r == 0) - r = q; - } - } - - return r; -} - static int daemon_reload(int argc, char *argv[], void *userdata) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; const char *method; @@ -5533,10 +5433,10 @@ static int enable_unit(int argc, char *argv[], void *userdata) { else assert_not_reached("Unknown verb"); - if (r < 0) { - log_error_errno(r, "Operation failed: %m"); - goto finish; - } + if (r == -ESHUTDOWN) + return log_error_errno(r, "Unit file is masked."); + if (r < 0) + return log_error_errno(r, "Operation failed: %m"); if (!arg_quiet) dump_unit_file_changes(changes, n_changes); @@ -5653,7 +5553,7 @@ static int enable_unit(int argc, char *argv[], void *userdata) { r = acquire_bus(BUS_MANAGER, &bus); if (r < 0) - return r; + goto finish; new_args[0] = (char*) (streq(argv[0], "enable") ? "start" : "stop"); for (i = 0; i < n_changes; i++) @@ -5699,7 +5599,8 @@ static int add_dependency(int argc, char *argv[], void *userdata) { unsigned n_changes = 0; r = unit_file_add_dependency(arg_scope, arg_runtime, arg_root, names, target, dep, arg_force, &changes, &n_changes); - + if (r == -ESHUTDOWN) + return log_error_errno(r, "Unit file is masked."); if (r < 0) return log_error_errno(r, "Can't add dependency: %m"); @@ -5836,8 +5737,8 @@ static int unit_is_enabled(int argc, char *argv[], void *userdata) { STRV_FOREACH(name, names) { UnitFileState state; - state = unit_file_get_state(arg_scope, arg_root, *name); - if (state < 0) + r = unit_file_get_state(arg_scope, arg_root, *name, &state); + if (r < 0) return log_error_errno(state, "Failed to get unit file state for %s: %m", *name); if (IN_SET(state, @@ -6381,9 +6282,6 @@ static void systemctl_help(void) { "Job Commands:\n" " list-jobs [PATTERN...] List jobs\n" " cancel [JOB...] Cancel all, one, or more jobs\n\n" - "Snapshot Commands:\n" - " snapshot [NAME] Create a snapshot\n" - " delete NAME... Remove one or more snapshots\n\n" "Environment Commands:\n" " show-environment Dump environment\n" " set-environment NAME=VALUE... Set one or more environment variables\n" @@ -6526,11 +6424,6 @@ static void help_states(void) { puts(slice_state_to_string(i)); if (!arg_no_legend) - puts("\nAvailable snapshot unit substates:"); - for (i = 0; i < _SNAPSHOT_STATE_MAX; i++) - puts(snapshot_state_to_string(i)); - - if (!arg_no_legend) puts("\nAvailable socket unit substates:"); for (i = 0; i < _SOCKET_STATE_MAX; i++) puts(socket_state_to_string(i)); @@ -7439,7 +7332,7 @@ static int systemctl_main(int argc, char *argv[]) { { "list-jobs", VERB_ANY, VERB_ANY, 0, list_jobs }, { "list-machines", VERB_ANY, VERB_ANY, 0, list_machines }, { "clear-jobs", VERB_ANY, 1, 0, daemon_reload }, - { "cancel", 2, VERB_ANY, 0, cancel_job }, + { "cancel", VERB_ANY, VERB_ANY, 0, cancel_job }, { "start", 2, VERB_ANY, 0, start_unit }, { "stop", 2, VERB_ANY, 0, start_unit }, { "condstop", 2, VERB_ANY, 0, start_unit }, /* For compatibility with ALTLinux */ @@ -7460,8 +7353,6 @@ static int systemctl_main(int argc, char *argv[]) { { "cat", 2, VERB_ANY, 0, cat }, { "status", VERB_ANY, VERB_ANY, 0, show }, { "help", VERB_ANY, VERB_ANY, 0, show }, - { "snapshot", VERB_ANY, 2, 0, snapshot }, - { "delete", 2, VERB_ANY, 0, delete_snapshot }, { "daemon-reload", VERB_ANY, 1, 0, daemon_reload }, { "daemon-reexec", VERB_ANY, 1, 0, daemon_reload }, { "show-environment", VERB_ANY, 1, 0, show_environment }, @@ -7815,5 +7706,7 @@ finish: release_busses(); + /* Note that we return r here, not EXIT_SUCCESS, so that we can implement the LSB-like return codes */ + return r < 0 ? EXIT_FAILURE : r; } |