From 178ef27ad536b96d66e05b337b823c3418b254e2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 29 Mar 2018 08:30:38 -0700 Subject: [PATCH] switch_ioscheduler(): only remove the last character if it's a newline Signed-off-by: Bart Van Assche --- backend.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend.c b/backend.c index fe335b5e..f2d7cc36 100644 --- a/backend.c +++ b/backend.c @@ -1328,7 +1328,7 @@ static int init_io_u(struct thread_data *td) static int switch_ioscheduler(struct thread_data *td) { #ifdef FIO_HAVE_IOSCHED_SWITCH - char tmp[256], tmp2[128]; + char tmp[256], tmp2[128], *p; FILE *f; int ret; @@ -1372,9 +1372,11 @@ static int switch_ioscheduler(struct thread_data *td) } tmp[ret] = '\0'; /* - * either a list of io schedulers or "none\n" is expected. + * either a list of io schedulers or "none\n" is expected. Strip the + * trailing newline. */ - tmp[strlen(tmp) - 1] = '\0'; + p = tmp; + strsep(&p, "\n"); /* * Write to "none" entry doesn't fail, so check the result here. -- 2.25.1