summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-01-12 00:09:22 +0100
committerLennart Poettering <lennart@poettering.net>2013-01-14 21:24:57 +0100
commit748ebafa7a10d4e1f168dd8ae0193124cdf4226e (patch)
treeaf4a7d69140019f2178da5c05c085200f45fbc3a
parentd255133d8edc84662d2370a77414505a800d1922 (diff)
systemctl: honour inhibitors only when running unprivileged
-rw-r--r--src/systemctl/systemctl.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index bfa4d45fc..91467cc08 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1791,7 +1791,16 @@ static int check_inhibitors(DBusConnection *bus, enum action a) {
int r;
unsigned c = 0;
- if (arg_ignore_inhibitors)
+ if (!bus)
+ return 0;
+
+ if (arg_ignore_inhibitors || arg_force > 0)
+ return 0;
+
+ if (arg_when > 0)
+ return 0;
+
+ if (geteuid() == 0)
return 0;
if (!on_tty())
@@ -1890,6 +1899,10 @@ static int start_special(DBusConnection *bus, char **args) {
a = verb_to_action(args[0]);
+ r = check_inhibitors(bus, a);
+ if (r < 0)
+ return r;
+
if (arg_force >= 2 && geteuid() != 0) {
log_error("Must be root.");
return -EPERM;
@@ -1909,12 +1922,6 @@ static int start_special(DBusConnection *bus, char **args) {
a == ACTION_EXIT))
return daemon_reload(bus, args);
- if (arg_force <= 0) {
- r = check_inhibitors(bus, a);
- if (r < 0)
- return r;
- }
-
/* first try logind, to allow authentication with polkit */
if (geteuid() != 0 &&
(a == ACTION_POWEROFF ||
@@ -5304,11 +5311,9 @@ static _noreturn_ void halt_now(enum action a) {
static int halt_main(DBusConnection *bus) {
int r;
- if (arg_when <= 0 && arg_force <= 0) {
- r = check_inhibitors(bus, arg_action);
- if (r < 0)
- return r;
- }
+ r = check_inhibitors(bus, arg_action);
+ if (r < 0)
+ return r;
if (geteuid() != 0) {
/* Try logind if we are a normal user and no special