From: Paul Kocialkowski <paul.kocialkowski@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t 1/2] lib/igt_core: Move all config-related parsing to common_init_config
Date: Thu, 20 Jul 2017 17:11:26 +0300 [thread overview]
Message-ID: <20170720141127.14974-1-paul.kocialkowski@linux.intel.com> (raw)
This moves all the pieces related to config parsing to the dedicated
function for this purpose, renamed common_init_config for consistency.
It allows making the common_init function less big and more readable.
Signed-off-by: Paul Kocialkowski <paul.kocialkowski@linux.intel.com>
---
lib/igt_core.c | 77 ++++++++++++++++++++++++++--------------------------------
1 file changed, 35 insertions(+), 42 deletions(-)
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 03d9a5bf..e25276fc 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -622,13 +622,35 @@ static void oom_adjust_for_doom(void)
}
#ifdef HAVE_GLIB
-static int config_parse(void)
+static void common_init_config(void)
{
+ char *key_file_env = NULL;
+ char *key_file_loc = NULL;
GError *error = NULL;
- int rc;
+ int ret;
- if (!igt_key_file)
- return 0;
+ /* Determine igt config path */
+ key_file_env = getenv("IGT_CONFIG_PATH");
+ if (key_file_env) {
+ key_file_loc = key_file_env;
+ } else {
+ key_file_loc = malloc(100);
+ snprintf(key_file_loc, 100, "%s/.igtrc", g_get_home_dir());
+ }
+
+ /* Load igt config file */
+ igt_key_file = g_key_file_new();
+ ret = g_key_file_load_from_file(igt_key_file, key_file_loc,
+ G_KEY_FILE_NONE, &error);
+ if (error && error->code == G_KEY_FILE_ERROR) {
+ g_error_free(error);
+ g_key_file_free(igt_key_file);
+ igt_key_file = NULL;
+
+ goto out;
+ }
+
+ g_clear_error(&error);
frame_dump_path = getenv("IGT_FRAME_DUMP_PATH");
@@ -639,19 +661,18 @@ static int config_parse(void)
g_clear_error(&error);
- rc = g_key_file_get_integer(igt_key_file, "DUT", "SuspendResumeDelay",
- &error);
- if (error && error->code == G_KEY_FILE_ERROR_INVALID_VALUE) {
- g_error_free(error);
- return -2;
- }
+ ret = g_key_file_get_integer(igt_key_file, "DUT", "SuspendResumeDelay",
+ &error);
+ assert(!error || error->code != G_KEY_FILE_ERROR_INVALID_VALUE);
g_clear_error(&error);
- if (rc != 0)
- igt_set_autoresume_delay(rc);
+ if (ret != 0)
+ igt_set_autoresume_delay(ret);
- return 0;
+out:
+ if (!key_file_env && key_file_loc)
+ free(key_file_loc);
}
#endif
@@ -678,9 +699,6 @@ static int common_init(int *argc, char **argv,
int extra_opt_count;
int all_opt_count;
int ret = 0;
- char *key_file_loc = NULL;
- char *key_file_env = NULL;
- GError *error = NULL;
const char *env;
if (!isatty(STDOUT_FILENO) || getenv("IGT_PLAIN_OUTPUT"))
@@ -802,36 +820,11 @@ static int common_init(int *argc, char **argv,
}
}
- key_file_env = getenv("IGT_CONFIG_PATH");
- if (key_file_env) {
- key_file_loc = key_file_env;
- } else {
- key_file_loc = malloc(100);
- snprintf(key_file_loc, 100, "%s/.igtrc", g_get_home_dir());
- }
-
#ifdef HAVE_GLIB
- igt_key_file = g_key_file_new();
- ret = g_key_file_load_from_file(igt_key_file, key_file_loc,
- G_KEY_FILE_NONE, &error);
- if (error && error->code == G_KEY_FILE_ERROR) {
- g_error_free(error);
- g_key_file_free(igt_key_file);
- igt_key_file = NULL;
- ret = -2;
-
- goto out;
- }
-
- g_clear_error(&error);
-
- ret = config_parse();
+ common_init_config();
#endif
out:
- if (!key_file_env && key_file_loc)
- free(key_file_loc);
-
free(short_opts);
free(combined_opts);
--
2.13.2
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next reply other threads:[~2017-07-20 14:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 14:11 Paul Kocialkowski [this message]
2017-07-20 14:11 ` [PATCH i-g-t 2/2] lib/igt_core: Split out env-related handling to common_init_env Paul Kocialkowski
2017-07-20 17:24 ` [PATCH i-g-t 1/2] lib/igt_core: Move all config-related parsing to common_init_config Lyude Paul
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=20170720141127.14974-1-paul.kocialkowski@linux.intel.com \
--to=paul.kocialkowski@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.