[systemd-devel] [PATCH] shutdown: do reboot() for openvz container

Kir Kolyshkin kir at openvz.org
Fri Aug 24 05:22:52 PDT 2012


Proper handling of reboot() syscall issued from the inside of a container
was always supported by OpenVZ kernels. More to say, OpenVZ relies on the fact
that container calls reboot in order to distinguish between shutdown and
reboot-- in the latter case container is being restarted.

This patch brings the reboot() back for OpenVZ container.

Originally found when using Fedora 17 container (systemd-44-17.fc17)
and reported to OpenVZ bugzilla: http://bugzilla.openvz.org/2336

Reported-by: Dāvis <davispuh at inbox.lv>
Cc: Konstantin Volckov <wolf at parallels.com>
Cc: Alexander Fenster <afenster at parallels.com>
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 src/core/shutdown.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/core/shutdown.c b/src/core/shutdown.c
index c3a4c39..50536fc 100644
--- a/src/core/shutdown.c
+++ b/src/core/shutdown.c
@@ -132,8 +132,9 @@ static int pivot_to_new_root(void) {
 int main(int argc, char *argv[]) {
         int cmd, r;
         unsigned retries;
-        bool need_umount = true, need_swapoff = true, need_loop_detach = true, need_dm_detach = true;
+        bool need_umount = true, need_swapoff = true, need_loop_detach = true, need_dm_detach = true, need_reboot = true;
         bool in_container, use_watchdog = false;
+        const char *container_type;
         char *arguments[3];
 
         log_parse_environment();
@@ -154,7 +155,7 @@ int main(int argc, char *argv[]) {
                 goto error;
         }
 
-        in_container = detect_container(NULL) > 0;
+        in_container = detect_container(&container_type) > 0;
 
         if (streq(argv[1], "reboot"))
                 cmd = RB_AUTOBOOT;
@@ -185,6 +186,8 @@ int main(int argc, char *argv[]) {
                 need_swapoff = false;
                 need_dm_detach = false;
                 need_loop_detach = false;
+                if (!streq(container_type, "openvz"))
+                        need_reboot = false;
         }
 
         /* Unmount all mountpoints, swaps, and loopback devices */
@@ -265,7 +268,7 @@ int main(int argc, char *argv[]) {
 
         /* If we are in a container, just exit, this will kill our
          * container for good. */
-        if (in_container) {
+        if (!need_reboot) {
                 log_error("Exiting container.");
                 exit(0);
         }
-- 
1.7.10.4



More information about the systemd-devel mailing list