From: Mike Yuan Date: Thu, 14 Dec 2023 15:41:06 +0000 (+0800) Subject: cgroup-util: check ferror() first X-Git-Tag: v256-rc1~1478^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=121b7054267d34e3f3ab1cbbbb1cc24ebc2d0ea4;p=thirdparty%2Fsystemd.git cgroup-util: check ferror() first Also, there's no need to set use errno_or_else(), since fscanf() is documented to set errno on error. --- diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 18b16ecc0e5..68b15846292 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -2141,15 +2141,14 @@ int cg_kernel_controllers(Set **ret) { _cleanup_free_ char *controller = NULL; int enabled = 0; - errno = 0; if (fscanf(f, "%ms %*i %*i %i", &controller, &enabled) != 2) { + if (ferror(f)) + return -errno; + if (feof(f)) break; - if (ferror(f)) - return errno_or_else(EIO); - return -EBADMSG; }