Yang Hongyang
2010-May-05 04:42 UTC
[Xen-devel] [PATCH]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. Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com> 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@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2010-May-05 16:20 UTC
Re: [Xen-devel] [PATCH]xl: move libxl init functions from xl.c to xl_cmdimpl.c
Yang Hongyang writes ("[Xen-devel] [PATCH]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.I don''t understand the purpose of this change. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Yang Hongyang
2010-May-06 01:12 UTC
Re: [Xen-devel] [PATCH]xl: move libxl init functions from xl.c to xl_cmdimpl.c
Hi Ian, On 05/06/2010 12:20 AM, Ian Jackson wrote:> Yang Hongyang writes ("[Xen-devel] [PATCH]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. > > 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.> > Ian. > >-- Regards Yang Hongyang _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel