From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDb51-0005gS-UD for qemu-devel@nongnu.org; Fri, 30 Mar 2012 08:37:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDb4w-0004mZ-Ex for qemu-devel@nongnu.org; Fri, 30 Mar 2012 08:37:23 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:47149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDb4t-0004VO-Q7 for qemu-devel@nongnu.org; Fri, 30 Mar 2012 08:37:18 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 30 Mar 2012 18:06:53 +0530 Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2UCamDt4051064 for ; Fri, 30 Mar 2012 18:06:48 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q2UI7GOF022804 for ; Sat, 31 Mar 2012 05:07:17 +1100 From: Wanpeng Li Date: Fri, 30 Mar 2012 20:36:43 +0800 Message-Id: <1333111003-28556-1-git-send-email-liwp@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] RFC: options parse in vl.c should be moduled List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori , Stefan Hajnoczi , =?UTF-8?q?Andreas=20F=C3=A4rber?= , qemu-devel Cc: Wanpeng Li , Gavin Shan Consider of the options parse process in main function of vl.c is too long.It should be module into single function to clear ideas, strengthen the source code management, and increase code readability.So I module the process of options parse as function options_parse, and expose some variables in order to not influence command-line invocations. Signed-off-by: Wanpeng Li --- vl.c | 159 ++++++++++++++++++++++++++++++++++------------------------------- 1 files changed, 83 insertions(+), 76 deletions(-) diff --git a/vl.c b/vl.c index 0fccf50..fa4d0a9 100644 --- a/vl.c +++ b/vl.c @@ -2251,84 +2251,40 @@ int qemu_init_main_loop(void) return main_loop_init(); } -int main(int argc, char **argv, char **envp) -{ - int i; - int snapshot, linux_boot; - const char *icount_option = NULL; - const char *initrd_filename; - const char *kernel_filename, *kernel_cmdline; - char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ - DisplayState *ds; - DisplayChangeListener *dcl; - int cyls, heads, secs, translation; - QemuOpts *hda_opts = NULL, *opts, *machine_opts; - QemuOptsList *olist; - int optind; - const char *optarg; - const char *loadvm = NULL; - QEMUMachine *machine; - const char *cpu_model; - const char *vga_model = NULL; - const char *pid_file = NULL; - const char *incoming = NULL; +int snapshot, linux_boot; +const char *icount_option; +const char *initrd_filename; +const char *kernel_filename, *kernel_cmdline; +char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ +DisplayState *ds; +DisplayChangeListener *dcl; +int cyls, heads, secs, translation; +QemuOpts *hda_opts , *opts, *machine_opts; +QemuOptsList *olist; +int optind; +const char *loadvm; +QEMUMachine *machine; +const char *cpu_model; +const char *vga_model; +const char *pid_file; +const char *incoming; #ifdef CONFIG_VNC - int show_vnc_port = 0; +int show_vnc_port; #endif - int defconfig = 1; - const char *log_mask = NULL; - const char *log_file = NULL; - GMemVTable mem_trace = { - .malloc = malloc_and_trace, - .realloc = realloc_and_trace, - .free = free_and_trace, - }; - const char *trace_events = NULL; - const char *trace_file = NULL; - - atexit(qemu_run_exit_notifiers); - error_set_progname(argv[0]); - - g_mem_set_vtable(&mem_trace); - if (!g_thread_supported()) { -#if !GLIB_CHECK_VERSION(2, 31, 0) - g_thread_init(NULL); -#else - fprintf(stderr, "glib threading failed to initialize.\n"); - exit(1); -#endif - } - - module_call_init(MODULE_INIT_QOM); - - runstate_init(); - - init_clocks(); - rtc_clock = host_clock; - - qemu_cache_utils_init(envp); - - QLIST_INIT (&vm_change_state_head); - os_setup_early_signal_handling(); - - module_call_init(MODULE_INIT_MACHINE); - machine = find_default_machine(); - cpu_model = NULL; - ram_size = 0; - snapshot = 0; - cyls = heads = secs = 0; - translation = BIOS_ATA_TRANSLATION_AUTO; - - for (i = 0; i < MAX_NODES; i++) { - node_mem[i] = 0; - node_cpumask[i] = 0; - } - - nb_numa_nodes = 0; - nb_nics = 0; - - autostart= 1; +int defconfig = 1; +const char *log_mask; +const char *log_file; +GMemVTable mem_trace = { + .malloc = malloc_and_trace, + .realloc = realloc_and_trace, + .free = free_and_trace, +}; +const char *trace_events; +const char *trace_file; +static void options_parse(int argc, char **argv) +{ + const char *optarg; /* first pass of option parsing */ optind = 1; while (optind < argc) { @@ -2867,7 +2823,7 @@ int main(int argc, char **argv, char **envp) if (watchdog) { fprintf(stderr, "qemu: only one watchdog option may be given\n"); - return 1; + exit(1); } watchdog = optarg; break; @@ -3186,6 +3142,57 @@ int main(int argc, char **argv, char **envp) } } } +} + +int main(int argc, char **argv, char **envp) +{ + int i; + + atexit(qemu_run_exit_notifiers); + error_set_progname(argv[0]); + + g_mem_set_vtable(&mem_trace); + if (!g_thread_supported()) { +#if !GLIB_CHECK_VERSION(2, 31, 0) + g_thread_init(NULL); +#else + fprintf(stderr, "glib threading failed to initialize.\n"); + exit(1); +#endif + } + + module_call_init(MODULE_INIT_QOM); + + runstate_init(); + + init_clocks(); + rtc_clock = host_clock; + + qemu_cache_utils_init(envp); + + QLIST_INIT(&vm_change_state_head); + os_setup_early_signal_handling(); + + module_call_init(MODULE_INIT_MACHINE); + machine = find_default_machine(); + cpu_model = NULL; + ram_size = 0; + snapshot = 0; + cyls = heads = secs = 0; + translation = BIOS_ATA_TRANSLATION_AUTO; + + for (i = 0; i < MAX_NODES; i++) { + node_mem[i] = 0; + node_cpumask[i] = 0; + } + + nb_numa_nodes = 0; + nb_nics = 0; + + autostart = 1; + + options_parse(argc, argv); + loc_set_none(); /* Init CPU def lists, based on config -- 1.7.5.4