From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUfwX-0005b6-RM for qemu-devel@nongnu.org; Wed, 26 Aug 2015 15:01:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUfwU-0004fu-KD for qemu-devel@nongnu.org; Wed, 26 Aug 2015 15:01:05 -0400 Received: from mx2.parallels.com ([199.115.105.18]:50908) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUfwU-0004fE-F5 for qemu-devel@nongnu.org; Wed, 26 Aug 2015 15:01:02 -0400 References: <1440583525-21632-1-git-send-email-marcandre.lureau@redhat.com> <1440583525-21632-12-git-send-email-marcandre.lureau@redhat.com> From: "Denis V. Lunev" Message-ID: <55DE0CE3.90208@parallels.com> Date: Wed, 26 Aug 2015 22:00:51 +0300 MIME-Version: 1.0 In-Reply-To: <1440583525-21632-12-git-send-email-marcandre.lureau@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v3 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 Cc: mdroth@linux.vnet.ibm.com On 08/26/2015 01:05 PM, marcandre.lureau@redhat.com wrote: > From: Marc-André Lureau > > This new option allows to review the agent configuration, > and ease the task of writing a configuration file. > > Signed-off-by: Marc-André Lureau > Reviewed-by: Michael Roth > --- > qga/main.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 62 insertions(+) > > diff --git a/qga/main.c b/qga/main.c > index 9193043..72dc366 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 = g_string_new(""); > + > + while (list) { > + str = g_string_append(str, (gchar *)list->data); > + list = g_list_next(list); > + if (list) { > + str = g_string_append_c(str, separator); > + } > + } > + > + return g_string_free(str, FALSE); > +} > + > +static void config_dump(GAConfig *config) > +{ > + GError *error = NULL; > + GKeyFile *keyfile; > + gchar *tmp; > + > + keyfile = g_key_file_new(); keyfile == NULL either means error and you should immediately return as I am not quite sure that calls below will survive Thus the check below for keyfile == NULL is extra and could be dropped. If these functions are OK with NULL then free will be also fine too and check is not needed too. > + g_key_file_set_boolean(keyfile, "general", "daemon", config->daemonize); > + g_key_file_set_string(keyfile, "general", "method", config->method); > + g_key_file_set_string(keyfile, "general", "path", config->channel_path); > + 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_filepath); > +#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 == G_LOG_LEVEL_MASK); > + tmp = list_join(config->blacklist, ','); > + g_key_file_set_string(keyfile, "general", "blacklist", tmp); > + g_free(tmp); > + > + tmp = 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 = "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[] = { > { "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 = 1; > break; > + case 'D': > + config->dumpconf = 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 = check_is_frozen(s); > > + if (config->dumpconf) { > + config_dump(config); > + goto end; > + } > + > ret = run_agent(s, config); > > end: