remove trailing blanks
[libguestfs.git] / daemon / command.c
index 1a9bebb..3f21807 100644 (file)
@@ -1,5 +1,5 @@
 /* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc. 
+ * Copyright (C) 2009 Red Hat Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include "actions.h"
 
 char *
-do_command (char * const * const argv)
+do_command (char **argv)
 {
   char *out, *err;
   int r;
-  int proc_ok, dev_ok, sys_ok;
+  int proc_ok, dev_ok, dev_pts_ok, sys_ok;
 
   /* We need a root filesystem mounted to do this. */
   NEED_ROOT (NULL);
@@ -53,11 +53,13 @@ do_command (char * const * const argv)
    * We deliberately allow these commands to fail silently, BUT
    * if a mount fails, don't unmount the corresponding mount.
    */
-  r = command (NULL, NULL, "mount", "--rbind", "/dev", "/sysroot/dev", NULL);
+  r = command (NULL, NULL, "mount", "--bind", "/dev", "/sysroot/dev", NULL);
   dev_ok = r != -1;
-  r = command (NULL, NULL, "mount", "--rbind", "/proc", "/sysroot/proc", NULL);
+  r = command (NULL, NULL, "mount", "--bind", "/dev/pts", "/sysroot/dev/pts", NULL);
+  dev_pts_ok = r != -1;
+  r = command (NULL, NULL, "mount", "--bind", "/proc", "/sysroot/proc", NULL);
   proc_ok = r != -1;
-  r = command (NULL, NULL, "mount", "--rbind", "/sys", "/sysroot/sys", NULL);
+  r = command (NULL, NULL, "mount", "--bind", "/sys", "/sysroot/sys", NULL);
   sys_ok = r != -1;
 
   CHROOT_IN;
@@ -66,6 +68,7 @@ do_command (char * const * const argv)
 
   if (sys_ok) command (NULL, NULL, "umount", "/sysroot/sys", NULL);
   if (proc_ok) command (NULL, NULL, "umount", "/sysroot/proc", NULL);
+  if (dev_pts_ok) command (NULL, NULL, "umount", "/sysroot/dev/pts", NULL);
   if (dev_ok) command (NULL, NULL, "umount", "/sysroot/dev", NULL);
 
   if (r == -1) {
@@ -81,7 +84,7 @@ do_command (char * const * const argv)
 }
 
 char **
-do_command_lines (char * const * const argv)
+do_command_lines (char **argv)
 {
   char *out;
   char **lines;
@@ -98,3 +101,19 @@ do_command_lines (char * const * const argv)
 
   return lines;                        /* Caller frees. */
 }
+
+char *
+do_sh (char *command)
+{
+  char *argv[] = { "/bin/sh", "-c", command, NULL };
+
+  return do_command (argv);
+}
+
+char **
+do_sh_lines (char *command)
+{
+  char *argv[] = { "/bin/sh", "-c", command, NULL };
+
+  return do_command_lines (argv);
+}