return true;
}
+static bool show_preset_for_state(UnitFileState state) {
+ /* Don't show preset state in those unit file states, it'll only confuse users. */
+ return !IN_SET(state,
+ UNIT_FILE_ALIAS,
+ UNIT_FILE_STATIC,
+ UNIT_FILE_GENERATED,
+ UNIT_FILE_TRANSIENT);
+}
+
static int output_unit_file_list(const UnitFileList *units, unsigned c) {
_cleanup_(table_unrefp) Table *table = NULL;
- const UnitFileList *u;
+ _cleanup_(unit_file_presets_freep) UnitFilePresets presets = {};
int r;
table = table_new("unit file", "state", "vendor preset");
if (arg_full)
table_set_width(table, 0);
- for (u = units; u < units + c; u++) {
+ for (const UnitFileList *u = units; u < units + c; u++) {
const char *on_underline = NULL, *on_unit_color = NULL, *id;
- const char *on_preset_color = NULL, *unit_preset_str;
bool underline;
underline = u + 1 < units + c &&
UNIT_FILE_DISABLED,
UNIT_FILE_BAD))
on_unit_color = underline ? ansi_highlight_red_underline() : ansi_highlight_red();
- else if (u->state == UNIT_FILE_ENABLED)
+ else if (IN_SET(u->state,
+ UNIT_FILE_ENABLED,
+ UNIT_FILE_ALIAS))
on_unit_color = underline ? ansi_highlight_green_underline() : ansi_highlight_green();
else
on_unit_color = on_underline;
id = basename(u->path);
- r = unit_file_query_preset(arg_scope, NULL, id);
- if (r < 0) {
- unit_preset_str = "n/a";
- on_preset_color = underline ? on_underline : ansi_normal();
- } else if (r == 0) {
- unit_preset_str = "disabled";
- on_preset_color = underline ? ansi_highlight_red_underline() : ansi_highlight_red();
- } else {
- unit_preset_str = "enabled";
- on_preset_color = underline ? ansi_highlight_green_underline() : ansi_highlight_green();
- }
-
r = table_add_many(table,
TABLE_STRING, id,
TABLE_SET_COLOR, strempty(on_underline),
TABLE_STRING, unit_file_state_to_string(u->state),
- TABLE_SET_COLOR, strempty(on_unit_color),
- TABLE_STRING, unit_preset_str,
- TABLE_SET_COLOR, strempty(on_preset_color));
+ TABLE_SET_COLOR, strempty(on_unit_color));
+ if (r < 0)
+ return table_log_add_error(r);
+
+ if (show_preset_for_state(u->state)) {
+ const char *unit_preset_str, *on_preset_color;
+
+ r = unit_file_query_preset(arg_scope, arg_root, id, &presets);
+ if (r < 0) {
+ unit_preset_str = "n/a";
+ on_preset_color = underline ? on_underline : ansi_normal();
+ } else if (r == 0) {
+ unit_preset_str = "disabled";
+ on_preset_color = underline ? ansi_highlight_red_underline() : ansi_highlight_red();
+ } else {
+ unit_preset_str = "enabled";
+ on_preset_color = underline ? ansi_highlight_green_underline() : ansi_highlight_green();
+ }
+
+ r = table_add_many(table,
+ TABLE_STRING, unit_preset_str,
+ TABLE_SET_COLOR, strempty(on_preset_color));
+ } else
+ r = table_add_many(table, TABLE_EMPTY);
+
if (r < 0)
return table_log_add_error(r);
}
if (!isempty(i->load_error))
printf(" Loaded: %s%s%s (Reason: %s)\n",
on, strna(i->load_state), off, i->load_error);
- else if (path && !isempty(i->unit_file_state) && !isempty(i->unit_file_preset) &&
- !STR_IN_SET(i->unit_file_state, "generated", "transient"))
- printf(" Loaded: %s%s%s (%s; %s; vendor preset: %s)\n",
- on, strna(i->load_state), off, path, i->unit_file_state, i->unit_file_preset);
- else if (path && !isempty(i->unit_file_state))
- printf(" Loaded: %s%s%s (%s; %s)\n",
- on, strna(i->load_state), off, path, i->unit_file_state);
- else if (path)
+ else if (path && !isempty(i->unit_file_state)) {
+ bool show_preset = !isempty(i->unit_file_preset) &&
+ show_preset_for_state(unit_file_state_from_string(i->unit_file_state));
+
+ printf(" Loaded: %s%s%s (%s; %s%s%s)\n",
+ on, strna(i->load_state), off,
+ path,
+ i->unit_file_state,
+ show_preset ? "; vendor preset: " : "",
+ show_preset ? i->unit_file_preset : "");
+
+ } else if (path)
printf(" Loaded: %s%s%s (%s)\n",
on, strna(i->load_state), off, path);
else
if (show_mode == SYSTEMCTL_SHOW_HELP && argc <= 1)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "This command expects one or more unit names. Did you mean --help?");
+ "'help' command expects one or more unit names.\n"
+ "(Alternatively, help for systemctl itself may be shown with --help)");
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
UNIT_FILE_ENABLED,
UNIT_FILE_ENABLED_RUNTIME,
UNIT_FILE_STATIC,
+ UNIT_FILE_ALIAS,
UNIT_FILE_INDIRECT,
UNIT_FILE_GENERATED))
enabled = true;
{ "help", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, show },
{ "daemon-reload", VERB_ANY, 1, VERB_ONLINE_ONLY, daemon_reload },
{ "daemon-reexec", VERB_ANY, 1, VERB_ONLINE_ONLY, daemon_reload },
- { "log-level", VERB_ANY, 2, 0, log_level },
- { "log-target", VERB_ANY, 2, 0, log_target },
- { "service-watchdogs", VERB_ANY, 2, 0, service_watchdogs },
+ { "log-level", VERB_ANY, 2, VERB_ONLINE_ONLY, log_level },
+ { "log-target", VERB_ANY, 2, VERB_ONLINE_ONLY, log_target },
+ { "service-watchdogs", VERB_ANY, 2, VERB_ONLINE_ONLY, service_watchdogs },
{ "show-environment", VERB_ANY, 1, VERB_ONLINE_ONLY, show_environment },
{ "set-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, set_environment },
{ "unset-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, set_environment },
{}
};
+ const Verb *verb = verbs_find_verb(argv[optind], verbs);
+ if (verb && (verb->flags & VERB_ONLINE_ONLY) && arg_root)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Verb '%s' cannot be used with --root=.",
+ argv[optind] ?: verb->verb);
+
return dispatch_verb(argc, argv, verbs, NULL);
}