]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chcpu: handle ul_path_readf_s32() errors
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 1 Jun 2026 23:02:45 +0000 (19:02 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Wed, 24 Jun 2026 23:51:48 +0000 (19:51 -0400)
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
sys-utils/chcpu.c

index 0d2946222a2211c6e2fe8b90e3c52febbb32190d..f57859eca011245d9d2b9eb50ef6a256f3d12ea1 100644 (file)
@@ -79,7 +79,7 @@ enum {
 static int cpu_enable(struct chcpu_context *ctx, int enable)
 {
        int cpu;
-       int online, rc;
+       int online = -1, rc;
        int configured = -1;
        int fails = 0;
 
@@ -96,16 +96,21 @@ static int cpu_enable(struct chcpu_context *ctx, int enable)
                        fails++;
                        continue;
                }
-               if (ul_path_readf_s32(ctx->sys, &online, "cpu%d/online", cpu) == 0
-                   && online == 1
-                   && enable == 1) {
-                       printf(_("CPU %d is already enabled\n"), cpu);
+
+               if (ul_path_readf_s32(ctx->sys, &online, "cpu%d/online", cpu) != 0) {
+                       warnx(_("failed to read CPU %d state"), cpu);
+                       fails++;
                        continue;
                }
-               if (online == 0 && enable == 0) {
+
+               if (online == 1 && enable == 1) {
+                       printf(_("CPU %d is already enabled\n"), cpu);
+                       continue;
+               } else if (online == 0 && enable == 0) {
                        printf(_("CPU %d is already disabled\n"), cpu);
                        continue;
                }
+
                if (ul_path_accessf(ctx->sys, F_OK, "cpu%d/configure", cpu) == 0)
                        ul_path_readf_s32(ctx->sys, &configured, "cpu%d/configure", cpu);
                if (enable) {
@@ -178,7 +183,7 @@ static int cpu_set_dispatch(struct path_cxt *sys, int mode)
 static int cpu_configure(struct chcpu_context *ctx, int configure)
 {
        int cpu;
-       int rc, current;
+       int rc, current = -1;
        int fails = 0;
 
        for (cpu = 0; cpu < ctx->maxcpus; cpu++) {
@@ -194,7 +199,12 @@ static int cpu_configure(struct chcpu_context *ctx, int configure)
                        fails++;
                        continue;
                }
-               ul_path_readf_s32(ctx->sys, &current, "cpu%d/configure", cpu);
+               if (ul_path_readf_s32(ctx->sys, &current, "cpu%d/configure", cpu) != 0) {
+                       warnx(_("failed to read CPU %d configuration state"), cpu);
+                       fails++;
+                       continue;
+               }
+
                if (current == 1 && configure == 1) {
                        printf(_("CPU %d is already configured\n"), cpu);
                        continue;