X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fcommand.c;h=3f21807f3b8df74b1f1796dbbe6647fe111aac81;hp=1a9bebb634fa4b4b26865d22df59e901a0f045d0;hb=a7b73d4a1e09f12b2002083618056f0c823c1dcf;hpb=80e15757879c4cf21e0511c62e57c19efb4aab63 diff --git a/daemon/command.c b/daemon/command.c index 1a9bebb..3f21807 100644 --- a/daemon/command.c +++ b/daemon/command.c @@ -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 @@ -27,11 +27,11 @@ #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); +}