From: Bruce Cran Date: Mon, 20 Feb 2012 06:59:06 +0000 (+0100) Subject: nice() error handling X-Git-Tag: fio-2.0.4~24 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=649c10c59b016ae8586e54746d3761bc6df33c9b;p=fio.git nice() error handling I've attached a patch which fixes a potential issue I noticed while reading the POSIX specs: nice() can succeed and return -1, so it's recommended to set errno to 0 and check it afterwards: "As -1 is a permissible return value in a successful situation, an application wishing to check for error situations should set errno to 0, then call nice(), and if it returns -1, check to see whether errno is non-zero." Signed-off-by: Jens Axboe --- diff --git a/backend.c b/backend.c index e567ad5e..6e0e4424 100644 --- a/backend.c +++ b/backend.c @@ -1019,7 +1019,8 @@ static void *thread_main(void *data) if (td->o.cgroup_weight && cgroup_setup(td, cgroup_list, &cgroup_mnt)) goto err; - if (nice(td->o.nice) == -1) { + errno = 0; + if (nice(td->o.nice) == -1 && errno != 0) { td_verror(td, errno, "nice"); goto err; }