From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUHlE-0006li-Op for qemu-devel@nongnu.org; Tue, 25 Aug 2015 13:11:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUHlC-0001mb-0W for qemu-devel@nongnu.org; Tue, 25 Aug 2015 13:11:48 -0400 Received: from e19.ny.us.ibm.com ([129.33.205.209]:33132) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUHlB-0001ly-TG for qemu-devel@nongnu.org; Tue, 25 Aug 2015 13:11:45 -0400 Received: from /spool/local by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Aug 2015 13:11:44 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 2BE1DC90042 for ; Tue, 25 Aug 2015 13:02:46 -0400 (EDT) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t7PHBflw61407434 for ; Tue, 25 Aug 2015 17:11:41 GMT Received: from d01av05.pok.ibm.com (localhost [127.0.0.1]) by d01av05.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t7PHBemS007741 for ; Tue, 25 Aug 2015 13:11:41 -0400 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <1435751267-26378-11-git-send-email-marcandre.lureau@gmail.com> References: <1435751267-26378-1-git-send-email-marcandre.lureau@gmail.com> <1435751267-26378-11-git-send-email-marcandre.lureau@gmail.com> Message-ID: <20150825171138.11069.51537@loki> Date: Tue, 25 Aug 2015 12:11:38 -0500 Subject: Re: [Qemu-devel] [PATCH 10/12] qga: add --dump-conf option 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:45) > This new option allows to review the agent configuration, > and ease the task of writing a configuration file. > = > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > qga/main.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 45 insertions(+), 1 deletion(-) > = > diff --git a/qga/main.c b/qga/main.c > index bd87050..f6dbb3e 100644 > --- a/qga/main.c > +++ b/qga/main.c > @@ -215,6 +215,7 @@ static void usage(const char *cmd) > #endif > " -b, --blacklist comma-separated list of RPCs to disable (no spaces,= \"?\"\n" > " to list available RPCs)\n" > +" -D, --dump-conf dump the configuration and exit\n" > " -h, --help display this help and exit\n" > "\n" > "Report bugs to \n" > @@ -904,6 +905,21 @@ static void ga_print_cmd(QmpCommand *cmd, void *opaq= ue) > printf("%s\n", qmp_command_name(cmd)); > } > = > +static gchar *list_join(GList *list, const gchar separator) > +{ > + GString *str =3D g_string_new(""); > + > + while (list) { > + str =3D g_string_append(str, (gchar *)list->data); > + list =3D g_list_next(list); > + if (list) { > + str =3D g_string_append_c(str, separator); > + } > + } > + > + return g_string_free(str, FALSE); > +} > + > static GList *split_list(gchar *str, const gchar separator) > { > GList *list =3D NULL; > @@ -936,9 +952,28 @@ static char *state_dir; > static const char *service; > #endif > static GList *blacklist; > -static int daemonize; > +static int daemonize, dumpconf; > static GLogLevelFlags log_level =3D G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRIT= ICAL; > = > +static void dump_config(void) > +{ > + gchar *bl =3D list_join(blacklist, ','); > + > + printf("[general]\n"); > + printf("daemonize =3D %d\n", daemonize); > + printf("pidfile =3D %s\n", pid_filepath); > + if (log_filepath) { > + printf("logfile =3D %s\n", log_filepath); > + } > + printf("verbose =3D %d\n", log_level =3D=3D G_LOG_LEVEL_MASK); > + printf("method =3D %s\n", method); > + printf("path =3D %s\n", device_path); > + printf("statedir =3D %s\n", state_dir); > + printf("blacklist =3D %s\n", bl); I think we're missing fsfreeze_hook option here. To me it seems cleaner to actually create the GKeyFile from current options, then let GLib do all the work of generation a config file we can spit out (g_key_file_to_data() should do it i think). That, paired with the idea of having a GAConfig structure to encapulate all the config options, might warrant restructuring things a bit so that we have a gkeyfile_to_gaconfig()/gkeyfile_from_gaconfig() pair to use for reading/dumping configs while keeping all the options in an easily trackable place. > + > + g_free(bl); > +} > + > static void option_parse(int argc, char **argv) > { > const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:D"; > @@ -946,6 +981,7 @@ static void option_parse(int argc, char **argv) > const struct option lopt[] =3D { > { "help", 0, NULL, 'h' }, > { "version", 0, NULL, 'V' }, > + { "dump-conf", 0, NULL, 'D' }, > { "logfile", 1, NULL, 'l' }, > { "pidfile", 1, NULL, 'f' }, > #ifdef CONFIG_FSFREEZE > @@ -1031,6 +1067,9 @@ static void option_parse(int argc, char **argv) > } > break; > #endif > + case 'D': > + dumpconf =3D 1; > + break; > case 'h': > usage(argv[0]); > exit(EXIT_SUCCESS); > @@ -1205,6 +1244,11 @@ int main(int argc, char **argv) > } > } > = > + if (dumpconf) { > + dump_config(); > + goto end; > + } > + > s->log_level =3D log_level; > s->log_file =3D stderr; > #ifdef CONFIG_FSFREEZE > -- = > 2.4.3 >=20