Allow for the include file specification to be relative.
authorAndrey Kuzmin <andrey.v.kuzmin@gmail.com>
Sat, 13 Feb 2016 19:31:00 +0000 (12:31 -0700)
committerJens Axboe <axboe@fb.com>
Sat, 13 Feb 2016 19:31:00 +0000 (12:31 -0700)
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 <axboe@fb.com>
init.c

diff --git a/init.c b/init.c
index 5ee408239eee29cf0942773a2bcd760bde2a2a80..c7ce2cc0df2c7858ac75e4db962aa633b3566b2a 100644 (file)
--- 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;
                        }