Merge pull request #25437 from YHNdnzj/systemctl-disable-warn-statically-enabled-services
systemctl: warn if trying to disable a unit with no install info
This commit is contained in:
@@ -67,7 +67,7 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
InstallChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
int carries_install_info = -1;
|
||||
bool ignore_carries_install_info = arg_quiet;
|
||||
bool ignore_carries_install_info = arg_quiet || arg_no_warn;
|
||||
int r;
|
||||
|
||||
if (!argv[1])
|
||||
@@ -109,9 +109,10 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
if (streq(verb, "enable")) {
|
||||
r = unit_file_enable(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
carries_install_info = r;
|
||||
} else if (streq(verb, "disable"))
|
||||
} else if (streq(verb, "disable")) {
|
||||
r = unit_file_disable(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
else if (streq(verb, "reenable")) {
|
||||
carries_install_info = r;
|
||||
} else if (streq(verb, "reenable")) {
|
||||
r = unit_file_reenable(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
carries_install_info = r;
|
||||
} else if (streq(verb, "link"))
|
||||
@@ -165,7 +166,8 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
method = "EnableUnitFiles";
|
||||
expect_carries_install_info = true;
|
||||
} else if (streq(verb, "disable")) {
|
||||
method = "DisableUnitFiles";
|
||||
method = "DisableUnitFilesWithFlagsAndInstallInfo";
|
||||
expect_carries_install_info = true;
|
||||
send_force = false;
|
||||
} else if (streq(verb, "reenable")) {
|
||||
method = "ReenableUnitFiles";
|
||||
@@ -208,7 +210,10 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
}
|
||||
|
||||
if (send_runtime) {
|
||||
r = sd_bus_message_append(m, "b", arg_runtime);
|
||||
if (streq(method, "DisableUnitFilesWithFlagsAndInstallInfo"))
|
||||
r = sd_bus_message_append(m, "t", arg_runtime ? UNIT_FILE_RUNTIME : 0);
|
||||
else
|
||||
r = sd_bus_message_append(m, "b", arg_runtime);
|
||||
if (r < 0)
|
||||
return bus_log_create_error(r);
|
||||
}
|
||||
@@ -245,7 +250,7 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
if (carries_install_info == 0 && !ignore_carries_install_info)
|
||||
log_notice("The unit files have no installation config (WantedBy=, RequiredBy=, Also=,\n"
|
||||
"Alias= settings in the [Install] section, and DefaultInstance= for template\n"
|
||||
"units). This means they are not meant to be enabled using systemctl.\n"
|
||||
"units). This means they are not meant to be enabled or disabled using systemctl.\n"
|
||||
" \n" /* trick: the space is needed so that the line does not get stripped from output */
|
||||
"Possible reasons for having this kind of units are:\n"
|
||||
"%1$s A unit may be statically enabled by being symlinked from another unit's\n"
|
||||
|
||||
@@ -84,6 +84,7 @@ bool arg_show_types = false;
|
||||
int arg_check_inhibitors = -1;
|
||||
bool arg_dry_run = false;
|
||||
bool arg_quiet = false;
|
||||
bool arg_no_warn = false;
|
||||
bool arg_full = false;
|
||||
bool arg_recursive = false;
|
||||
bool arg_with_dependencies = false;
|
||||
@@ -277,6 +278,8 @@ static int systemctl_help(void) {
|
||||
" kexec, suspend, hibernate, suspend-then-hibernate,\n"
|
||||
" hybrid-sleep, default, rescue, emergency, and exit.\n"
|
||||
" -q --quiet Suppress output\n"
|
||||
" --no-warn Don't generate warning when trying to enable/disable\n"
|
||||
" units without install information\n"
|
||||
" --wait For (re)start, wait until service stopped again\n"
|
||||
" For is-system-running, wait until startup is completed\n"
|
||||
" --no-block Do not wait until operation finished\n"
|
||||
@@ -433,6 +436,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
|
||||
ARG_READ_ONLY,
|
||||
ARG_MKDIR,
|
||||
ARG_MARKED,
|
||||
ARG_NO_WARN,
|
||||
};
|
||||
|
||||
static const struct option options[] = {
|
||||
@@ -465,6 +469,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
|
||||
{ "no-wall", no_argument, NULL, ARG_NO_WALL },
|
||||
{ "dry-run", no_argument, NULL, ARG_DRY_RUN },
|
||||
{ "quiet", no_argument, NULL, 'q' },
|
||||
{ "no-warn", no_argument, NULL, ARG_NO_WARN },
|
||||
{ "root", required_argument, NULL, ARG_ROOT },
|
||||
{ "image", required_argument, NULL, ARG_IMAGE },
|
||||
{ "force", no_argument, NULL, 'f' },
|
||||
@@ -926,6 +931,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
|
||||
arg_marked = true;
|
||||
break;
|
||||
|
||||
case ARG_NO_WARN:
|
||||
arg_no_warn = true;
|
||||
break;
|
||||
|
||||
case '.':
|
||||
/* Output an error mimicking getopt, and print a hint afterwards */
|
||||
log_error("%s: invalid option -- '.'", program_invocation_name);
|
||||
|
||||
@@ -65,6 +65,7 @@ extern bool arg_show_types;
|
||||
extern int arg_check_inhibitors;
|
||||
extern bool arg_dry_run;
|
||||
extern bool arg_quiet;
|
||||
extern bool arg_no_warn;
|
||||
extern bool arg_full;
|
||||
extern bool arg_recursive;
|
||||
extern bool arg_with_dependencies;
|
||||
|
||||
Reference in New Issue
Block a user