11 #define MAX_GUEST_CMDLINE 1024
12 #define PARSE_ARGS(ARGS,START,QUOTE,END) \
25 } else if (*c == ' ') \
27 if (*c == '"' || *c == '\'') { \
41 printf("Warning: unterminated quotation %c\n", quote); \
44 #define PARSE_ARGS_COUNT(ARGS) PARSE_ARGS(ARGS, argc++, c++, )
45 #define PARSE_ARGS_STORE(ARGS) PARSE_ARGS(ARGS, argv[argc++] = c, memmove(c, c + 1, strlen(c + 1) + 1), *c++ = 0)
47 struct xs_handle
*xsh
=NULL
;
49 int xenbus_read_integer(const char *path
)
55 buf
= xs_read(xsh
,XBT_NULL
, path
, &len
);
57 printf("Failed to read %s.\n", path
);
61 sscanf(buf
, "%d", &t
);
72 char *envp
[] = { NULL
};
77 char cmdline
[MAX_GUEST_CMDLINE
];
83 /* read cmdline from /proc/cmdline */
84 fd
=open("/proc/cmdline",O_RDONLY
);
86 printf("Cannot open /proc/cmdline\n");
89 if(read(fd
,cmdline
,MAX_GUEST_CMDLINE
) < 0){
90 printf("Cannot read cmdline from /proc/cmdline\n");
94 printf("cmdline(%s)\n",cmdline
);
97 mount("xenfs","/proc/xen","xenfs",MS_NODEV
,"");
99 printf("printf /dev dir\n");
100 if((dp
=opendir("/dev")) == NULL
)
102 printf("there is no /dev dir\n");
105 while((dirp
=readdir(dp
)) != NULL
)
106 printf("%s ",dirp
->d_name
);
110 xsh
=xs_daemon_open();
112 printf("Cannot open xenstore handle\n");
116 /* Fetch argc, argv from XenStore */
117 domid
= xenbus_read_integer("target");
119 printf("Couldn't read target\n");
123 snprintf(path
, sizeof(path
), "/local/domain/%d/vm", domid
);
124 vm
= xs_read(xsh
,XBT_NULL
, path
,&len
);
126 printf("Couldn't read vm path\n");
130 snprintf(path
, sizeof(path
), "%s/image/dmargs", vm
);
133 domargs
= xs_read(xsh
,XBT_NULL
, path
, &len
);
135 printf("stubdom args is empty\n");
136 domargs
= strdup("");
139 xs_daemon_close(xsh
);
143 // PARSE_ARGS_COUNT(cmdline);
144 PARSE_ARGS_COUNT(domargs
);
146 argv
= alloca((argc
+ 3) * sizeof(char *));
152 // PARSE_ARGS_STORE(cmdline)
153 PARSE_ARGS_STORE(domargs
)
157 for (i
= 0; i
< argc
; i
++)
158 printf("\"%s\" ", argv
[i
]);
161 execve("/bin/qemu",argv
,envp
);