X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fcommand.c;h=03992555b4a99f1fb1cd378faceea081d0f4bf84;hp=3254de58462b23fe83a3cf1dc6970008711a6be0;hb=1a5755dbbff0fa4d87984cb7d67cb8239fd71a84;hpb=887290e949d54c6ac4c9b787231e588f84f2367c diff --git a/daemon/command.c b/daemon/command.c index 3254de5..0399255 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 @@ -31,6 +31,7 @@ do_command (char **argv) { char *out, *err; int r; + char *sysroot_proc, *sysroot_dev, *sysroot_dev_pts, *sysroot_sys; int proc_ok, dev_ok, dev_pts_ok, sys_ok; /* We need a root filesystem mounted to do this. */ @@ -53,23 +54,33 @@ do_command (char **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", "--bind", "/dev", "/sysroot/dev", NULL); + sysroot_dev = sysroot_path ("/dev"); + sysroot_dev_pts = sysroot_path ("/dev/pts"); + sysroot_proc = sysroot_path ("/proc"); + sysroot_sys = sysroot_path ("/sys"); + + r = command (NULL, NULL, "mount", "--bind", "/dev", sysroot_dev, NULL); dev_ok = r != -1; - r = command (NULL, NULL, "mount", "--bind", "/dev/pts", "/sysroot/dev/pts", 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); + r = command (NULL, NULL, "mount", "--bind", "/proc", sysroot_proc, NULL); proc_ok = r != -1; - r = command (NULL, NULL, "mount", "--bind", "/sys", "/sysroot/sys", NULL); + r = command (NULL, NULL, "mount", "--bind", "/sys", sysroot_sys, NULL); sys_ok = r != -1; CHROOT_IN; r = commandv (&out, &err, argv); CHROOT_OUT; - 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 (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); + + free (sysroot_dev); + free (sysroot_dev_pts); + free (sysroot_proc); + free (sysroot_sys); if (r == -1) { reply_with_error ("%s", err); @@ -101,3 +112,19 @@ do_command_lines (char **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); +}