X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fchecksum.c;h=7967f0c0c6b602043ce465e3485439d67efff5c8;hp=f7e2d125ec6bf7fce3181e5e973813d6f88b7e18;hb=2729421d176e1194537b499911a5eeb5e32a8b09;hpb=41ee105aabaf1e9a7efc437b87d9536d3dc14a75 diff --git a/daemon/checksum.c b/daemon/checksum.c index f7e2d12..7967f0c 100644 --- a/daemon/checksum.c +++ b/daemon/checksum.c @@ -22,9 +22,10 @@ #include #include #include +#include #include -#include "../src/guestfs_protocol.h" +#include "guestfs_protocol.h" #include "daemon.h" #include "actions.h" @@ -52,18 +53,19 @@ program_of_csum (const char *csumtype) } static char * -checksum (const char *csumtype, const char *path) +checksum (const char *csumtype, int fd) { const char *program; char *out, *err; - int r; + int flags, r; int len; program = program_of_csum (csumtype); if (program == NULL) return NULL; - r = command (&out, &err, program, path, NULL); + flags = COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN | fd; + r = commandf (&out, &err, flags, program, NULL); if (r == -1) { reply_with_error ("%s: %s", program, err); free (out); @@ -83,22 +85,32 @@ checksum (const char *csumtype, const char *path) char * do_checksum (const char *csumtype, const char *path) { - /* Make the path relative to /sysroot. */ - char *buf = sysroot_path (path); - if (!buf) { - reply_with_perror ("malloc"); + int fd; + + CHROOT_IN; + fd = open (path, O_RDONLY); + CHROOT_OUT; + + if (fd == -1) { + reply_with_perror ("%s", path); return NULL; } - char *r = checksum (csumtype, buf); - free (buf); - return r; + return checksum (csumtype, fd); } char * do_checksum_device (const char *csumtype, const char *device) { - return checksum (csumtype, device); + int fd; + + fd = open (device, O_RDONLY); + if (fd == -1) { + reply_with_perror ("%s", device); + return NULL; + } + + return checksum (csumtype, fd); } /* Has one FileOut parameter. */