From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUNPE-0001S3-Py for qemu-devel@nongnu.org; Tue, 25 Aug 2015 19:13:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUNPB-00021L-Jb for qemu-devel@nongnu.org; Tue, 25 Aug 2015 19:13:28 -0400 Received: from e17.ny.us.ibm.com ([129.33.205.207]:42848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUNPB-00021D-Et for qemu-devel@nongnu.org; Tue, 25 Aug 2015 19:13:25 -0400 Received: from /spool/local by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Aug 2015 19:13:24 -0400 Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 0BDED6E8040 for ; Tue, 25 Aug 2015 19:05:06 -0400 (EDT) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t7PNDLRi59441352 for ; Tue, 25 Aug 2015 23:13:21 GMT Received: from d01av04.pok.ibm.com (localhost [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t7PNDLCY003561 for ; Tue, 25 Aug 2015 19:13:21 -0400 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <1440540624-7998-12-git-send-email-marcandre.lureau@redhat.com> References: <1440540624-7998-1-git-send-email-marcandre.lureau@redhat.com> <1440540624-7998-12-git-send-email-marcandre.lureau@redhat.com> Message-ID: <20150825231318.11069.90786@loki> Date: Tue, 25 Aug 2015 18:13:18 -0500 Subject: Re: [Qemu-devel] [PATCH v2 11/12] qga: add --dump-conf option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Quoting marcandre.lureau@redhat.com (2015-08-25 17:10:23) > From: Marc-Andr=C3=A9 Lureau > = > 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 | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 62 insertions(+) > = > diff --git a/qga/main.c b/qga/main.c > index 154975c..a47310b 100644 > --- a/qga/main.c > +++ b/qga/main.c > @@ -941,6 +941,7 @@ typedef struct GAConfig { > GList *blacklist; > int daemonize; > GLogLevelFlags log_level; > + int dumpconf; > } GAConfig; > = > static void config_load(GAConfig *config) > @@ -1009,6 +1010,58 @@ end: > g_clear_error(&gerr); > } > = > +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 void config_dump(GAConfig *config) > +{ > + GError *error =3D NULL; > + GKeyFile *keyfile; > + gchar *tmp; > + > + keyfile =3D g_key_file_new(); > + g_key_file_set_boolean(keyfile, "general", "daemon", config->daemoni= ze); > + g_key_file_set_string(keyfile, "general", "method", config->method); > + g_key_file_set_string(keyfile, "general", "path", config->channel_pa= th); > + if (config->log_filepath) { > + g_key_file_set_string(keyfile, "general", "logfile", > + config->log_filepath); > + } > + g_key_file_set_string(keyfile, "general", "pidfile", config->pid_fil= epath); > +#ifdef CONFIG_FSFREEZE > + if (config->fsfreeze_hook) { > + g_key_file_set_string(keyfile, "general", "fsfreeze-hook", > + config->fsfreeze_hook); > + } > +#endif > + g_key_file_set_string(keyfile, "general", "statedir", config->state_= dir); > + g_key_file_set_boolean(keyfile, "general", "verbose", > + config->log_level =3D=3D G_LOG_LEVEL_MASK); > + tmp =3D list_join(config->blacklist, ','); Since we have the list_join() helper to convert config->blacklist, it makes me wonder if there's really any need to add/init config->bliststr in the previous patch. This patch looks good though: Reviewed-by: Michael Roth > + g_key_file_set_string(keyfile, "general", "blacklist", tmp); > + g_free(tmp); > + > + tmp =3D g_key_file_to_data(keyfile, NULL, &error); > + printf("%s", tmp); > + > + g_free(tmp); > + if (keyfile) { > + g_key_file_free(keyfile); > + } > +} > + > static void config_parse(GAConfig *config, int argc, char **argv) > { > const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:D"; > @@ -1016,6 +1069,7 @@ static void config_parse(GAConfig *config, 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 > @@ -1067,6 +1121,9 @@ static void config_parse(GAConfig *config, int argc= , char **argv) > case 'd': > config->daemonize =3D 1; > break; > + case 'D': > + config->dumpconf =3D 1; > + break; > case 'b': { > if (is_help_option(optarg)) { > qmp_for_each_command(ga_print_cmd, NULL); > @@ -1310,6 +1367,11 @@ int main(int argc, char **argv) > config->state_dir); > s->frozen =3D check_is_frozen(s); > = > + if (config->dumpconf) { > + config_dump(config); > + goto end; > + } > + > ret =3D run_agent(s, config); > = > end: > -- = > 2.4.3 >=20