1 #include <stdlib.h>
2 #include <stdint.h>
3 #include <string.h>
4 #include <stdio.h>
5
6 #include <xenstore.h>
7
8 #include "init-dom-json.h"
9
10 #define DOMNAME_PATH "/local/domain/0/name"
11 #define DOMID_PATH "/local/domain/0/domid"
12
main(int argc,char ** argv)13 int main(int argc, char **argv)
14 {
15 int rc;
16 struct xs_handle *xsh;
17 char *domname_string = NULL, *domid_string = NULL;
18
19 xsh = xs_open(0);
20 if (!xsh) {
21 fprintf(stderr, "cannot open xenstore connection\n");
22 exit(1);
23 }
24
25 /* Sanity check: this program can only be run once. */
26 domid_string = xs_read(xsh, XBT_NULL, DOMID_PATH, NULL);
27 domname_string = xs_read(xsh, XBT_NULL, DOMNAME_PATH, NULL);
28 if (domid_string && domname_string) {
29 fprintf(stderr, "Dom0 is already set up\n");
30 rc = 0;
31 goto out;
32 }
33
34 rc = gen_stub_json_config(0);
35 if (rc)
36 goto out;
37
38 /* Write xenstore entries. */
39 if (!xs_write(xsh, XBT_NULL, DOMID_PATH, "0", strlen("0"))) {
40 fprintf(stderr, "cannot set domid for Dom0\n");
41 rc = 1;
42 goto out;
43 }
44
45 if (!xs_write(xsh, XBT_NULL, DOMNAME_PATH, "Domain-0",
46 strlen("Domain-0"))) {
47 fprintf(stderr, "cannot set domain name for Dom0\n");
48 rc = 1;
49 goto out;
50 }
51
52 printf("Done setting up Dom0\n");
53
54 out:
55 free(domid_string);
56 free(domname_string);
57 xs_close(xsh);
58 return rc;
59 }
60
61 /*
62 * Local variables:
63 * mode: C
64 * c-basic-offset: 4
65 * indent-tabs-mode: nil
66 * End:
67 */
68