From: Bart Van Assche Date: Thu, 29 Mar 2018 15:30:38 +0000 (-0700) Subject: switch_ioscheduler(): only remove the last character if it's a newline X-Git-Tag: fio-3.6~21^2 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=178ef27ad536b96d66e05b337b823c3418b254e2 switch_ioscheduler(): only remove the last character if it's a newline Signed-off-by: Bart Van Assche --- 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.