From cd91e4825ba3963f1a87f5bd28d7cbac4f8bd3ad Mon Sep 17 00:00:00 2001 From: donny372 <51675586+donny372@users.noreply.github.com> Date: Tue, 18 Aug 2020 10:36:05 -0700 Subject: [PATCH] Avoid multiple instance read iolog from stdin. https://github.com/axboe/fio/pull/1019 added support for reading iolog from stdin, but we could have multiple instance of read iolog, only one can read from stdin. --- init.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/init.c b/init.c index 6ff7c68d..3d5e4695 100644 --- a/init.c +++ b/init.c @@ -1838,6 +1838,7 @@ static int __parse_jobs_ini(struct thread_data *td, int nested, char *name, char ***popts, int *aopts, int *nopts) { bool global = false; + bool stdin_occupied = false; char *string; FILE *f; char *p; @@ -1854,9 +1855,10 @@ static int __parse_jobs_ini(struct thread_data *td, if (is_buf) f = NULL; else { - if (!strcmp(file, "-")) + if (!strcmp(file, "-")) { f = stdin; - else + stdin_occupied = true; + } else f = fopen(file, "r"); if (!f) { @@ -2059,15 +2061,17 @@ static int __parse_jobs_ini(struct thread_data *td, ret = fio_options_parse(td, opts, num_opts); - if (!ret) { - if (!strcmp(file, "-") && td->o.read_iolog_file != NULL) { - char *fname = get_name_by_idx(td->o.read_iolog_file, - td->subjob_number); - if (!strcmp(fname, "-")) { - log_err("fio: we can't read both iolog " - "and job file from stdin.\n"); + if (!ret && td->o.read_iolog_file != NULL) { + char *fname = get_name_by_idx(td->o.read_iolog_file, + td->subjob_number); + if (!strcmp(fname, "-")) { + if (stdin_occupied) { + log_err("fio: only one user (read_iolog_file/job " + "file) of stdin is permitted at once but " + "more than one was found.\n"); ret = 1; } + stdin_occupied = true; } } if (!ret) { -- 2.25.1