X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fcommand.c;h=ef2369576bf1f5a6ea04af99509a5d645b5e13be;hp=f7a6dcf6d805df431b67e23bf0822e36e9ddfd04;hb=7f16c346bbeba2f2fe3c31ccb85158178a284d84;hpb=6bda071b5cd8393b37653687027c4ae6c6cf3804 diff --git a/daemon/command.c b/daemon/command.c index f7a6dcf..ef23695 100644 --- a/daemon/command.c +++ b/daemon/command.c @@ -22,12 +22,20 @@ #include #include -#include "../src/guestfs_protocol.h" +#include "guestfs_protocol.h" #include "daemon.h" #include "actions.h" +#include "ignore-value.h" + +static inline void +umount_ignore_fail (const char *path) +{ + ignore_value (command (NULL, NULL, "umount", path, NULL)); +} + char * -do_command (char **argv) +do_command (char *const *argv) { char *out, *err; int r; @@ -36,14 +44,14 @@ do_command (char **argv) int dev_ok, dev_pts_ok, proc_ok, selinux_ok, sys_ok; /* We need a root filesystem mounted to do this. */ - NEED_ROOT (return NULL); + NEED_ROOT (, return NULL); /* Conveniently, argv is already a NULL-terminated argv-style array * of parameters, so we can pass it straight in to our internal * commandv. We just have to check the list is non-empty. */ if (argv[0] == NULL) { - reply_with_error ("command: passed an empty list"); + reply_with_error ("passed an empty list"); return NULL; } @@ -85,14 +93,14 @@ do_command (char **argv) sys_ok = r != -1; CHROOT_IN; - r = commandv (&out, &err, argv); + r = commandv (&out, &err, (const char * const *) argv); CHROOT_OUT; - if (sys_ok) command (NULL, NULL, "umount", sysroot_sys, NULL); - if (selinux_ok) command (NULL, NULL, "umount", sysroot_selinux, 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) umount_ignore_fail (sysroot_sys); + if (selinux_ok) umount_ignore_fail (sysroot_selinux); + if (proc_ok) umount_ignore_fail (sysroot_proc); + if (dev_pts_ok) umount_ignore_fail (sysroot_dev_pts); + if (dev_ok) umount_ignore_fail (sysroot_dev); free (sysroot_dev); free (sysroot_dev_pts); @@ -113,7 +121,7 @@ do_command (char **argv) } char ** -do_command_lines (char **argv) +do_command_lines (char *const *argv) { char *out; char **lines; @@ -132,17 +140,17 @@ do_command_lines (char **argv) } char * -do_sh (char *command) +do_sh (const char *cmd) { - char *argv[] = { "/bin/sh", "-c", command, NULL }; + const char *argv[] = { "/bin/sh", "-c", cmd, NULL }; - return do_command (argv); + return do_command ((char **) argv); } char ** -do_sh_lines (char *command) +do_sh_lines (const char *cmd) { - char *argv[] = { "/bin/sh", "-c", command, NULL }; + const char *argv[] = { "/bin/sh", "-c", cmd, NULL }; - return do_command_lines (argv); + return do_command_lines ((char **) argv); }