]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: refuse online-only ops with --root
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 Apr 2020 12:26:36 +0000 (14:26 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 5 May 2020 16:05:23 +0000 (18:05 +0200)
It is super confusing when a command does not support --root, and is called
with it specified, and returns some bogus results. Let's just catch this
early and refuse.

src/systemctl/systemctl.c

index 0a3d975d888ae9f7ee58a6eb057f1116a9a30e1e..077609f4de6b56b9d2b9a4169d8d820eb15668ac 100644 (file)
@@ -9213,6 +9213,12 @@ static int systemctl_main(int argc, char *argv[]) {
                 {}
         };
 
+        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);
 }