chiark / gitweb /
systemctl: make most operations NOPs in a chroot
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Apr 2011 23:35:56 +0000 (01:35 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Apr 2011 23:35:56 +0000 (01:35 +0200)
src/systemctl.c

index 1507b52..eab4bf3 100644 (file)
@@ -5336,11 +5336,17 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
 
         /* Require a bus connection for all operations but
          * enable/disable */
-        if (!streq(verbs[i].verb, "enable") &&
-            !streq(verbs[i].verb, "disable") &&
-            !bus) {
-                log_error("Failed to get D-Bus connection: %s", error->message);
-                return -EIO;
+        if (!streq(verbs[i].verb, "enable") && !streq(verbs[i].verb, "disable")) {
+
+                if (running_in_chroot() > 0) {
+                        log_info("Running in chroot, ignoring request.");
+                        return 0;
+                }
+
+                if (!bus) {
+                        log_error("Failed to get D-Bus connection: %s", error->message);
+                        return -EIO;
+                }
         }
 
         return verbs[i].dispatch(bus, argv + optind, left);
@@ -5652,6 +5658,12 @@ int main(int argc, char*argv[]) {
                 goto finish;
         }
 
+        if (running_in_chroot() > 0 && arg_action != ACTION_SYSTEMCTL) {
+                log_info("Running in chroot, ignoring request.");
+                retval = 0;
+                goto finish;
+        }
+
         if (arg_transport == TRANSPORT_NORMAL)
                 bus_connect(arg_user ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, &private_bus, &error);
         else if (arg_transport == TRANSPORT_POLKIT) {