summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Stupp <felix.stupp@outlook.com>2020-10-29 12:48:48 +0100
committerLennart Poettering <lennart@poettering.net>2021-01-13 16:07:36 +0100
commit4327574fc1093513badc2177f71cede2fc88c13c (patch)
treebc9ffc4c024a5b20d532aab512fd836812f96815 /src
parent65ab27211c32089e038de7352091b46903c91ee6 (diff)
downloadsystemd-4327574fc1093513badc2177f71cede2fc88c13c.tar.gz
Added option --check-inhibitors for non-tty usage
As described in #2680, systemctl did ignore inhibitors if it is not attached to a tty to allow scripts to ignore inhibitors automatically. This pull request preserves this behavior but allows scripts to explicit check inhibitors if required. The new parameter '--check-inhibitors=yes' enables this feature. The old parameter '-i'/'--ignore-inhibitors' was deprecated in favor of '--check-inhibitors=no', the default behaviour can be specified with '--check-inhibitors=auto'. The new parameter is also described in the documentations and shell completions found here.
Diffstat (limited to 'src')
-rw-r--r--src/systemctl/systemctl-logind.c12
-rw-r--r--src/systemctl/systemctl.c24
-rw-r--r--src/systemctl/systemctl.h2
3 files changed, 28 insertions, 10 deletions
diff --git a/src/systemctl/systemctl-logind.c b/src/systemctl/systemctl-logind.c
index 405f12a33d..4070c64257 100644
--- a/src/systemctl/systemctl-logind.c
+++ b/src/systemctl/systemctl-logind.c
@@ -96,17 +96,19 @@ int logind_check_inhibitors(enum action a) {
char **s;
int r;
- if (arg_ignore_inhibitors || arg_force > 0)
+ if (arg_check_inhibitors == 0 || arg_force > 0)
return 0;
if (arg_when > 0)
return 0;
- if (geteuid() == 0)
- return 0;
+ if (arg_check_inhibitors < 0) {
+ if (geteuid() == 0)
+ return 0;
- if (!on_tty())
- return 0;
+ if (!on_tty())
+ return 0;
+ }
if (arg_transport != BUS_TRANSPORT_LOCAL)
return 0;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 7fe1e4e65b..7471fadd91 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -74,7 +74,7 @@ bool arg_no_wall = false;
bool arg_no_reload = false;
bool arg_value = false;
bool arg_show_types = false;
-bool arg_ignore_inhibitors = false;
+int arg_check_inhibitors = -1;
bool arg_dry_run = false;
bool arg_quiet = false;
bool arg_full = false;
@@ -241,7 +241,10 @@ static int systemctl_help(void) {
" -T --show-transaction When enqueuing a unit job, show full transaction\n"
" --show-types When showing sockets, explicitly show their type\n"
" --value When showing properties, only print the value\n"
- " -i --ignore-inhibitors When shutting down or sleeping, ignore inhibitors\n"
+ " --check-inhibitors=MODE\n"
+ " Specify if checking inhibitors before shutting down,\n"
+ " sleeping or hibernating\n"
+ " -i Shortcut for --check-inhibitors=no\n"
" --kill-who=WHO Whom to send signal to\n"
" -s --signal=SIGNAL Which signal to send\n"
" --what=RESOURCES Which types of resources to remove\n"
@@ -364,6 +367,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
ARG_REVERSE,
ARG_AFTER,
ARG_BEFORE,
+ ARG_CHECK_INHIBITORS,
ARG_DRY_RUN,
ARG_SHOW_TYPES,
ARG_IRREVERSIBLE,
@@ -415,7 +419,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
{ "fail", no_argument, NULL, ARG_FAIL }, /* compatibility only */
{ "irreversible", no_argument, NULL, ARG_IRREVERSIBLE }, /* compatibility only */
{ "ignore-dependencies", no_argument, NULL, ARG_IGNORE_DEPENDENCIES }, /* compatibility only */
- { "ignore-inhibitors", no_argument, NULL, 'i' },
+ { "ignore-inhibitors", no_argument, NULL, 'i' }, /* compatibility only */
+ { "check-inhibitors", required_argument, NULL, ARG_CHECK_INHIBITORS },
{ "value", no_argument, NULL, ARG_VALUE },
{ "user", no_argument, NULL, ARG_USER },
{ "system", no_argument, NULL, ARG_SYSTEM },
@@ -716,7 +721,18 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
break;
case 'i':
- arg_ignore_inhibitors = true;
+ arg_check_inhibitors = 0;
+ break;
+
+ case ARG_CHECK_INHIBITORS:
+ if (streq(optarg, "auto"))
+ arg_check_inhibitors = -1;
+ else {
+ r = parse_boolean(optarg);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse --check-inhibitors= argument: %s", optarg);
+ arg_check_inhibitors = r;
+ }
break;
case ARG_PLAIN:
diff --git a/src/systemctl/systemctl.h b/src/systemctl/systemctl.h
index f8cefc9b01..cdf56c7220 100644
--- a/src/systemctl/systemctl.h
+++ b/src/systemctl/systemctl.h
@@ -59,7 +59,7 @@ extern bool arg_no_wall;
extern bool arg_no_reload;
extern bool arg_value;
extern bool arg_show_types;
-extern bool arg_ignore_inhibitors;
+extern int arg_check_inhibitors;
extern bool arg_dry_run;
extern bool arg_quiet;
extern bool arg_full;