Move libxl init functions from xl.c to xl_cmdimpl.c, use a wrapper function
xl_init to do libxl init things.
Signed-off-by: Yang Hongyang <yanghy@xxxxxxxxxxxxxx>
diff -r efa1b905d893 tools/libxl/xl.c
--- a/tools/libxl/xl.c Tue May 04 13:59:55 2010 +0100
+++ b/tools/libxl/xl.c Wed May 05 20:22:03 2010 +0800
@@ -31,17 +31,6 @@
#include "xl_cmdimpl.h"
#include "xl_cmdtable.h"
-extern struct libxl_ctx ctx;
-extern int logfile;
-
-void log_callback(void *userdata, int loglevel, const char *file, int line,
const char *func, char *s)
-{
- char str[1024];
-
- snprintf(str, sizeof(str), "[%d] %s:%d:%s: %s\n", loglevel, file, line,
func, s);
- write(logfile, str, strlen(str));
-}
-
int main(int argc, char **argv)
{
int i;
@@ -51,14 +40,7 @@
exit(1);
}
- if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
- fprintf(stderr, "cannot init xl context\n");
- exit(1);
- }
- if (libxl_ctx_set_log(&ctx, log_callback, NULL)) {
- fprintf(stderr, "cannot set xl log callback\n");
- exit(-ERROR_FAIL);
- }
+ xl_init();
srand(time(0));
diff -r efa1b905d893 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Tue May 04 13:59:55 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Wed May 05 20:22:03 2010 +0800
@@ -87,6 +87,26 @@
#define SAVEFILE_BYTEORDER_VALUE ((uint32_t)0x01020304UL)
+void log_callback(void *userdata, int loglevel, const char *file, int line,
const char *func, char *s)
+{
+ char str[1024];
+
+ snprintf(str, sizeof(str), "[%d] %s:%d:%s: %s\n", loglevel, file, line,
func, s);
+ write(logfile, str, strlen(str));
+}
+
+void xl_init(void)
+{
+ if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+ fprintf(stderr, "cannot init xl context\n");
+ exit(1);
+ }
+ if (libxl_ctx_set_log(&ctx, log_callback, NULL)) {
+ fprintf(stderr, "cannot set xl log callback\n");
+ exit(-ERROR_FAIL);
+ }
+}
+
static int domain_qualifier_to_domid(const char *p, uint32_t *domid_r,
int *was_name_r)
{
diff -r efa1b905d893 tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h Tue May 04 13:59:55 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h Wed May 05 20:22:03 2010 +0800
@@ -37,3 +37,4 @@
int main_sched_credit(int argc, char **argv);
void help(char *command);
+void xl_init(void);
--
Regards
Yang Hongyang
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|