From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUHTH-0006Zy-8N for qemu-devel@nongnu.org; Tue, 25 Aug 2015 12:53:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUHT8-000686-S9 for qemu-devel@nongnu.org; Tue, 25 Aug 2015 12:53:10 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:55018) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUHT8-00067d-DI for qemu-devel@nongnu.org; Tue, 25 Aug 2015 12:53:06 -0400 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Aug 2015 10:53:05 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 4878B19D8040 for ; Tue, 25 Aug 2015 10:42:11 -0600 (MDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t7PGoGY327328676 for ; Tue, 25 Aug 2015 09:50:16 -0700 Received: from d03av03.boulder.ibm.com (localhost [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t7PGpFCb017482 for ; Tue, 25 Aug 2015 10:51:15 -0600 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <1435751267-26378-7-git-send-email-marcandre.lureau@gmail.com> References: <1435751267-26378-1-git-send-email-marcandre.lureau@gmail.com> <1435751267-26378-7-git-send-email-marcandre.lureau@gmail.com> Message-ID: <20150825162400.11069.79378@loki> Date: Tue, 25 Aug 2015 11:24:00 -0500 Subject: Re: [Qemu-devel] [PATCH 06/12] qga: move option parsing to seperate function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Quoting Marc-Andr=C3=A9 Lureau (2015-07-01 06:47:41) > Move option parsing out of giant main(). > = > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > qga/main.c | 41 +++++++++++++++++++++++++---------------- > 1 file changed, 25 insertions(+), 16 deletions(-) > = > diff --git a/qga/main.c b/qga/main.c > index b776d16..b965f61 100644 > --- a/qga/main.c > +++ b/qga/main.c > @@ -941,19 +941,25 @@ static GList *split_list(gchar *str, const gchar se= parator) > return list; > } > = > -int main(int argc, char **argv) > -{ > - const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:"; > - char *method =3D NULL, *device_path =3D NULL; > - char *log_filepath =3D NULL; > - char *pid_filepath =3D NULL; > +static char *device_path; > +static char *method; > +static char *log_filepath; > +static char *pid_filepath; Since we want to pass these around as a representation of the configuration state, I'd rather we package them into a GAConfig structure or something of the sort that and pass it around as arguments rather than as globals. Between parse/load_config/load_defaults it's becoming a little difficult to keep track of where all these values are being modified. Otherwise, looks good, and makes for a nice cleanup. > #ifdef CONFIG_FSFREEZE > - char *fsfreeze_hook =3D NULL; > +static char *fsfreeze_hook; > #endif > - char *state_dir =3D NULL; > +static char *state_dir; > #ifdef _WIN32 > - const char *service =3D NULL; > +static const char *service; > #endif > +static GList *blacklist; > +static int daemonize; > +static GLogLevelFlags log_level =3D G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRIT= ICAL; > + > +static void option_parse(int argc, char **argv) > +{ > + const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:D"; > + int opt_ind =3D 0, ch; > const struct option lopt[] =3D { > { "help", 0, NULL, 'h' }, > { "version", 0, NULL, 'V' }, > @@ -973,14 +979,7 @@ int main(int argc, char **argv) > { "statedir", 1, NULL, 't' }, > { NULL, 0, NULL, 0 } > }; > - int opt_ind =3D 0, ch, daemonize =3D 0; > - GLogLevelFlags log_level =3D G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICA= L; > - GList *blacklist =3D NULL; > - GAState *s; > = > - module_call_init(MODULE_INIT_QAPI); > - > - init_dfl_pathnames(); > while ((ch =3D getopt_long(argc, argv, sopt, lopt, &opt_ind)) !=3D -= 1) { > switch (ch) { > case 'm': > @@ -1058,6 +1057,16 @@ int main(int argc, char **argv) > exit(EXIT_FAILURE); > } > } > +} > + > +int main(int argc, char **argv) > +{ > + GAState *s; > + > + module_call_init(MODULE_INIT_QAPI); > + > + init_dfl_pathnames(); > + option_parse(argc, argv); > = > if (pid_filepath =3D=3D NULL) { > pid_filepath =3D g_strdup(dfl_pathnames.pidfile); > -- = > 2.4.3 >=20