static int arg_force = 0;
static bool arg_ask_password = true;
static bool arg_runtime = false;
+static UnitFilePresetMode arg_preset_mode = UNIT_FILE_PRESET_FULL;
static char **arg_wall = NULL;
static const char *arg_kill_who = NULL;
static int arg_signal = SIGTERM;
static bool output_show_unit(const UnitInfo *u, char **patterns) {
const char *dot;
- if (!strv_isempty(arg_states))
- return
- strv_contains(arg_states, u->load_state) ||
- strv_contains(arg_states, u->sub_state) ||
- strv_contains(arg_states, u->active_state);
-
if (!strv_isempty(patterns)) {
char **pattern;
}
if (circle_len > 0)
- printf("%s%s%s", on_circle, circle ? draw_special_char(DRAW_BLACK_CIRCLE) : " ", off_circle);
+ printf("%s%s%s ", on_circle, circle ? draw_special_char(DRAW_BLACK_CIRCLE) : " ", off_circle);
printf("%s%-*s%s %s%-*s%s %s%-*s %-*s%s %-*s",
on_active, id_len, id, off_active,
int c,
sd_bus_message **_reply) {
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
size_t size = c;
assert(unit_infos);
assert(_reply);
- r = sd_bus_call_method(
+ r = sd_bus_message_new_method_call(
bus,
+ &m,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
- "ListUnits",
- &error,
- &reply,
- NULL);
+ "ListUnitsFiltered");
+
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_message_append_strv(m, arg_states);
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_call(bus, m, 0, &error, &reply);
if (r < 0) {
log_error("Failed to list units: %s", bus_error_message(&error, r));
return r;
assert(_unit_infos);
assert(_machines);
- replies = set_new(NULL, NULL);
+ replies = set_new(NULL);
if (!replies)
return log_oom();
return r;
STRV_FOREACH(i, machines) {
- _cleanup_bus_unref_ sd_bus *container = NULL;
+ _cleanup_bus_close_unref_ sd_bus *container = NULL;
int k;
r = sd_bus_open_system_container(&container, *i);
assert(nw);
assert(next);
- if (next->monotonic != (usec_t) -1 && next->monotonic > 0) {
+ if (next->monotonic != USEC_INFINITY && next->monotonic > 0) {
usec_t converted;
if (next->monotonic > nw->monotonic)
else
converted = nw->realtime - (nw->monotonic - next->monotonic);
- if (next->realtime != (usec_t) -1 && next->realtime > 0)
+ if (next->realtime != USEC_INFINITY && next->realtime > 0)
next_elapse = MIN(converted, next->realtime);
else
next_elapse = converted;
Iterator i;
unsigned n_units;
- h = hashmap_new(string_hash_func, string_compare_func);
+ h = hashmap_new(&string_hash_ops);
if (!h)
return log_oom();
}
n_units = hashmap_size(h);
+
units = new(UnitFileList, n_units);
- if (!units) {
+ if (!units && n_units > 0) {
unit_file_list_free(h);
return log_oom();
}
return bus_log_parse_error(r);
}
- if (c > 0) {
- qsort(units, c, sizeof(UnitFileList), compare_unit_file_list);
- output_unit_file_list(units, c);
- }
+ qsort_safe(units, c, sizeof(UnitFileList), compare_unit_file_list);
+ output_unit_file_list(units, c);
- if (avoid_bus())
+ if (avoid_bus()) {
for (unit = units; unit < units + c; unit++)
free(unit->path);
+ }
return 0;
}
printf("%s...\n",max_len % 2 ? "" : " ");
return 0;
}
- printf("%s", draw_special_char(branches & (1 << i) ? DRAW_TREE_VERT : DRAW_TREE_SPACE));
+ printf("%s", draw_special_char(branches & (1 << i) ? DRAW_TREE_VERTICAL : DRAW_TREE_SPACE));
}
len += 2;
state = check_one_unit(bus, *c, "activating\0active\0reloading\0", true);
if (state > 0)
- printf("%s%s%s", ansi_highlight_green(), draw_special_char(DRAW_BLACK_CIRCLE), ansi_highlight_off());
+ printf("%s%s%s ", ansi_highlight_green(), draw_special_char(DRAW_BLACK_CIRCLE), ansi_highlight_off());
else
- printf("%s%s%s", ansi_highlight_red(), draw_special_char(DRAW_BLACK_CIRCLE), ansi_highlight_off());
+ printf("%s%s%s ", ansi_highlight_red(), draw_special_char(DRAW_BLACK_CIRCLE), ansi_highlight_off());
r = list_dependencies_print(*c, level, branches, c[1] == NULL);
if (r < 0)
}
static int get_machine_properties(sd_bus *bus, struct machine_info *mi) {
- _cleanup_bus_unref_ sd_bus *container = NULL;
+ _cleanup_bus_close_unref_ sd_bus *container = NULL;
int r;
assert(mi);
on_failed = off_failed = "";
if (circle_len > 0)
- printf("%s%s%s", on_state, circle ? draw_special_char(DRAW_BLACK_CIRCLE) : " ", off_state);
+ printf("%s%s%s ", on_state, circle ? draw_special_char(DRAW_BLACK_CIRCLE) : " ", off_state);
if (m->is_host)
printf("%-*s (host) %s%-*s%s %s%*u%s %*u\n",
for (i = 0; i < n_changes; i++) {
if (changes[i].type == UNIT_FILE_SYMLINK)
- log_info("ln -s '%s' '%s'", changes[i].source, changes[i].path);
+ log_info("Created symlink from %s to %s.", changes[i].path, changes[i].source);
else
- log_info("rm '%s'", changes[i].path);
+ log_info("Removed symlink %s.", changes[i].path);
}
}
while ((r = sd_bus_message_read(m, "(sss)", &type, &path, &source)) > 0) {
if (!arg_quiet) {
if (streq(type, "symlink"))
- log_info("ln -s '%s' '%s'", source, path);
+ log_info("Created symlink from %s to %s.", path, source);
else
- log_info("rm '%s'", path);
+ log_info("Removed symlink %s.", path);
}
}
if (r < 0)
r = sd_bus_add_match(
bus,
+ NULL,
"type='signal',"
"sender='org.freedesktop.systemd1',"
"interface='org.freedesktop.systemd1.Manager',"
else if (streq(d->result, "canceled"))
log_error("Job for %s canceled.", strna(d->name));
else if (streq(d->result, "dependency"))
- log_error("A dependency job for %s failed. See 'journalctl -xn' for details.", strna(d->name));
- else if (!streq(d->result, "done") && !streq(d->result, "skipped"))
- log_error("Job for %s failed. See 'systemctl status %s' and 'journalctl -xn' for details.", strna(d->name), strna(d->name));
+ log_error("A dependency job for %s failed. See 'journalctl -xe' for details.", strna(d->name));
+ else if (!streq(d->result, "done") && !streq(d->result, "skipped")) {
+ if (d->name) {
+ bool quotes;
+
+ quotes = chars_intersect(d->name, SHELL_NEED_QUOTES);
+
+ log_error("Job for %s failed. See \"systemctl status %s%s%s\" and \"journalctl -xe\" for details.",
+ d->name,
+ quotes ? "'" : "", d->name, quotes ? "'" : "");
+ } else
+ log_error("Job failed. See \"journalctl -xe\" for details.");
+ }
}
if (streq(d->result, "timeout"))
}
static int wait_for_jobs(sd_bus *bus, Set *s) {
+ _cleanup_bus_slot_unref_ sd_bus_slot *slot = NULL;
WaitData d = { .set = s };
int r = 0, q;
assert(bus);
assert(s);
- q = sd_bus_add_filter(bus, wait_filter, &d);
+ q = sd_bus_add_filter(bus, &slot, wait_filter, &d);
if (q < 0)
return log_oom();
while (!set_isempty(s)) {
q = bus_process_wait(bus);
if (q < 0) {
- log_error("Failed to wait for response: %s", strerror(-r));
+ log_error("Failed to wait for response: %s", strerror(-q));
return q;
}
d.result = NULL;
}
- q = sd_bus_remove_filter(bus, wait_filter, &d);
- if (q < 0 && r == 0)
- r = q;
-
return r;
}
return r;
}
- s = set_new(string_hash_func, string_compare_func);
+ s = set_new(&string_hash_ops);
if (!s)
return log_oom();
}
get_process_comm(pid, &comm);
user = uid_to_name(uid);
- log_warning("Operation inhibited by \"%s\" (PID %lu \"%s\", user %s), reason is \"%s\".",
- who, (unsigned long) pid, strna(comm), strna(user), why);
+ log_warning("Operation inhibited by \"%s\" (PID "PID_FMT" \"%s\", user %s), reason is \"%s\".",
+ who, pid, strna(comm), strna(user), why);
c++;
}
const char *status_text;
const char *pid_file;
bool running:1;
+ int status_errno;
usec_t start_timestamp;
usec_t exit_timestamp;
} else
active_on = active_off = "";
- printf("%s%s%s%s", active_on, draw_special_char(DRAW_BLACK_CIRCLE), active_off, strna(i->id));
+ printf("%s%s%s %s", active_on, draw_special_char(DRAW_BLACK_CIRCLE), active_off, strna(i->id));
if (i->description && !streq_ptr(i->id, i->description))
printf(" - %s", i->description);
if (i->status_text)
printf(" Status: \"%s\"\n", i->status_text);
+ if (i->status_errno > 0)
+ printf(" Error: %i (%s)\n", i->status_errno, strerror(i->status_errno));
if (i->control_group &&
(i->main_pid > 0 || i->control_pid > 0 ||
return;
}
- STRV_FOREACH(p, i->documentation) {
-
- if (startswith(*p, "man:")) {
- const char *args[4] = { "man", NULL, NULL, NULL };
- _cleanup_free_ char *page = NULL, *section = NULL;
- char *e = NULL;
- pid_t pid;
- size_t k;
-
- k = strlen(*p);
-
- if ((*p)[k-1] == ')')
- e = strrchr(*p, '(');
-
- if (e) {
- page = strndup((*p) + 4, e - *p - 4);
- section = strndup(e + 1, *p + k - e - 2);
- if (!page || !section) {
- log_oom();
- return;
- }
-
- args[1] = section;
- args[2] = page;
- } else
- args[1] = *p + 4;
-
- pid = fork();
- if (pid < 0) {
- log_error("Failed to fork: %m");
- continue;
- }
-
- if (pid == 0) {
- /* Child */
- execvp(args[0], (char**) args);
- log_error("Failed to execute man: %m");
- _exit(EXIT_FAILURE);
- }
-
- wait_for_terminate(pid, NULL);
- } else
+ STRV_FOREACH(p, i->documentation)
+ if (startswith(*p, "man:"))
+ show_man_page(*p + 4, false);
+ else
log_info("Can't show: %s", *p);
- }
}
static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *i, const char *contents) {
i->exit_code = (int) j;
else if (streq(name, "ExecMainStatus"))
i->exit_status = (int) j;
+ else if (streq(name, "StatusErrno"))
+ i->status_errno = (int) j;
break;
}
&reply,
"u", pid);
if (r < 0) {
- log_error("Failed to get unit for PID %lu: %s", (unsigned long) pid, bus_error_message(&error, r));
+ log_error("Failed to get unit for PID "PID_FMT": %s", pid, bus_error_message(&error, r));
return r;
}
_cleanup_free_ UnitInfo *unit_infos = NULL;
const UnitInfo *u;
unsigned c;
- int r;
+ int r, ret = 0;
r = get_unit_list(bus, NULL, NULL, &unit_infos, 0, &reply);
if (r < 0)
r = show_one(verb, bus, p, show_properties, new_line, ellipsized);
if (r < 0)
return r;
+ else if (r > 0 && ret == 0)
+ ret = r;
}
- return 0;
+ return ret;
}
static int show_system_status(sd_bus *bus) {
} else
on = off = "";
- printf("%s%s%s%s\n", on, draw_special_char(DRAW_BLACK_CIRCLE), off, arg_host ? arg_host : hn);
+ printf("%s%s%s %s\n", on, draw_special_char(DRAW_BLACK_CIRCLE), off, arg_host ? arg_host : hn);
printf(" State: %s%s%s\n",
on, strna(mi.state), off);
}
}
- show_one(args[0], bus, unit, show_properties, &new_line, &ellipsized);
+ r = show_one(args[0], bus, unit, show_properties,
+ &new_line, &ellipsized);
+ if (r < 0)
+ return r;
+ else if (r > 0 && ret == 0)
+ ret = r;
}
if (!strv_isempty(patterns)) {
if (!unit)
return log_oom();
- show_one(args[0], bus, unit, show_properties, &new_line, &ellipsized);
+ r = show_one(args[0], bus, unit, show_properties,
+ &new_line, &ellipsized);
+ if (r < 0)
+ return r;
+ else if (r > 0 && ret == 0)
+ ret = r;
}
}
}
}
static int cat(sd_bus *bus, char **args) {
- _cleanup_free_ char *unit = NULL;
_cleanup_strv_free_ char **names = NULL;
char **name;
bool first = true;
STRV_FOREACH(name, names) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_strv_free_ char **dropin_paths = NULL;
- _cleanup_free_ char *fragment_path = NULL;
+ _cleanup_free_ char *fragment_path = NULL, *unit = NULL;
char **path;
unit = unit_dbus_path_from_name(*name);
const char *root_systemd_path = NULL, *root_init_path = NULL;
root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH);
- root_init_path = strappenda3(root, "/", init);
+ root_init_path = strappenda(root, "/", init);
/* If the passed init is actually the same as the
* systemd binary, then let's suppress it. */
/* Processes all SysV units, and reshuffles the array so that
* afterwards only the native units remain */
- r = lookup_paths_init(&paths, SYSTEMD_SYSTEM, false, NULL, NULL, NULL);
+ r = lookup_paths_init(&paths, SYSTEMD_SYSTEM, false, arg_root, NULL, NULL, NULL);
if (r < 0)
return r;
r = 0;
for (f = 0; args[f]; f++) {
const char *name;
- _cleanup_free_ char *p = NULL, *q = NULL;
+ _cleanup_free_ char *p = NULL, *q = NULL, *l = NULL;
bool found_native = false, found_sysv;
unsigned c = 1;
const char *argv[6] = { "/sbin/chkconfig", NULL, NULL, NULL, NULL };
- char **k, *l;
+ char **k;
int j;
pid_t pid;
siginfo_t status;
continue;
STRV_FOREACH(k, paths.unit_path) {
- if (!isempty(arg_root))
- asprintf(&p, "%s/%s/%s", arg_root, *k, name);
- else
- asprintf(&p, "%s/%s", *k, name);
-
- if (!p) {
- r = log_oom();
- goto finish;
- }
+ _cleanup_free_ char *path = NULL;
- found_native = access(p, F_OK) >= 0;
- free(p);
- p = NULL;
+ path = path_join(arg_root, *k, name);
+ if (!path)
+ return log_oom();
+ found_native = access(path, F_OK) >= 0;
if (found_native)
break;
}
if (found_native)
continue;
- if (!isempty(arg_root))
- asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
- else
- asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
- if (!p) {
- r = log_oom();
- goto finish;
- }
+ p = path_join(arg_root, SYSTEM_SYSVINIT_PATH, name);
+ if (!p)
+ return log_oom();
- p[strlen(p) - sizeof(".service") + 1] = 0;
+ p[strlen(p) - strlen(".service")] = 0;
found_sysv = access(p, F_OK) >= 0;
-
if (!found_sysv)
continue;
argv[c] = NULL;
l = strv_join((char**)argv, " ");
- if (!l) {
- r = log_oom();
- goto finish;
- }
+ if (!l)
+ return log_oom();
log_info("Executing %s", l);
- free(l);
pid = fork();
if (pid < 0) {
log_error("Failed to fork: %m");
- r = -errno;
- goto finish;
+ return -errno;
} else if (pid == 0) {
/* Child */
j = wait_for_terminate(pid, &status);
if (j < 0) {
log_error("Failed to wait for child: %s", strerror(-r));
- r = j;
- goto finish;
+ return j;
}
if (status.si_code == CLD_EXITED) {
puts("disabled");
}
- } else if (status.si_status != 0) {
- r = -EINVAL;
- goto finish;
- }
- } else {
- r = -EPROTO;
- goto finish;
- }
+ } else if (status.si_status != 0)
+ return -EINVAL;
+ } else
+ return -EPROTO;
}
-finish:
/* Drop all SysV units */
for (f = 0, t = 0; args[f]; f++) {
} else if (streq(verb, "link"))
r = unit_file_link(arg_scope, arg_runtime, arg_root, names, arg_force, &changes, &n_changes);
else if (streq(verb, "preset")) {
- r = unit_file_preset(arg_scope, arg_runtime, arg_root, names, arg_force, &changes, &n_changes);
+ r = unit_file_preset(arg_scope, arg_runtime, arg_root, names, arg_preset_mode, arg_force, &changes, &n_changes);
carries_install_info = r;
} else if (streq(verb, "mask"))
r = unit_file_mask(arg_scope, arg_runtime, arg_root, names, arg_force, &changes, &n_changes);
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
int expect_carries_install_info = false;
- bool send_force = true;
+ bool send_force = true, send_preset_mode = false;
const char *method;
if (streq(verb, "enable")) {
} else if (streq(verb, "link"))
method = "LinkUnitFiles";
else if (streq(verb, "preset")) {
- method = "PresetUnitFiles";
+
+ if (arg_preset_mode != UNIT_FILE_PRESET_FULL) {
+ method = "PresetUnitFilesWithMode";
+ send_preset_mode = true;
+ } else
+ method = "PresetUnitFiles";
+
expect_carries_install_info = true;
} else if (streq(verb, "mask"))
method = "MaskUnitFiles";
if (r < 0)
return bus_log_create_error(r);
+ if (send_preset_mode) {
+ r = sd_bus_message_append(m, "s", unit_file_preset_mode_to_string(arg_preset_mode));
+ if (r < 0)
+ return bus_log_create_error(r);
+ }
+
r = sd_bus_message_append(m, "b", arg_runtime);
if (r < 0)
return bus_log_create_error(r);
return r;
}
+static int add_dependency(sd_bus *bus, char **args) {
+ _cleanup_strv_free_ char **names = NULL;
+ _cleanup_free_ char *target = NULL;
+ const char *verb = args[0];
+ UnitDependency dep;
+ int r = 0;
+
+ if (!args[1])
+ return 0;
+
+ target = unit_name_mangle_with_suffix(args[1], MANGLE_NOGLOB, ".target");
+ if (!target)
+ return log_oom();
+
+ r = mangle_names(args+2, &names);
+ if (r < 0)
+ return r;
+
+ if (streq(verb, "add-wants"))
+ dep = UNIT_WANTS;
+ else if (streq(verb, "add-requires"))
+ dep = UNIT_REQUIRES;
+ else
+ assert_not_reached("Unknown verb");
+
+ if (!bus || avoid_bus()) {
+ UnitFileChange *changes = NULL;
+ 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 < 0) {
+ log_error("Can't add dependency: %s", strerror(-r));
+ return r;
+ }
+
+ if (!arg_quiet)
+ dump_unit_file_changes(changes, n_changes);
+
+ unit_file_changes_free(changes, n_changes);
+
+ } else {
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+
+ r = sd_bus_message_new_method_call(
+ bus,
+ &m,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "AddDependencyUnitFiles");
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_message_append_strv(m, names);
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_message_append(m, "s", target);
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_message_append(m, "s", unit_dependency_to_string(dep));
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_message_append(m, "b", arg_runtime);
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_message_append(m, "b", arg_force);
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_call(bus, m, 0, &error, &reply);
+ if (r < 0) {
+ log_error("Failed to execute operation: %s", bus_error_message(&error, r));
+ return r;
+ }
+
+ r = deserialize_and_dump_unit_file_changes(reply);
+ if (r < 0)
+ return r;
+
+ if (!arg_no_reload)
+ r = daemon_reload(bus, args);
+ else
+ r = 0;
+ }
+
+ return r;
+}
+
+static int preset_all(sd_bus *bus, char **args) {
+ UnitFileChange *changes = NULL;
+ unsigned n_changes = 0;
+ int r;
+
+ if (!bus || avoid_bus()) {
+
+ r = unit_file_preset_all(arg_scope, arg_runtime, arg_root, arg_preset_mode, arg_force, &changes, &n_changes);
+ if (r < 0) {
+ log_error("Operation failed: %s", strerror(-r));
+ goto finish;
+ }
+
+ if (!arg_quiet)
+ dump_unit_file_changes(changes, n_changes);
+
+ r = 0;
+
+ } else {
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "PresetAllUnitFiles",
+ &error,
+ &reply,
+ "sbb",
+ unit_file_preset_mode_to_string(arg_preset_mode),
+ arg_runtime,
+ arg_force);
+ if (r < 0) {
+ log_error("Failed to execute operation: %s", bus_error_message(&error, r));
+ return r;
+ }
+
+ r = deserialize_and_dump_unit_file_changes(reply);
+ if (r < 0)
+ return r;
+
+ if (!arg_no_reload)
+ r = daemon_reload(bus, args);
+ else
+ r = 0;
+ }
+
+finish:
+ unit_file_changes_free(changes, n_changes);
+
+ return r;
+}
+
static int unit_is_enabled(sd_bus *bus, char **args) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
return !enabled;
}
-static int systemctl_help(void) {
+static int is_system_running(sd_bus *bus, char **args) {
+ _cleanup_free_ char *state = NULL;
+ int r;
+
+ r = sd_bus_get_property_string(
+ bus,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "SystemState",
+ NULL,
+ &state);
+ if (r < 0) {
+ if (!arg_quiet)
+ puts("unknown");
+ return 0;
+ }
+
+ if (!arg_quiet)
+ puts(state);
+
+ return streq(state, "running") ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+static void systemctl_help(void) {
pager_open_if_enabled();
" --runtime Enable unit files only temporarily until next reboot\n"
" -f --force When enabling unit files, override existing symlinks\n"
" When shutting down, execute action immediately\n"
+ " --preset-mode= Specifies whether fully apply presets, or only enable,\n"
+ " or only disable\n"
" --root=PATH Enable unit files in the specified root directory\n"
" -n --lines=INTEGER Number of journal entries to show\n"
" -o --output=STRING Change journal output mode (short, short-monotonic,\n"
" reenable NAME... Reenable one or more unit files\n"
" preset NAME... Enable/disable one or more unit files\n"
" based on preset configuration\n"
+ " preset-all Enable/disable all unit files based on\n"
+ " preset configuration\n"
" is-enabled NAME... Check whether unit files are enabled\n\n"
" mask NAME... Mask one or more units\n"
" unmask NAME... Unmask one or more units\n"
" link PATH... Link one or more units files into\n"
" the search path\n"
+ " add-wants TARGET NAME... Add 'Wants' dependency for the target\n"
+ " on specified one or more units\n"
+ " add-requires TARGET NAME... Add 'Requires' dependency for the target\n"
+ " on specified one or more units\n"
" get-default Get the name of the default target\n"
" set-default NAME Set the default target\n\n"
"Machine Commands:\n"
" daemon-reload Reload systemd manager configuration\n"
" daemon-reexec Reexecute systemd manager\n\n"
"System Commands:\n"
+ " is-system-running Check whether system is fully running\n"
" default Enter system default mode\n"
" rescue Enter system rescue mode\n"
" emergency Enter system emergency mode\n"
" hibernate Hibernate the system\n"
" hybrid-sleep Hibernate and suspend the system\n",
program_invocation_short_name);
-
- return 0;
}
-static int halt_help(void) {
-
+static void halt_help(void) {
printf("%s [OPTIONS...]%s\n\n"
"%s the system.\n\n"
" --help Show this help\n"
arg_action == ACTION_REBOOT ? "Reboot" :
arg_action == ACTION_POWEROFF ? "Power off" :
"Halt");
-
- return 0;
}
-static int shutdown_help(void) {
-
+static void shutdown_help(void) {
printf("%s [OPTIONS...] [TIME] [WALL...]\n\n"
"Shut down the system.\n\n"
" --help Show this help\n"
" --no-wall Don't send wall message before halt/power-off/reboot\n"
" -c Cancel a pending shutdown\n",
program_invocation_short_name);
-
- return 0;
}
-static int telinit_help(void) {
-
+static void telinit_help(void) {
printf("%s [OPTIONS...] {COMMAND}\n\n"
"Send control commands to the init daemon.\n\n"
" --help Show this help\n"
" q, Q Reload init daemon configuration\n"
" u, U Reexecute init daemon\n",
program_invocation_short_name);
-
- return 0;
}
-static int runlevel_help(void) {
-
+static void runlevel_help(void) {
printf("%s [OPTIONS...]\n\n"
"Prints the previous and current runlevel of the init system.\n\n"
" --help Show this help\n",
program_invocation_short_name);
-
- return 0;
}
-static int help_types(void) {
+static void help_types(void) {
int i;
const char *t;
- puts("Available unit types:");
+ if (!arg_no_legend)
+ puts("Available unit types:");
for (i = 0; i < _UNIT_TYPE_MAX; i++) {
t = unit_type_to_string(i);
if (t)
puts(t);
}
-
- return 0;
}
static int systemctl_parse_argv(int argc, char *argv[]) {
ARG_FORCE,
ARG_PLAIN,
ARG_STATE,
- ARG_JOB_MODE
+ ARG_JOB_MODE,
+ ARG_PRESET_MODE,
};
static const struct option options[] = {
{ "plain", no_argument, NULL, ARG_PLAIN },
{ "state", required_argument, NULL, ARG_STATE },
{ "recursive", no_argument, NULL, 'r' },
+ { "preset-mode", required_argument, NULL, ARG_PRESET_MODE },
{}
};
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "ht:p:alqfs:H:M:n:o:ir", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "ht:p:alqfs:H:M:n:o:ir", options, NULL)) >= 0)
switch (c) {
case 'h':
- return systemctl_help();
+ systemctl_help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
return 0;
case 't': {
- char *word, *state;
+ const char *word, *state;
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
if (!arg_properties)
return log_oom();
} else {
- char *word, *state;
+ const char *word, *state;
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
break;
case ARG_STATE: {
- char *word, *state;
+ const char *word, *state;
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
case 'r':
if (geteuid() != 0) {
- log_error("--recursive requires root priviliges.");
+ log_error("--recursive requires root privileges.");
return -EPERM;
}
arg_recursive = true;
break;
+ case ARG_PRESET_MODE:
+
+ arg_preset_mode = unit_file_preset_mode_from_string(optarg);
+ if (arg_preset_mode < 0) {
+ log_error("Failed to parse preset mode: %s.", optarg);
+ return -EINVAL;
+ }
+
+ break;
+
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_transport != BUS_TRANSPORT_LOCAL && arg_scope != UNIT_FILE_SYSTEM) {
log_error("Cannot access user instance remotely.");
if (runlevel == '0' || runlevel == '6')
arg_force = 2;
- while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
- return halt_help();
+ halt_help();
+ return 0;
case ARG_HALT:
arg_action = ACTION_HALT;
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_action == ACTION_REBOOT && (argc == optind || argc == optind + 1)) {
r = update_reboot_param_file(argc == optind + 1 ? argv[optind] : NULL);
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "HPrhkt:afFc", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "HPrhkt:afFc", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
- return shutdown_help();
+ shutdown_help();
+ return 0;
case 'H':
arg_action = ACTION_HALT;
default:
assert_not_reached("Unhandled option");
}
- }
if (argc > optind && arg_action != ACTION_CANCEL_SHUTDOWN) {
r = parse_time_spec(argv[optind], &arg_when);
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
- return telinit_help();
+ telinit_help();
+ return 0;
case ARG_NO_WALL:
arg_no_wall = true;
default:
assert_not_reached("Unhandled option");
}
- }
if (optind >= argc) {
- telinit_help();
+ log_error("%s: required argument missing.",
+ program_invocation_short_name);
return -EINVAL;
}
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
- return runlevel_help();
+ runlevel_help();
+ return 0;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
- }
if (optind < argc) {
log_error("Too many arguments.");
{ "is-enabled", MORE, 2, unit_is_enabled, NOBUS },
{ "reenable", MORE, 2, enable_unit, NOBUS },
{ "preset", MORE, 2, enable_unit, NOBUS },
+ { "preset-all", EQUAL, 1, preset_all, NOBUS },
{ "mask", MORE, 2, enable_unit, NOBUS },
{ "unmask", MORE, 2, enable_unit, NOBUS },
{ "link", MORE, 2, enable_unit, NOBUS },
{ "set-default", EQUAL, 2, set_default, NOBUS },
{ "get-default", EQUAL, 1, get_default, NOBUS },
{ "set-property", MORE, 3, set_property },
+ { "is-system-running", EQUAL, 1, is_system_running },
+ { "add-wants", MORE, 3, add_dependency, NOBUS },
+ { "add-requires", MORE, 3, add_dependency, NOBUS },
{}
}, *verb = verbs;
}
int main(int argc, char*argv[]) {
- _cleanup_bus_unref_ sd_bus *bus = NULL;
+ _cleanup_bus_close_unref_ sd_bus *bus = NULL;
int r;
setlocale(LC_ALL, "");