From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@gmail.com>,
mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 11/12] qga: add an optionnal qemu-ga.conf system configuration
Date: Wed, 1 Jul 2015 13:47:46 +0200 [thread overview]
Message-ID: <1435751267-26378-12-git-send-email-marcandre.lureau@gmail.com> (raw)
In-Reply-To: <1435751267-26378-1-git-send-email-marcandre.lureau@gmail.com>
Learn to configure the agent with a system configuration.
This may simplify command-line handling, especially when the blacklist
is long.
Among the other benefits, this may standardize the configuration of a
init service (instead distro-specific init keys/files)
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
---
qga/main.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/qga/main.c b/qga/main.c
index f6dbb3e..9026c9a 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -56,6 +56,7 @@
#define QGA_FSFREEZE_HOOK_DEFAULT CONFIG_QEMU_CONFDIR "/fsfreeze-hook"
#endif
#define QGA_SENTINEL_BYTE 0xFF
+#define QGA_CONF_DEFAULT CONFIG_QEMU_CONFDIR G_DIR_SEPARATOR_S "qemu-ga.conf"
static struct {
const char *state_dir;
@@ -951,6 +952,7 @@ static char *state_dir;
#ifdef _WIN32
static const char *service;
#endif
+static char *bliststr;
static GList *blacklist;
static int daemonize, dumpconf;
static GLogLevelFlags log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL;
@@ -959,6 +961,7 @@ static void dump_config(void)
{
gchar *bl = list_join(blacklist, ',');
+ printf("### Read from configuration file: %s ###\n", QGA_CONF_DEFAULT);
printf("[general]\n");
printf("daemonize = %d\n", daemonize);
printf("pidfile = %s\n", pid_filepath);
@@ -974,6 +977,71 @@ static void dump_config(void)
g_free(bl);
}
+static void load_system_config(void)
+{
+ GError *gerr = NULL;
+ GKeyFile *keyfile;
+
+ /* read system config */
+ keyfile = g_key_file_new();
+ if (!g_key_file_load_from_file(keyfile, QGA_CONF_DEFAULT, 0, &gerr)) {
+ goto end;
+ }
+ if (g_key_file_has_key(keyfile, "general", "daemon", NULL)) {
+ daemonize =
+ g_key_file_get_boolean(keyfile, "general", "daemon", &gerr);
+ }
+ if (g_key_file_has_key(keyfile, "general", "method", NULL)) {
+ method =
+ g_key_file_get_string(keyfile, "general", "method", &gerr);
+ }
+ if (g_key_file_has_key(keyfile, "general", "path", NULL)) {
+ device_path =
+ g_key_file_get_string(keyfile, "general", "path", &gerr);
+ }
+ if (g_key_file_has_key(keyfile, "general", "logfile", NULL)) {
+ log_filepath =
+ g_key_file_get_string(keyfile, "general", "logfile", &gerr);
+ }
+ if (g_key_file_has_key(keyfile, "general", "pidfile", NULL)) {
+ pid_filepath =
+ g_key_file_get_string(keyfile, "general", "pidfile", &gerr);
+ }
+#ifdef CONFIG_FSFREEZE
+ if (g_key_file_has_key(keyfile, "general", "fsfreeze-hook", NULL)) {
+ fsfreeze_hook =
+ g_key_file_get_string(keyfile,
+ "general", "fsfreeze-hook", &gerr);
+ }
+#endif
+ if (g_key_file_has_key(keyfile, "general", "statedir", NULL)) {
+ state_dir =
+ g_key_file_get_string(keyfile, "general", "statedir", &gerr);
+ }
+ if (g_key_file_has_key(keyfile, "general", "verbose", NULL) &&
+ g_key_file_get_boolean(keyfile, "general", "verbose", &gerr)) {
+ /* enable all log levels */
+ log_level = G_LOG_LEVEL_MASK;
+ }
+ if (g_key_file_has_key(keyfile, "general", "blacklist", NULL)) {
+ bliststr =
+ g_key_file_get_string(keyfile, "general", "blacklist", &gerr);
+ blacklist = g_list_concat(blacklist, split_list(bliststr, ','));
+ }
+
+end:
+ if (keyfile) {
+ g_key_file_free(keyfile);
+ }
+ if (gerr &&
+ !(gerr->domain == G_FILE_ERROR && gerr->code == G_FILE_ERROR_NOENT)) {
+ g_critical("error loading configuration from path: %s, %s",
+ QGA_CONF_DEFAULT, gerr->message);
+ exit(EXIT_FAILURE);
+ }
+ g_clear_error(&gerr);
+}
+
static void option_parse(int argc, char **argv)
{
const char *sopt = "hVvdm:p:l:f:F::b:s:t:D";
@@ -1216,6 +1284,7 @@ int main(int argc, char **argv)
module_call_init(MODULE_INIT_QAPI);
init_dfl_pathnames();
+ load_system_config();
option_parse(argc, argv);
if (pid_filepath == NULL) {
@@ -1283,6 +1352,7 @@ end:
#ifdef CONFIG_FSFREEZE
g_free(fsfreeze_hook);
#endif
+ g_free(bliststr);
g_free(s);
return ret;
--
2.4.3
next prev parent reply other threads:[~2015-07-01 11:48 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-01 11:47 [Qemu-devel] [PATCH 00/12] qemu-ga: add a configuration file Marc-André Lureau
2015-07-01 11:47 ` [Qemu-devel] [PATCH 01/12] qga: misc spelling Marc-André Lureau
2015-07-30 15:05 ` Eric Blake
2015-08-25 18:17 ` Denis V. Lunev
2015-07-01 11:47 ` [Qemu-devel] [PATCH 02/12] qga: use exit() when parsing options Marc-André Lureau
2015-07-31 14:34 ` Eric Blake
2015-08-25 20:20 ` Denis V. Lunev
2015-07-01 11:47 ` [Qemu-devel] [PATCH 03/12] qga: move string split in seperate function Marc-André Lureau
2015-08-25 15:50 ` Michael Roth
2015-07-01 11:47 ` [Qemu-devel] [PATCH 04/12] qga: rename 'path' to 'device_path' Marc-André Lureau
2015-08-25 15:55 ` Michael Roth
2015-08-25 22:00 ` Marc-André Lureau
2015-07-01 11:47 ` [Qemu-devel] [PATCH 05/12] qga: copy argument strings Marc-André Lureau
2015-07-01 11:47 ` [Qemu-devel] [PATCH 06/12] qga: move option parsing to seperate function Marc-André Lureau
2015-08-25 16:24 ` Michael Roth
2015-08-25 21:59 ` Marc-André Lureau
2015-07-01 11:47 ` [Qemu-devel] [PATCH 07/12] qga: fill default options in main() Marc-André Lureau
2015-08-25 16:04 ` Michael Roth
2015-07-01 11:47 ` [Qemu-devel] [PATCH 08/12] qga: move agent run in a seperate function Marc-André Lureau
2015-08-25 16:51 ` Michael Roth
2015-08-25 21:59 ` Marc-André Lureau
2015-07-01 11:47 ` [Qemu-devel] [PATCH 09/12] qga: free a bit more Marc-André Lureau
2015-07-01 11:47 ` [Qemu-devel] [PATCH 10/12] qga: add --dump-conf option Marc-André Lureau
2015-08-25 17:11 ` Michael Roth
2015-08-25 21:58 ` Marc-André Lureau
2015-07-01 11:47 ` Marc-André Lureau [this message]
2015-07-01 11:47 ` [Qemu-devel] [PATCH 12/12] qga: start a man page Marc-André Lureau
2015-08-25 17:43 ` Michael Roth
2015-08-25 21:57 ` Marc-André Lureau
2015-07-29 13:41 ` [Qemu-devel] [PATCH 00/12] qemu-ga: add a configuration file Marc-André Lureau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1435751267-26378-12-git-send-email-marcandre.lureau@gmail.com \
--to=marcandre.lureau@gmail.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).