ia64/xen-unstable

view tools/internal/xi_destroy.c @ 522:07cb518caf2f

bitkeeper revision 1.289 (3f09877bT-kkJTOM1WvHevpN2wY-qw)

Prune old code
author rac61@labyrinth.cl.cam.ac.uk
date Mon Jul 07 14:45:15 2003 +0000 (2003-07-07)
parents 62a46bc69cac
children 9339f3942f4e cda951fc1bef
line source
1 /*
2 * A very(!) simple program to kill a domain. (c) Boris Dragovic
3 * Usage: <executable> <mem_kb> <os image> <num_vifs>
4 */
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <sys/stat.h>
11 #include <sys/types.h>
13 #include "dom0_ops.h"
14 #include "dom0_defs.h"
16 /***********************************************************************/
18 static char *argv0 = "internal_domain_stop";
20 static void ERROR (char *message)
21 {
22 fprintf (stderr, "%s: %s\n", argv0, message);
23 exit (-1);
24 }
26 static void PERROR (char *message)
27 {
28 fprintf (stderr, "%s: %s (%s)\n", argv0, message, strerror(errno));
29 exit (-1);
30 }
32 /***********************************************************************/
34 static int do_kill_domain(int dom_id, int force)
35 {
36 char cmd_path[MAX_PATH];
37 dom0_op_t dop;
38 int cmd_fd;
40 dop.cmd = DOM0_DESTROYDOMAIN;
41 dop.u.killdomain.domain = dom_id;
42 dop.u.killdomain.force = force;
44 /* open the /proc command interface */
45 sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
46 cmd_fd = open(cmd_path, O_WRONLY);
47 if(cmd_fd < 0){
48 PERROR ("Count not open PROC_CMD interface");
49 }
51 write(cmd_fd, &dop, sizeof(dom0_op_t));
52 close(cmd_fd);
54 return 0;
55 }
57 int main(int argc, char **argv)
58 {
59 int ret;
61 if (argv[0] != NULL)
62 {
63 argv0 = argv[0];
64 }
66 if ( (argc < 2) || (argc > 3) )
67 {
68 usage:
69 fprintf(stderr, "Usage: %s [-f] <domain_id>\n", argv0);
70 fprintf(stderr, " -f: Forces immediate destruction of specified domain\n");
71 ret = -1;
72 goto out;
73 }
75 if ( (argc == 3) && strcmp("-f", argv[1]) ) goto usage;
77 ret = do_kill_domain(atoi(argv[argc-1]), argc == 3);
79 out:
80 return ret;
81 }