*
* 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
struct guestfs_message_header hdr;
struct timeval start_t, end_t;
int64_t start_us, end_us, elapsed_us;
struct guestfs_message_header hdr;
struct timeval start_t, end_t;
int64_t start_us, end_us, elapsed_us;
/* Most common errors are leaked memory and leaked file descriptors,
* so run this between each command:
*/
/* Most common errors are leaked memory and leaked file descriptors,
* so run this between each command:
*/
xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE);
xdr_uint32_t (&xdr, &len);
xdr_destroy (&xdr);
if (len > GUESTFS_MESSAGE_MAX) {
fprintf (stderr, "guestfsd: incoming message is too long (%u bytes)\n",
xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE);
xdr_uint32_t (&xdr, &len);
xdr_destroy (&xdr);
if (len > GUESTFS_MESSAGE_MAX) {
fprintf (stderr, "guestfsd: incoming message is too long (%u bytes)\n",
- printf ("%04x: ", i);
- for (j = i; j < MIN (i+16, len); ++j)
- printf ("%02x ", (unsigned char) buf[j]);
- for (; j < i+16; ++j)
- printf (" ");
- printf ("|");
- for (j = i; j < MIN (i+16, len); ++j)
- if (isprint (buf[j]))
- printf ("%c", buf[j]);
- else
- printf (".");
- for (; j < i+16; ++j)
- printf (" ");
- printf ("|\n");
+ printf ("%04zx: ", i);
+ for (j = i; j < MIN (i+16, len); ++j)
+ printf ("%02x ", (unsigned char) buf[j]);
+ for (; j < i+16; ++j)
+ printf (" ");
+ printf ("|");
+ for (j = i; j < MIN (i+16, len); ++j)
+ if (isprint (buf[j]))
+ printf ("%c", buf[j]);
+ else
+ printf (".");
+ for (; j < i+16; ++j)
+ printf (" ");
+ printf ("|\n");
end_us = (int64_t) end_t.tv_sec * 1000000 + end_t.tv_usec;
elapsed_us = end_us - start_us;
fprintf (stderr, "proc %d (%s) took %d.%02d seconds\n",
end_us = (int64_t) end_t.tv_sec * 1000000 + end_t.tv_usec;
elapsed_us = end_us - start_us;
fprintf (stderr, "proc %d (%s) took %d.%02d seconds\n",
- proc_nr,
- proc_nr >= 0 && proc_nr < GUESTFS_PROC_NR_PROCS
- ? function_names[proc_nr] : "UNKNOWN PROCEDURE",
- (int) (elapsed_us / 1000000),
- (int) ((elapsed_us / 10000) % 100));
+ proc_nr,
+ proc_nr >= 0 && proc_nr < GUESTFS_PROC_NR_PROCS
+ ? function_names[proc_nr] : "UNKNOWN PROCEDURE",
+ (int) (elapsed_us / 1000000),
+ (int) ((elapsed_us / 10000) % 100));
xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE);
xdr_uint32_t (&xdr, &len);
xdr_destroy (&xdr);
xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE);
xdr_uint32_t (&xdr, &len);
xdr_destroy (&xdr);
if (len > GUESTFS_MESSAGE_MAX) {
fprintf (stderr, "guestfsd: incoming message is too long (%u bytes)\n",
if (len > GUESTFS_MESSAGE_MAX) {
fprintf (stderr, "guestfsd: incoming message is too long (%u bytes)\n",
xdrmem_create (&xdr, buf, len, XDR_DECODE);
memset (&chunk, 0, sizeof chunk);
xdrmem_create (&xdr, buf, len, XDR_DECODE);
memset (&chunk, 0, sizeof chunk);
if (verbose)
printf ("receive_file: got chunk: cancel = %d, len = %d, buf = %p\n",
if (verbose)
printf ("receive_file: got chunk: cancel = %d, len = %d, buf = %p\n",
if (len > GUESTFS_MAX_CHUNK_SIZE) {
fprintf (stderr, "send_file_write: len (%d) > GUESTFS_MAX_CHUNK_SIZE (%d)\n",
if (len > GUESTFS_MAX_CHUNK_SIZE) {
fprintf (stderr, "send_file_write: len (%d) > GUESTFS_MAX_CHUNK_SIZE (%d)\n",
/* Read the message from the daemon. */
r = xread (sock, buf, sizeof buf);
/* Read the message from the daemon. */
r = xread (sock, buf, sizeof buf);
xdrmem_create (&xdr, buf, sizeof buf, XDR_DECODE);
xdr_uint32_t (&xdr, &flag);
xdrmem_create (&xdr, buf, sizeof buf, XDR_DECODE);
xdr_uint32_t (&xdr, &flag);
if (flag != GUESTFS_CANCEL_FLAG) {
fprintf (stderr, "check_for_library_cancellation: read 0x%x from library, expected 0x%x\n",
if (flag != GUESTFS_CANCEL_FLAG) {
fprintf (stderr, "check_for_library_cancellation: read 0x%x from library, expected 0x%x\n",
- (void) xwrite (sock, lenbuf, 4);
- (void) xwrite (sock, buf, len);
+ int err = (xwrite (sock, lenbuf, 4) == 0
+ && xwrite (sock, buf, len) == 0 ? 0 : -1);
+ if (err) {
+ fprintf (stderr, "send_chunk: write failed\n");
+ exit (1);
+ }