git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
resize: Refactor the code for creating target partitions.
[libguestfs.git]
/
daemon
/
checksum.c
diff --git
a/daemon/checksum.c
b/daemon/checksum.c
index
f7e2d12
..
0bd9623
100644
(file)
--- a/
daemon/checksum.c
+++ b/
daemon/checksum.c
@@
-1,5
+1,5
@@
/* libguestfs - the guestfsd daemon
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009
-2011
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
*
* 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
@@
-22,9
+22,10
@@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#include <sys/stat.h>
#include <sys/stat.h>
-#include "
../src/
guestfs_protocol.h"
+#include "guestfs_protocol.h"
#include "daemon.h"
#include "actions.h"
#include "daemon.h"
#include "actions.h"
@@
-52,19
+53,25
@@
program_of_csum (const char *csumtype)
}
static char *
}
static char *
-checksum (const char *csumtype,
const char *path
)
+checksum (const char *csumtype,
int fd
)
{
const char *program;
char *out, *err;
{
const char *program;
char *out, *err;
- int r;
+ int
flags,
r;
int len;
program = program_of_csum (csumtype);
int len;
program = program_of_csum (csumtype);
- if (program == NULL)
+ if (program == NULL) {
+ close (fd);
return NULL;
return NULL;
+ }
- r = command (&out, &err, program, path, NULL);
+ pulse_mode_start ();
+
+ flags = COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN | fd;
+ r = commandf (&out, &err, flags, program, NULL);
if (r == -1) {
if (r == -1) {
+ pulse_mode_cancel ();
reply_with_error ("%s: %s", program, err);
free (out);
free (err);
reply_with_error ("%s: %s", program, err);
free (out);
free (err);
@@
-77,28
+84,40
@@
checksum (const char *csumtype, const char *path)
len = strcspn (out, " \t\n");
out[len] = '\0';
len = strcspn (out, " \t\n");
out[len] = '\0';
+ pulse_mode_end ();
+
return out; /* Caller frees. */
}
char *
do_checksum (const char *csumtype, const char *path)
{
return out; /* Caller frees. */
}
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;
}
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)
{
}
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. */
}
/* Has one FileOut parameter. */