# Specification in the form of a command-line invocation:
-# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=gl byteswap c-ctype connect fsusage futimens getaddrinfo getline glob hash ignore-value manywarnings mkdtemp netdb openat perror pread readlink select sleep socket strchrnul strndup symlinkat sys_select sys_wait vasprintf warnings
+# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=gl byteswap c-ctype connect error fsusage futimens getaddrinfo getline glob hash ignore-value manywarnings mkdtemp netdb openat perror pread read-file readlink select sleep socket strchrnul strndup symlinkat sys_select sys_wait vasprintf warnings
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([])
openat
perror
pread
+ read-file
readlink
select
sleep
#include <string.h>
#include <fcntl.h>
+#include "read-file.h"
+
#include "../src/guestfs_protocol.h"
#include "daemon.h"
#include "actions.h"
+/* Redirect errors from the tar command to the error file, then
+ * provide functions for reading it in. We overwrite the file each
+ * time, and since it's small and stored on the appliance we don't
+ * bother to delete it.
+ */
+static const char *error_file = "/tmp/error";
+
+static char *
+read_error_file (void)
+{
+ size_t len;
+ char *str = read_file (error_file, &len);
+ if (str == NULL) {
+ str = strdup ("(no error)");
+ if (str == NULL) {
+ perror ("strdup");
+ exit (EXIT_FAILURE);
+ }
+ len = strlen (str);
+ }
+
+ /* Remove trailing \n character if any. */
+ if (len > 0 && str[len-1] == '\n')
+ str[--len] = '\0';
+
+ return str; /* caller frees */
+}
+
static int
write_cb (void *fd_ptr, const void *buf, size_t len)
{
char *cmd;
/* "tar -C /sysroot%s -xf -" but we have to quote the dir. */
- if (asprintf_nowarn (&cmd, "tar -C %R -%sxf -",
- dir, filter) == -1) {
+ if (asprintf_nowarn (&cmd, "tar -C %R -%sxf - 2> %s",
+ dir, filter, error_file) == -1) {
err = errno;
r = cancel_receive ();
errno = err;
r = receive_file (write_cb, &fd);
if (r == -1) { /* write error */
- if (cancel_receive () != -2)
- reply_with_error ("write error on directory: %s", dir);
+ if (cancel_receive () != -2) {
+ char *errstr = read_error_file ();
+ reply_with_error ("write error on directory: %s: %s", dir, errstr);
+ free (errstr);
+ }
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
if (r == -1) /* if r == 0, file transfer ended already */
r = cancel_receive ();
- if (r != -2)
- reply_with_error ("tar subcommand failed on directory: %s", dir);
+ if (r != -2) {
+ char *errstr = read_error_file ();
+ reply_with_error ("tar subcommand failed on directory: %s: %s",
+ dir, errstr);
+ free (errstr);
+ }
return -1;
}