[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 20/26] qga: add --dump-conf option
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 20/26] qga: add --dump-conf option |
Date: |
Tue, 1 Sep 2015 13:38:57 -0500 |
From: Marc-André Lureau <address@hidden>
This new option allows to review the agent configuration,
and ease the task of writing a configuration file.
Signed-off-by: Marc-André Lureau <address@hidden>
Reviewed-by: Michael Roth <address@hidden>
Reviewed-by: Denis V. Lunev <address@hidden>
* removed unecessary keyfile != NULL prior to free
* documented --dump-conf is qemu-ga --help output
Signed-off-by: Michael Roth <address@hidden>
---
qga/main.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/qga/main.c b/qga/main.c
index cc7a910..d8e063a 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 <address@hidden>\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);
@@ -1314,6 +1373,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
- [Qemu-devel] [PULL v2 00/26] qemu-ga patch queue for 2015-09-01, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 10/26] qga: use exit() when parsing options, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 09/26] qga: misc spelling, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 12/26] qga: make split_list() return allocated strings, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 11/26] qga: move string split in separate function, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 16/26] qga: fill default options in main(), Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 18/26] qga: free a bit more, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 17/26] qga: move agent run in a separate function, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 15/26] qga: move option parsing to separate function, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 13/26] qga: rename 'path' to 'channel_path', Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 20/26] qga: add --dump-conf option,
Michael Roth <=
- [Qemu-devel] [PATCH 21/26] qga: start a man page, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 01/26] qemu-ga: Add .msi files to .gitignore, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 22/26] qemu-ga: implement win32 guest-set-user-password, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 14/26] qga: copy argument strings, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 23/26] configure: qemu-ga: move MSI installer probe after qga probe, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 25/26] build: qemu-ga: fix VSS dependencies, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 24/26] configure: qemu-ga: explicitly enable qemu-ga MSI support when probed, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 04/26] qemu-ga: Minor cosmetic changes to the WXS file, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 06/26] qemu-ga: Prevent QEMU-GA VSS provider from being unregistered on MSI reinstall, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 03/26] qemu-ga: Fixed GUID capitalization, Michael Roth, 2015/09/01