xl: move libxl init functions from xl.c to xl_cmdimpl.c
PATCH 1/1 xl: move libxl init functions from xl.c to xl_cmdimpl.c
Move libxl init functions from xl.c to xl_cmdimpl.c, use a wrapper function xl_init to do libxl init things.
tools/libxl/xl.c +1 -19
@@ -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 ));
tools/libxl/xl_cmdimpl.c +20 -0
@@ -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) {
tools/libxl/xl_cmdimpl.h +1 -0
@@ -37,3 +37,4 @@int main_sched_credit (int argc,char **argv);void help (char *command); +void xl_init (void );
Signature · 2 lines
Regards Yang Hongyang
Yang Hongyang writes ("[Xen-devel] [PATCH]xl: move libxl init functions from xl.c to xl_cmdimpl.c"):
Quoted 2 lines
Move libxl init functions from
xl.ctoxl_cmdimpl.c, use a wrapper functionxl_initto do libxl init things.
I don't understand the purpose of this change.
Ian.
Hi Ian,
Quoted 5 lines · Ian Jackson
Yang Hongyang writes ("[Xen-devel] [PATCH]xl: move libxl init functions from
xl.ctoxl_cmdimpl.c"):Quoted 2 lines
Move libxl init functions from
xl.ctoxl_cmdimpl.c, use a wrapper functionxl_initto do libxl init things.I don't understand the purpose of this change.
It's my mistake that uses extern vars in .c file this way, Keir fix part of it, but there remains two declarations in xl.c. My prupose is to correct this usage. But compare to move these declarations to .h file, I prefer move code related to these vars to xl_cmdimpl.c, because I think the libxl init and set log functions is more related to command implementations.
Quoted 4 lines
Ian.
Signature · 2 lines
Regards Yang Hongyang