ia64/xen-unstable

view tools/misc/xc_shadow.c @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 06d84bf87159
children d4e433d615b0
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
2 ****************************************************************************
3 * (C) 2005 - Rolf Neugebauer - Intel Research Cambridge
4 ****************************************************************************
5 *
6 * File: xc_shadow.c
7 * Author: Rolf Neugebauer (rolf.neugebauer@intel.com)
8 * Date: Mar 2005
9 *
10 * Description:
11 */
14 #include <xenctrl.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <sys/mman.h>
18 #include <errno.h>
19 #include <string.h>
21 void usage()
22 {
23 printf("xc_shadow: -[0|1|2]\n");
24 printf(" set shadow mode\n");
25 exit(0);
26 }
28 int main(int argc, char *argv[])
29 {
30 int xc_handle;
31 int mode;
33 if ( argc > 1 )
34 {
35 char *p = argv[1];
36 if (*p++ == '-') {
37 if (*p == '1')
38 mode = 1;
39 else if (*p == '2')
40 mode = 2;
41 else if (*p == '0')
42 mode = 0;
43 else
44 usage();
45 } else
46 usage();
47 }
48 else
49 usage();
51 if ( (xc_handle = xc_interface_open()) == -1 )
52 {
53 fprintf(stderr, "Error opening xc interface: %d (%s)\n",
54 errno, strerror(errno));
55 return 1;
56 }
58 if ( xc_shadow_control(xc_handle,
59 0,
60 mode,
61 NULL,
62 0,
63 NULL) < 0 )
64 {
65 fprintf(stderr, "Error reseting performance counters: %d (%s)\n",
66 errno, strerror(errno));
67 return 1;
68 }
69 return 0;
70 }