Don't use seeks on stdin for job file parsing
The previous commit added the support for reading a job file
from stdin, but this breaks when fio uses fgetpos/fsetpos on
the file handle. So remove the seeking.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/init.c b/init.c
index 45bd92f..dc5fed9 100644
--- a/init.c
+++ b/init.c
@@ -565,11 +565,11 @@
unsigned int global;
struct thread_data *td;
char *string, *name;
- fpos_t off;
FILE *f;
char *p;
int ret = 0, stonewall;
int first_sect = 1;
+ int skip_fgets = 0;
if (!strcmp(file, "-"))
f = stdin;
@@ -591,10 +591,17 @@
stonewall = stonewall_flag;
do {
- p = fgets(string, 4095, f);
- if (!p)
- break;
+ /*
+ * if skip_fgets is set, we already have loaded a line we
+ * haven't handled.
+ */
+ if (!skip_fgets) {
+ p = fgets(string, 4095, f);
+ if (!p)
+ break;
+ }
+ skip_fgets = 0;
strip_blank_front(&p);
strip_blank_end(p);
@@ -631,20 +638,23 @@
stonewall = 0;
}
- fgetpos(f, &off);
while ((p = fgets(string, 4096, f)) != NULL) {
if (is_empty_or_comment(p))
continue;
strip_blank_front(&p);
- if (p[0] == '[')
+ /*
+ * new section, break out and make sure we don't
+ * fgets() a new line at the top.
+ */
+ if (p[0] == '[') {
+ skip_fgets = 1;
break;
+ }
strip_blank_end(p);
- fgetpos(f, &off);
-
/*
* Don't break here, continue parsing options so we
* dump all the bad ones. Makes trial/error fixups
@@ -655,10 +665,9 @@
log_info("--%s ", p);
}
- if (!ret) {
- fsetpos(f, &off);
+ if (!ret)
ret = add_job(td, name, 0);
- } else {
+ else {
log_err("fio: job %s dropped\n", name);
put_job(td);
}