bin/admin: Check for booted deployment to see if we should reboot
authorColin Walters <walters@verbum.org>
Fri, 1 Sep 2017 18:43:33 +0000 (14:43 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 1 Sep 2017 21:34:32 +0000 (21:34 +0000)
Rather than calling `ostree_sysroot_get_path()`, which I'd like to deprecate for
the same reason as `ostree_repo_get_path()`.

Closes: #1123
Approved by: jlebon

src/ostree/ot-admin-functions.c

index a0a66b6a23281345a1bf01e7d856fd3f37922b27..6a99db04ac7d7b6bd88e4752a1795cbca4104e4b 100644 (file)
@@ -151,13 +151,15 @@ ot_admin_sysroot_lock (OstreeSysroot  *sysroot,
 gboolean
 ot_admin_execve_reboot (OstreeSysroot *sysroot, GError **error)
 {
-  g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/");
+  OstreeDeployment *booted = ostree_sysroot_get_booted_deployment (sysroot);
 
-  if (g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
-    {
-      if (execlp ("systemctl", "systemctl", "reboot", NULL) < 0)
-        return glnx_throw_errno (error);
-    }
+  /* If the sysroot isn't booted, we shouldn't reboot, even if somehow the user
+   * asked for it; might accidentally be specified in a build script, etc.
+   */
+  if (!booted)
+    return TRUE;
 
+  if (execlp ("systemctl", "systemctl", "reboot", NULL) < 0)
+    return glnx_throw_errno_prefix (error, "execve(systemctl reboot)");
   return TRUE;
 }