summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-09-14 19:42:23 -0600
committerJens Axboe <axboe@kernel.dk>2020-09-14 19:42:23 -0600
commit260d1e6a23065a3141fd6cb4532294cedfcb2f4d (patch)
tree5d8e6acbdb4f3899e0ec875b3bc5044708706fb3
parent695611a9d4cd554d44d8b2ec5da2811061950a2e (diff)
parentb7e4a53ce230f0118d5b45206f8c4f0319f4d377 (diff)
downloadfio-260d1e6a23065a3141fd6cb4532294cedfcb2f4d.tar.gz
fio-260d1e6a23065a3141fd6cb4532294cedfcb2f4d.tar.bz2
Merge branch 'backend' of https://github.com/bvanassche/fio into master
* 'backend' of https://github.com/bvanassche/fio: backend: Use asprintf() instead of strlen() + sprintf() backend: Remove two superfluous casts
-rw-r--r--backend.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/backend.c b/backend.c
index 05453ae2..f91f3caf 100644
--- a/backend.c
+++ b/backend.c
@@ -1458,16 +1458,17 @@ static bool keep_running(struct thread_data *td)
return false;
}
-static int exec_string(struct thread_options *o, const char *string, const char *mode)
+static int exec_string(struct thread_options *o, const char *string,
+ const char *mode)
{
- size_t newlen = strlen(string) + strlen(o->name) + strlen(mode) + 13 + 1;
int ret;
char *str;
- str = malloc(newlen);
- sprintf(str, "%s > %s.%s.txt 2>&1", string, o->name, mode);
+ if (asprintf(&str, "%s > %s.%s.txt 2>&1", string, o->name, mode) < 0)
+ return -1;
- log_info("%s : Saving output of %s in %s.%s.txt\n",o->name, mode, o->name, mode);
+ log_info("%s : Saving output of %s in %s.%s.txt\n", o->name, mode,
+ o->name, mode);
ret = system(str);
if (ret == -1)
log_err("fio: exec of cmd <%s> failed\n", str);
@@ -1731,7 +1732,7 @@ static void *thread_main(void *data)
if (!init_random_map(td))
goto err;
- if (o->exec_prerun && exec_string(o, o->exec_prerun, (const char *)"prerun"))
+ if (o->exec_prerun && exec_string(o, o->exec_prerun, "prerun"))
goto err;
if (o->pre_read && !pre_read_files(td))
@@ -1890,7 +1891,7 @@ static void *thread_main(void *data)
rate_submit_exit(td);
if (o->exec_postrun)
- exec_string(o, o->exec_postrun, (const char *)"postrun");
+ exec_string(o, o->exec_postrun, "postrun");
if (exitall_on_terminate || (o->exitall_error && td->error))
fio_terminate_threads(td->groupid, td->o.exit_what);