As a previous, incorrect attempt to fix RHBZ#576879 we tried to
prevent the daemon from sending an error reply if the daemon had
cancelled the transfer. This is wrong: the daemon should send an
error reply in these cases.
A simple test case is this:
guestfish -N fs -m /dev/sda1 upload big-file /
(This fails because the target "/" is a directory, not a file.)
Prior to this commit, libguestfs would hang instead of printing an
error. With this commit, libguestfs prints an error.
What is happening is:
(1) Library is uploading
a file (2) In the middle of the long
upload, daemon detects an error.
Daemon cancels.
(3) Library detects cancel,
sends cancel chunk, then waits
for the error reply from the
daemon. (4) Daemon is supposed to send
an error reply message.
Because step (4) wasn't happening, uploads that failed like this would
hang in the library (waiting for the error message, while the daemon
was waiting for the next request).
This also adds a regression test.
This temporarily breaks the "both ends cancel" case (RHBZ#
576879c5).
Therefore the test for that is disabled, and this is fixed in the next
patch in the series.
This partially reverts commit
dc706a639eec16084c0618baf7bfde00c6565f63.
int dev_ok, dev_pts_ok, proc_ok, selinux_ok, sys_ok;
/* We need a root filesystem mounted to do this. */
- NEED_ROOT (0, 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
/* daemon functions that receive files (FileIn) can call this
* to cancel incoming transfers (eg. if there is a local error).
- *
- * If and only if this function does NOT return -2, they MUST then
- * call reply_with_*
- * (see https://bugzilla.redhat.com/show_bug.cgi?id=576879#c5).
*/
extern int cancel_receive (void);
#define NEED_ROOT(cancel_stmt,fail_stmt) \
do { \
if (!is_root_mounted ()) { \
- if ((cancel_stmt) != -2) \
- reply_with_error ("%s: you must call 'mount' first to mount the root filesystem", __func__); \
+ cancel_stmt; \
+ reply_with_error ("%s: you must call 'mount' first to mount the root filesystem", __func__); \
fail_stmt; \
} \
} \
#define ABS_PATH(path,cancel_stmt,fail_stmt) \
do { \
if ((path)[0] != '/') { \
- if ((cancel_stmt) != -2) \
- reply_with_error ("%s: path must start with a / character", __func__); \
+ cancel_stmt; \
+ reply_with_error ("%s: path must start with a / character", __func__); \
fail_stmt; \
} \
} while (0)
#define RESOLVE_DEVICE(path,cancel_stmt,fail_stmt) \
do { \
if (STRNEQLEN ((path), "/dev/", 5)) { \
- if ((cancel_stmt) != -2) \
- reply_with_error ("%s: %s: expecting a device name", __func__, (path)); \
+ cancel_stmt; \
+ reply_with_error ("%s: %s: expecting a device name", __func__, (path)); \
fail_stmt; \
} \
if (is_root_device (path)) \
reply_with_error ("%s: %s: device not found", __func__, path); \
if (device_name_translation ((path)) == -1) { \
int err = errno; \
- int r = cancel_stmt; \
+ cancel_stmt; \
errno = err; \
- if (r != -2) \
- reply_with_perror ("%s: %s", __func__, path); \
+ reply_with_perror ("%s: %s", __func__, path); \
fail_stmt; \
} \
} while (0)
int r;
char *out, *err;
- NEED_ROOT (0, return NULL);
+ NEED_ROOT (, return NULL);
r = command (&out, &err, "df", NULL);
if (r == -1) {
int r;
char *out, *err;
- NEED_ROOT (0, return NULL);
+ NEED_ROOT (, return NULL);
r = command (&out, &err, "df", "-h", NULL);
if (r == -1) {
#ifdef HAVE_SYS_INOTIFY_H
FILE *fp;
- NEED_ROOT (0, return -1);
+ NEED_ROOT (, return -1);
if (max_events < 0) {
reply_with_error ("max_events < 0");
char *error;
struct stat statbuf;
- ABS_PATH (mountpoint, 0, return -1);
+ ABS_PATH (mountpoint, , return -1);
mp = sysroot_path (mountpoint);
if (!mp) {
}
if (is_dev)
- RESOLVE_DEVICE (buf, 0, { free (buf); return -1; });
+ RESOLVE_DEVICE (buf, , { free (buf); return -1; });
r = command (NULL, &err, "umount", buf, NULL);
free (buf);
int r;
/* NEED_ROOT (return -1); - we don't want this test for this call. */
- ABS_PATH (path, 0, return -1);
+ ABS_PATH (path, , return -1);
CHROOT_IN;
r = mkdir (path, 0777);
int r;
/* NEED_ROOT (return -1); - we don't want this test for this call. */
- ABS_PATH (path, 0, return -1);
+ ABS_PATH (path, , return -1);
CHROOT_IN;
r = rmdir (path);
err = errno;
r = cancel_receive ();
errno = err;
- if (r != -2) reply_with_perror ("asprintf");
+ reply_with_perror ("asprintf");
return -1;
}
err = errno;
r = cancel_receive ();
errno = err;
- if (r != -2) reply_with_perror ("%s", cmd);
+ reply_with_perror ("%s", cmd);
free (cmd);
return -1;
}
r = receive_file (write_cb, &fd);
if (r == -1) { /* write error */
- if (cancel_receive () != -2) {
- char *errstr = read_error_file ();
- reply_with_error ("write error on directory: %s: %s", dir, errstr);
- free (errstr);
- }
+ cancel_receive ();
+ 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) {
- char *errstr = read_error_file ();
- reply_with_error ("tar subcommand failed on directory: %s: %s",
- dir, errstr);
- free (errstr);
- }
+ char *errstr = read_error_file ();
+ reply_with_error ("tar subcommand failed on directory: %s: %s",
+ dir, errstr);
+ free (errstr);
return -1;
}
err = errno;
r = cancel_receive ();
errno = err;
- if (r != -2) reply_with_perror ("%s", filename);
+ reply_with_perror ("%s", filename);
return -1;
}
err = errno;
r = cancel_receive ();
errno = err;
- if (r != -2) reply_with_perror ("lseek: %s", filename);
+ reply_with_perror ("lseek: %s", filename);
return -1;
}
}
err = errno;
r = cancel_receive ();
errno = err;
- if (r != -2) reply_with_error ("write error: %s", filename);
+ reply_with_error ("write error: %s", filename);
close (data.fd);
return -1;
}
if (r == -1) /* if r == 0, file transfer ended already */
r = cancel_receive ();
errno = err;
- if (r != -2)
- reply_with_perror ("close: %s", filename);
+ reply_with_perror ("close: %s", filename);
return -1;
}
| Pathname n ->
pr_args n;
pr " ABS_PATH (%s, %s, goto done);\n"
- n (if is_filein then "cancel_receive ()" else "0");
+ n (if is_filein then "cancel_receive ()" else "");
| Device n ->
pr_args n;
pr " RESOLVE_DEVICE (%s, %s, goto done);\n"
- n (if is_filein then "cancel_receive ()" else "0");
+ n (if is_filein then "cancel_receive ()" else "");
| Dev_or_Path n ->
pr_args n;
pr " REQUIRE_ROOT_OR_RESOLVE_DEVICE (%s, %s, goto done);\n"
- n (if is_filein then "cancel_receive ()" else "0");
+ n (if is_filein then "cancel_receive ()" else "");
| String n | Key n -> pr_args n
| OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n
| StringList n ->
pr " size_t i;\n";
pr " for (i = 0; %s[i] != NULL; ++i)\n" n;
pr " RESOLVE_DEVICE (%s[i], %s, goto done);\n" n
- (if is_filein then "cancel_receive ()" else "0");
+ (if is_filein then "cancel_receive ()" else "");
pr " }\n";
| Bool n -> pr " %s = args.%s;\n" n n
| Int n -> pr " %s = args.%s;\n" n n
(* Emit NEED_ROOT just once, even when there are two or
more Pathname args *)
pr " NEED_ROOT (%s, goto done);\n"
- (if is_filein then "cancel_receive ()" else "0");
+ (if is_filein then "cancel_receive ()" else "");
);
(* Don't want to call the impl with any FileIn or FileOut
rhbz503169c10.sh \
rhbz503169c13.sh \
rhbz557655.sh \
- rhbz576879c0.sh \
- rhbz576879c5.sh \
+ rhbz576879.sh \
rhbz578407.sh \
rhbz580246.sh \
test-add-domain.sh \
test-read_file.sh \
test-remote.sh \
test-reopen.sh \
- test-stringlist.sh
+ test-stringlist.sh \
+ test-upload-to-dir.sh
SKIPPED_TESTS = \
test-bootbootboot.sh
FAILING_TESTS = \
+ test-both-ends-cancel.sh \
test-qemudie-launchfail.sh
random_val := $(shell awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)
rm -f test1.img
../fish/guestfish -N disk <<EOF
--upload $srcdir/rhbz576879c0.sh /test.sh
+-upload $srcdir/rhbz576879.sh /test.sh
# Shouldn't lose synchronization, so next command should work:
ping-daemon
EOF
--- /dev/null
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# If you used the guestfish command 'upload' and accidentally set the
+# target to a directory instead of the full filename, then previously
+# libguestfs would hang. It should return an error instead.
+
+set -e
+
+rm -f test1.img test.out
+
+if ../fish/guestfish -N fs -m /dev/sda1 upload ../images/test.iso / 2>test.out
+then
+ echo "$0: expecting guestfish to return an error"
+ exit 1
+fi
+
+if ! grep -q "upload: /: Is a directory" test.out; then
+ echo "$0: unexpected error message from guestfish"
+ cat test.out
+ exit 1
+fi
+
+rm -f test1.img test.out