From c0821a08db2fd3e37e16db73c3c4c9c7ff601e88 Mon Sep 17 00:00:00 2001 From: Andrey Kuzmin Date: Sat, 13 Feb 2016 12:31:00 -0700 Subject: [PATCH] Allow for the include file specification to be relative. Simplifies include file grouping, with same directory file included via file name. Checked only if the lookup by the file name specified fails. Signed-off-by: Jens Axboe --- init.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/init.c b/init.c index 5ee40823..c7ce2cc0 100644 --- a/init.c +++ b/init.c @@ -1773,15 +1773,48 @@ int __parse_jobs_ini(struct thread_data *td, strip_blank_end(p); if (!strncmp(p, "include", strlen("include"))) { - char *filename = p + strlen("include") + 1; + char *filename = p + strlen("include") + 1, + *ts, *full_fn = NULL; - if ((ret = __parse_jobs_ini(td, filename, - is_buf, stonewall_flag, type, 1, - name, &opts, &alloc_opts, &num_opts))) { - log_err("Error %d while parsing include file %s\n", + /* + * Allow for the include filename + * specification to be relative. + */ + if (access(filename, F_OK) && + (ts = strrchr(file, '/'))) { + int len = ts - file + + strlen(filename) + 2; + + if (!(full_fn = calloc(1, len))) { + ret = ENOMEM; + break; + } + + strncpy(full_fn, + file, (ts - file) + 1); + strncpy(full_fn + (ts - file) + 1, + filename, strlen(filename)); + full_fn[len - 1] = 0; + filename = full_fn; + } + + ret = __parse_jobs_ini(td, filename, is_buf, + stonewall_flag, type, 1, + name, &opts, + &alloc_opts, &num_opts); + + if (ret) { + log_err("Error %d while parsing " + "include file %s\n", ret, filename); - break; } + + if (full_fn) + free(full_fn); + + if (ret) + break; + continue; } -- 2.25.1