]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: check ferror() first
authorMike Yuan <me@yhndnzj.com>
Thu, 14 Dec 2023 15:41:06 +0000 (23:41 +0800)
committerMike Yuan <me@yhndnzj.com>
Fri, 15 Dec 2023 13:21:17 +0000 (21:21 +0800)
Also, there's no need to set use errno_or_else(), since fscanf() is
documented to set errno on error.

src/basic/cgroup-util.c

index 18b16ecc0e5c5786024568b9c11a2859f9aee547..68b1584629219f274894c61d031a57246e19a417 100644 (file)
@@ -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;
                 }