daemon: Remove some less useful debugging messages.
[libguestfs.git] / daemon / proto.c
1 /* libguestfs - the guestfsd daemon
2  * Copyright (C) 2009-2011 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <config.h>
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <signal.h>
26 #include <inttypes.h>
27 #include <unistd.h>
28 #include <errno.h>
29 #include <sys/param.h>          /* defines MIN */
30 #include <sys/select.h>
31 #include <sys/time.h>
32 #include <rpc/types.h>
33 #include <rpc/xdr.h>
34
35 #ifdef HAVE_WINDOWS_H
36 #include <windows.h>
37 #endif
38
39 #include "c-ctype.h"
40 #include "ignore-value.h"
41
42 #include "daemon.h"
43 #include "guestfs_protocol.h"
44 #include "errnostring.h"
45
46 /* The message currently being processed. */
47 int proc_nr;
48 int serial;
49
50 /* Hint for implementing progress messages for uploaded/incoming data.
51  * The caller sets this to a value > 0 if it knows or can estimate how
52  * much data will be sent (this is not always known, eg. for uploads
53  * coming from a pipe).  If this is known then we can emit progress
54  * messages as we write the data.
55  */
56 uint64_t progress_hint;
57
58 /* Optional arguments bitmask.  Caller sets this to indicate which
59  * optional arguments in the guestfs_<foo>_args structure are
60  * meaningful.  Optional arguments not covered by the bitmask are set
61  * to arbitrary values and the daemon should ignore them.  If the
62  * bitmask has bits set that the daemon doesn't understand, then the
63  * whole call is rejected early in processing.
64  */
65 uint64_t optargs_bitmask;
66
67 /* Time at which we received the current request. */
68 static struct timeval start_t;
69
70 /* Time at which the last progress notification was sent. */
71 static struct timeval last_progress_t;
72
73 /* Counts the number of progress notifications sent during this call. */
74 static int count_progress;
75
76 /* The daemon communications socket. */
77 static int sock;
78
79 void
80 main_loop (int _sock)
81 {
82   XDR xdr;
83   char *buf;
84   char lenbuf[4];
85   uint32_t len;
86   struct guestfs_message_header hdr;
87
88   sock = _sock;
89
90   for (;;) {
91     /* Read the length word. */
92     if (xread (sock, lenbuf, 4) == -1)
93       exit (EXIT_FAILURE);
94
95     xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE);
96     xdr_u_int (&xdr, &len);
97     xdr_destroy (&xdr);
98
99     if (verbose)
100       fprintf (stderr,
101                "guestfsd: main_loop: new request, len 0x%" PRIx32 "\n",
102                len);
103
104     if (len > GUESTFS_MESSAGE_MAX) {
105       fprintf (stderr, "guestfsd: incoming message is too long (%u bytes)\n",
106                len);
107       exit (EXIT_FAILURE);
108     }
109
110     buf = malloc (len);
111     if (!buf) {
112       reply_with_perror ("malloc");
113       continue;
114     }
115
116     if (xread (sock, buf, len) == -1)
117       exit (EXIT_FAILURE);
118
119 #ifdef ENABLE_PACKET_DUMP
120     if (verbose) {
121       size_t i, j;
122
123       for (i = 0; i < len; i += 16) {
124         printf ("%04zx: ", i);
125         for (j = i; j < MIN (i+16, len); ++j)
126           printf ("%02x ", (unsigned char) buf[j]);
127         for (; j < i+16; ++j)
128           printf ("   ");
129         printf ("|");
130         for (j = i; j < MIN (i+16, len); ++j)
131           if (c_isprint (buf[j]))
132             printf ("%c", buf[j]);
133           else
134             printf (".");
135         for (; j < i+16; ++j)
136           printf (" ");
137         printf ("|\n");
138       }
139     }
140 #endif
141
142     gettimeofday (&start_t, NULL);
143     last_progress_t = start_t;
144     count_progress = 0;
145
146     /* Decode the message header. */
147     xdrmem_create (&xdr, buf, len, XDR_DECODE);
148     if (!xdr_guestfs_message_header (&xdr, &hdr)) {
149       fprintf (stderr, "guestfsd: could not decode message header\n");
150       exit (EXIT_FAILURE);
151     }
152
153     /* Check the version etc. */
154     if (hdr.prog != GUESTFS_PROGRAM) {
155       reply_with_error ("wrong program (%d)", hdr.prog);
156       goto cont;
157     }
158     if (hdr.vers != GUESTFS_PROTOCOL_VERSION) {
159       reply_with_error ("wrong protocol version (%d)", hdr.vers);
160       goto cont;
161     }
162     if (hdr.direction != GUESTFS_DIRECTION_CALL) {
163       reply_with_error ("unexpected message direction (%d)", hdr.direction);
164       goto cont;
165     }
166     if (hdr.status != GUESTFS_STATUS_OK) {
167       reply_with_error ("unexpected message status (%d)", hdr.status);
168       goto cont;
169     }
170
171     proc_nr = hdr.proc;
172     serial = hdr.serial;
173     progress_hint = hdr.progress_hint;
174     optargs_bitmask = hdr.optargs_bitmask;
175
176     /* Clear errors before we call the stub functions.  This is just
177      * to ensure that we can accurately report errors in cases where
178      * error handling paths don't set errno correctly.
179      */
180     errno = 0;
181 #ifdef WIN32
182     SetLastError (0);
183     WSASetLastError (0);
184 #endif
185
186     /* Now start to process this message. */
187     dispatch_incoming_message (&xdr);
188     /* Note that dispatch_incoming_message will also send a reply. */
189
190     /* In verbose mode, display the time taken to run each command. */
191     if (verbose) {
192       struct timeval end_t;
193       gettimeofday (&end_t, NULL);
194
195       int64_t start_us, end_us, elapsed_us;
196       start_us = (int64_t) start_t.tv_sec * 1000000 + start_t.tv_usec;
197       end_us = (int64_t) end_t.tv_sec * 1000000 + end_t.tv_usec;
198       elapsed_us = end_us - start_us;
199
200       fprintf (stderr,
201                "guestfsd: main_loop: proc %d (%s) took %d.%02d seconds\n",
202                proc_nr,
203                proc_nr >= 0 && proc_nr < GUESTFS_PROC_NR_PROCS
204                ? function_names[proc_nr] : "UNKNOWN PROCEDURE",
205                (int) (elapsed_us / 1000000),
206                (int) ((elapsed_us / 10000) % 100));
207     }
208
209   cont:
210     xdr_destroy (&xdr);
211     free (buf);
212   }
213 }
214
215 static void send_error (int errnum, const char *msg);
216
217 void
218 reply_with_error (const char *fs, ...)
219 {
220   char err[GUESTFS_ERROR_LEN];
221   va_list args;
222
223   va_start (args, fs);
224   vsnprintf (err, sizeof err, fs, args);
225   va_end (args);
226
227   send_error (0, err);
228 }
229
230 void
231 reply_with_perror_errno (int err, const char *fs, ...)
232 {
233   char buf1[GUESTFS_ERROR_LEN];
234   char buf2[GUESTFS_ERROR_LEN];
235   va_list args;
236
237   va_start (args, fs);
238   vsnprintf (buf1, sizeof buf1, fs, args);
239   va_end (args);
240
241   snprintf (buf2, sizeof buf2, "%s: %s", buf1, strerror (err));
242
243   send_error (err, buf2);
244 }
245
246 static void
247 send_error (int errnum, const char *msg)
248 {
249   XDR xdr;
250   char buf[GUESTFS_ERROR_LEN + 200];
251   char lenbuf[4];
252   struct guestfs_message_header hdr;
253   struct guestfs_message_error err;
254   unsigned len;
255
256   fprintf (stderr, "guestfsd: error: %s\n", msg);
257
258   xdrmem_create (&xdr, buf, sizeof buf, XDR_ENCODE);
259
260   hdr.prog = GUESTFS_PROGRAM;
261   hdr.vers = GUESTFS_PROTOCOL_VERSION;
262   hdr.direction = GUESTFS_DIRECTION_REPLY;
263   hdr.status = GUESTFS_STATUS_ERROR;
264   hdr.proc = proc_nr;
265   hdr.serial = serial;
266
267   if (!xdr_guestfs_message_header (&xdr, &hdr)) {
268     fprintf (stderr, "guestfsd: failed to encode error message header\n");
269     exit (EXIT_FAILURE);
270   }
271
272   /* These strings are not going to be freed.  We just cast them
273    * to (char *) because they are defined that way in the XDR structs.
274    */
275   err.errno_string =
276     (char *) (errnum > 0 ? guestfs___errno_to_string (errnum) : "");
277   err.error_message = (char *) msg;
278
279   if (!xdr_guestfs_message_error (&xdr, &err)) {
280     fprintf (stderr, "guestfsd: failed to encode error message body\n");
281     exit (EXIT_FAILURE);
282   }
283
284   len = xdr_getpos (&xdr);
285   xdr_destroy (&xdr);
286
287   xdrmem_create (&xdr, lenbuf, 4, XDR_ENCODE);
288   xdr_u_int (&xdr, &len);
289   xdr_destroy (&xdr);
290
291   if (xwrite (sock, lenbuf, 4) == -1) {
292     fprintf (stderr, "guestfsd: xwrite failed\n");
293     exit (EXIT_FAILURE);
294   }
295   if (xwrite (sock, buf, len) == -1) {
296     fprintf (stderr, "guestfsd: xwrite failed\n");
297     exit (EXIT_FAILURE);
298   }
299 }
300
301 void
302 reply (xdrproc_t xdrp, char *ret)
303 {
304   XDR xdr;
305   char buf[GUESTFS_MESSAGE_MAX];
306   char lenbuf[4];
307   struct guestfs_message_header hdr;
308   unsigned len;
309
310   xdrmem_create (&xdr, buf, sizeof buf, XDR_ENCODE);
311
312   hdr.prog = GUESTFS_PROGRAM;
313   hdr.vers = GUESTFS_PROTOCOL_VERSION;
314   hdr.direction = GUESTFS_DIRECTION_REPLY;
315   hdr.status = GUESTFS_STATUS_OK;
316   hdr.proc = proc_nr;
317   hdr.serial = serial;
318
319   if (!xdr_guestfs_message_header (&xdr, &hdr)) {
320     fprintf (stderr, "guestfsd: failed to encode reply header\n");
321     exit (EXIT_FAILURE);
322   }
323
324   if (xdrp) {
325     /* This can fail if the reply body is too large, for example
326      * if it exceeds the maximum message size.  In that case
327      * we want to return an error message instead. (RHBZ#509597).
328      */
329     if (!(*xdrp) (&xdr, ret)) {
330       reply_with_error ("guestfsd: failed to encode reply body\n(maybe the reply exceeds the maximum message size in the protocol?)");
331       xdr_destroy (&xdr);
332       return;
333     }
334   }
335
336   len = xdr_getpos (&xdr);
337   xdr_destroy (&xdr);
338
339   xdrmem_create (&xdr, lenbuf, 4, XDR_ENCODE);
340   xdr_u_int (&xdr, &len);
341   xdr_destroy (&xdr);
342
343   if (xwrite (sock, lenbuf, 4) == -1) {
344     fprintf (stderr, "guestfsd: xwrite failed\n");
345     exit (EXIT_FAILURE);
346   }
347   if (xwrite (sock, buf, len) == -1) {
348     fprintf (stderr, "guestfsd: xwrite failed\n");
349     exit (EXIT_FAILURE);
350   }
351 }
352
353 /* Receive file chunks, repeatedly calling 'cb'. */
354 int
355 receive_file (receive_cb cb, void *opaque)
356 {
357   guestfs_chunk chunk;
358   char lenbuf[4];
359   char *buf;
360   XDR xdr;
361   int r;
362   uint32_t len;
363
364   for (;;) {
365     if (verbose)
366       fprintf (stderr, "guestfsd: receive_file: reading length word\n");
367
368     /* Read the length word. */
369     if (xread (sock, lenbuf, 4) == -1)
370       exit (EXIT_FAILURE);
371
372     xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE);
373     xdr_u_int (&xdr, &len);
374     xdr_destroy (&xdr);
375
376     if (len == GUESTFS_CANCEL_FLAG)
377       continue;                 /* Just ignore it. */
378
379     if (len > GUESTFS_MESSAGE_MAX) {
380       fprintf (stderr, "guestfsd: incoming message is too long (%u bytes)\n",
381                len);
382       exit (EXIT_FAILURE);
383     }
384
385     buf = malloc (len);
386     if (!buf) {
387       perror ("malloc");
388       return -1;
389     }
390
391     if (xread (sock, buf, len) == -1)
392       exit (EXIT_FAILURE);
393
394     xdrmem_create (&xdr, buf, len, XDR_DECODE);
395     memset (&chunk, 0, sizeof chunk);
396     if (!xdr_guestfs_chunk (&xdr, &chunk)) {
397       xdr_destroy (&xdr);
398       free (buf);
399       return -1;
400     }
401     xdr_destroy (&xdr);
402     free (buf);
403
404     if (verbose)
405       fprintf (stderr,
406                "guestfsd: receive_file: got chunk: cancel = 0x%x, len = %d, buf = %p\n",
407                chunk.cancel, chunk.data.data_len, chunk.data.data_val);
408
409     if (chunk.cancel != 0 && chunk.cancel != 1) {
410       fprintf (stderr,
411                "guestfsd: receive_file: chunk.cancel != [0|1] ... "
412                "continuing even though we have probably lost synchronization with the library\n");
413       return -1;
414     }
415
416     if (chunk.cancel) {
417       if (verbose)
418         fprintf (stderr,
419           "guestfsd: receive_file: received cancellation from library\n");
420       xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
421       return -2;
422     }
423     if (chunk.data.data_len == 0) {
424       if (verbose)
425         fprintf (stderr,
426                  "guestfsd: receive_file: end of file, leaving function\n");
427       xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
428       return 0;                 /* end of file */
429     }
430
431     /* Note that the callback can generate progress messages. */
432     if (cb)
433       r = cb (opaque, chunk.data.data_val, chunk.data.data_len);
434     else
435       r = 0;
436
437     xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
438     if (r == -1) {              /* write error */
439       if (verbose)
440         fprintf (stderr, "guestfsd: receive_file: write error\n");
441       return -1;
442     }
443   }
444 }
445
446 /* Send a cancellation flag back to the library. */
447 int
448 cancel_receive (void)
449 {
450   XDR xdr;
451   char fbuf[4];
452   uint32_t flag = GUESTFS_CANCEL_FLAG;
453
454   xdrmem_create (&xdr, fbuf, sizeof fbuf, XDR_ENCODE);
455   xdr_u_int (&xdr, &flag);
456   xdr_destroy (&xdr);
457
458   if (xwrite (sock, fbuf, sizeof fbuf) == -1) {
459     perror ("write to socket");
460     return -1;
461   }
462
463   /* Keep receiving chunks and discarding, until library sees cancel. */
464   return receive_file (NULL, NULL);
465 }
466
467 static int check_for_library_cancellation (void);
468 static int send_chunk (const guestfs_chunk *);
469
470 /* Also check if the library sends us a cancellation message. */
471 int
472 send_file_write (const void *buf, int len)
473 {
474   guestfs_chunk chunk;
475   int cancel;
476
477   if (len > GUESTFS_MAX_CHUNK_SIZE) {
478     fprintf (stderr, "guestfsd: send_file_write: len (%d) > GUESTFS_MAX_CHUNK_SIZE (%d)\n",
479              len, GUESTFS_MAX_CHUNK_SIZE);
480     return -1;
481   }
482
483   cancel = check_for_library_cancellation ();
484
485   if (cancel) {
486     chunk.cancel = 1;
487     chunk.data.data_len = 0;
488     chunk.data.data_val = NULL;
489   } else {
490     chunk.cancel = 0;
491     chunk.data.data_len = len;
492     chunk.data.data_val = (char *) buf;
493   }
494
495   if (send_chunk (&chunk) == -1)
496     return -1;
497
498   if (cancel) return -2;
499   return 0;
500 }
501
502 static int
503 check_for_library_cancellation (void)
504 {
505   fd_set rset;
506   struct timeval tv;
507   int r;
508   char buf[4];
509   uint32_t flag;
510   XDR xdr;
511
512   FD_ZERO (&rset);
513   FD_SET (sock, &rset);
514   tv.tv_sec = 0;
515   tv.tv_usec = 0;
516   r = select (sock+1, &rset, NULL, NULL, &tv);
517   if (r == -1) {
518     perror ("select");
519     return 0;
520   }
521   if (r == 0)
522     return 0;
523
524   /* Read the message from the daemon. */
525   r = xread (sock, buf, sizeof buf);
526   if (r == -1)
527     return 0;
528
529   xdrmem_create (&xdr, buf, sizeof buf, XDR_DECODE);
530   xdr_u_int (&xdr, &flag);
531   xdr_destroy (&xdr);
532
533   if (flag != GUESTFS_CANCEL_FLAG) {
534     fprintf (stderr, "guestfsd: check_for_library_cancellation: read 0x%x from library, expected 0x%x\n",
535              flag, GUESTFS_CANCEL_FLAG);
536     return 0;
537   }
538
539   return 1;
540 }
541
542 int
543 send_file_end (int cancel)
544 {
545   guestfs_chunk chunk;
546
547   chunk.cancel = cancel;
548   chunk.data.data_len = 0;
549   chunk.data.data_val = NULL;
550   return send_chunk (&chunk);
551 }
552
553 static int
554 send_chunk (const guestfs_chunk *chunk)
555 {
556   char buf[GUESTFS_MAX_CHUNK_SIZE + 48];
557   char lenbuf[4];
558   XDR xdr;
559   uint32_t len;
560
561   xdrmem_create (&xdr, buf, sizeof buf, XDR_ENCODE);
562   if (!xdr_guestfs_chunk (&xdr, (guestfs_chunk *) chunk)) {
563     fprintf (stderr, "guestfsd: send_chunk: failed to encode chunk\n");
564     xdr_destroy (&xdr);
565     return -1;
566   }
567
568   len = xdr_getpos (&xdr);
569   xdr_destroy (&xdr);
570
571   xdrmem_create (&xdr, lenbuf, 4, XDR_ENCODE);
572   xdr_u_int (&xdr, &len);
573   xdr_destroy (&xdr);
574
575   int err = (xwrite (sock, lenbuf, 4) == 0
576              && xwrite (sock, buf, len) == 0 ? 0 : -1);
577   if (err) {
578     fprintf (stderr, "guestfsd: send_chunk: write failed\n");
579     exit (EXIT_FAILURE);
580   }
581
582   return err;
583 }
584
585 /* Initial delay before sending notification messages, and
586  * the period at which we send them thereafter.  These times
587  * are in microseconds.
588  */
589 #define NOTIFICATION_INITIAL_DELAY 2000000
590 #define NOTIFICATION_PERIOD         333333
591
592 void
593 notify_progress (uint64_t position, uint64_t total)
594 {
595   struct timeval now_t;
596   gettimeofday (&now_t, NULL);
597
598   /* Always send a notification at 100%.  This simplifies callers by
599    * allowing them to 'finish' the progress bar at 100% without
600    * needing special code.
601    */
602   if (count_progress > 0 && position == total)
603     goto send;
604
605   /* Calculate time in microseconds since the last progress message
606    * was sent out (or since the start of the call).
607    */
608   int64_t last_us, now_us, elapsed_us;
609   last_us =
610     (int64_t) last_progress_t.tv_sec * 1000000 + last_progress_t.tv_usec;
611   now_us = (int64_t) now_t.tv_sec * 1000000 + now_t.tv_usec;
612   elapsed_us = now_us - last_us;
613
614   /* Rate limit. */
615   if ((count_progress == 0 && elapsed_us < NOTIFICATION_INITIAL_DELAY) ||
616       (count_progress > 0 && elapsed_us < NOTIFICATION_PERIOD))
617     return;
618
619  send:
620   /* We're going to send a message now ... */
621   count_progress++;
622   last_progress_t = now_t;
623
624   /* Send the header word. */
625   XDR xdr;
626   char buf[128];
627   uint32_t i = GUESTFS_PROGRESS_FLAG;
628   size_t len;
629   xdrmem_create (&xdr, buf, 4, XDR_ENCODE);
630   xdr_u_int (&xdr, &i);
631   xdr_destroy (&xdr);
632
633   if (xwrite (sock, buf, 4) == -1) {
634     fprintf (stderr, "guestfsd: xwrite failed\n");
635     exit (EXIT_FAILURE);
636   }
637
638   guestfs_progress message = {
639     .proc = proc_nr,
640     .serial = serial,
641     .position = position,
642     .total = total,
643   };
644
645   xdrmem_create (&xdr, buf, sizeof buf, XDR_ENCODE);
646   if (!xdr_guestfs_progress (&xdr, &message)) {
647     fprintf (stderr, "guestfsd: xdr_guestfs_progress: failed to encode message\n");
648     xdr_destroy (&xdr);
649     return;
650   }
651   len = xdr_getpos (&xdr);
652   xdr_destroy (&xdr);
653
654   if (xwrite (sock, buf, len) == -1) {
655     fprintf (stderr, "guestfsd: xwrite failed\n");
656     exit (EXIT_FAILURE);
657   }
658 }
659
660 /* "Pulse mode" progress messages. */
661
662 #if defined(HAVE_SETITIMER) && defined(HAVE_SIGACTION)
663
664 static void async_safe_send_pulse (int sig);
665
666 void
667 pulse_mode_start (void)
668 {
669   struct sigaction act;
670   struct itimerval it;
671
672   memset (&act, 0, sizeof act);
673   act.sa_handler = async_safe_send_pulse;
674   act.sa_flags = SA_RESTART;
675
676   if (sigaction (SIGALRM, &act, NULL) == -1) {
677     perror ("pulse_mode_start: sigaction");
678     return;
679   }
680
681   it.it_value.tv_sec = NOTIFICATION_INITIAL_DELAY / 1000000;
682   it.it_value.tv_usec = NOTIFICATION_INITIAL_DELAY % 1000000;
683   it.it_interval.tv_sec = NOTIFICATION_PERIOD / 1000000;
684   it.it_interval.tv_usec = NOTIFICATION_PERIOD % 1000000;
685
686   if (setitimer (ITIMER_REAL, &it, NULL) == -1)
687     perror ("pulse_mode_start: setitimer");
688 }
689
690 void
691 pulse_mode_end (void)
692 {
693   pulse_mode_cancel ();         /* Cancel the itimer. */
694
695   notify_progress (1, 1);
696 }
697
698 void
699 pulse_mode_cancel (void)
700 {
701   int err = errno;              /* Function must preserve errno. */
702   struct itimerval it;
703   struct sigaction act;
704
705   /* Setting it_value to zero cancels the itimer. */
706   it.it_value.tv_sec = 0;
707   it.it_value.tv_usec = 0;
708   it.it_interval.tv_sec = 0;
709   it.it_interval.tv_usec = 0;
710
711   if (setitimer (ITIMER_REAL, &it, NULL) == -1)
712     perror ("pulse_mode_cancel: setitimer");
713
714   memset (&act, 0, sizeof act);
715   act.sa_handler = SIG_DFL;
716
717   if (sigaction (SIGALRM, &act, NULL) == -1)
718     perror ("pulse_mode_cancel: sigaction");
719
720   errno = err;
721 }
722
723 /* Send a position = 0, total = 1 (pulse mode) message.  The tricky
724  * part is we have to do it without invoking any non-async-safe
725  * functions (see signal(7) for a list).  Therefore, KISS.
726  */
727 static void
728 async_safe_send_pulse (int sig)
729 {
730   /* XDR is a RFC ... */
731   unsigned char msg[] = {
732     (GUESTFS_PROGRESS_FLAG & 0xff000000) >> 24,
733     (GUESTFS_PROGRESS_FLAG & 0x00ff0000) >> 16,
734     (GUESTFS_PROGRESS_FLAG & 0x0000ff00) >> 8,
735     GUESTFS_PROGRESS_FLAG & 0x000000ff,
736     (proc_nr & 0xff000000) >> 24,
737     (proc_nr & 0x00ff0000) >> 16,
738     (proc_nr & 0x0000ff00) >> 8,
739     proc_nr & 0x000000ff,
740     (serial & 0xff000000) >> 24,
741     (serial & 0x00ff0000) >> 16,
742     (serial & 0x0000ff00) >> 8,
743     serial & 0x000000ff,
744     /* 64 bit position = 0 */ 0, 0, 0, 0, 0, 0, 0, 0,
745     /* 64 bit total = 1 */    0, 0, 0, 0, 0, 0, 0, 1
746   };
747
748   if (xwrite (sock, msg, sizeof msg) == -1)
749     exit (EXIT_FAILURE);
750 }
751
752 #else /* !HAVE_SETITIMER || !HAVE_SIGACTION */
753
754 void
755 pulse_mode_start (void)
756 {
757   /* empty */
758 }
759
760 void
761 pulse_mode_end (void)
762 {
763   /* empty */
764 }
765
766 void
767 pulse_mode_cancel (void)
768 {
769   /* empty */
770 }
771
772 #endif /* !HAVE_SETITIMER || !HAVE_SIGACTION */