From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWozP-00020n-Tm for qemu-devel@nongnu.org; Tue, 01 Sep 2015 13:04:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWozN-00011U-1V for qemu-devel@nongnu.org; Tue, 01 Sep 2015 13:04:55 -0400 Received: from e36.co.us.ibm.com ([32.97.110.154]:40335) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWozM-000114-S0 for qemu-devel@nongnu.org; Tue, 01 Sep 2015 13:04:52 -0400 Received: from /spool/local by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Sep 2015 11:04:50 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 04C793E4003E for ; Tue, 1 Sep 2015 11:04:01 -0600 (MDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t81H40jb32243936 for ; Tue, 1 Sep 2015 10:04:00 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t81H40nb031508 for ; Tue, 1 Sep 2015 11:04:00 -0600 From: Michael Roth Date: Tue, 1 Sep 2015 12:01:00 -0500 Message-Id: <1441126866-17199-21-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1441126866-17199-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1441126866-17199-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 20/26] qga: add --dump-conf option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= 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 Reviewed-by: Denis V. Lunev * removed unecessary keyfile != NULL prior to free * documented --dump-conf is qemu-ga --help output Signed-off-by: Michael Roth --- qga/main.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/qga/main.c b/qga/main.c index 322f81d..f75ab4b 100644 --- a/qga/main.c +++ b/qga/main.c @@ -216,6 +216,8 @@ 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 a qemu-ga config file based on current config\n" +" options / command-line parameters to stdout\n" " -h, --help display this help and exit\n" "\n" "Report bugs to \n" @@ -936,6 +938,7 @@ typedef struct GAConfig { GList *blacklist; int daemonize; GLogLevelFlags log_level; + int dumpconf; } GAConfig; static void config_load(GAConfig *config) @@ -1002,6 +1005,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(); + g_assert(keyfile); + + 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); + 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"; @@ -1009,6 +1064,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 @@ -1066,6 +1122,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); @@ -1309,6 +1368,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: -- 1.9.1