NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/39955 (cpuctl identifies non-existing CPUs)



This diff should fix it.


Index: usr.sbin/cpuctl/cpuctl.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/cpuctl/cpuctl.c,v
retrieving revision 1.10
diff -u -p -r1.10 cpuctl.c
--- usr.sbin/cpuctl/cpuctl.c    15 Oct 2008 08:22:06 -0000      1.10
+++ usr.sbin/cpuctl/cpuctl.c    19 Nov 2008 10:52:26 -0000
@@ -147,11 +147,12 @@ void
 cpu_identify(char **argv)
 {
        char name[32];
-       int id, np;
+       u_int id;
+       long np;
        cpuset_t *cpuset;
 
        id = getcpuid(argv);
-       snprintf(name, sizeof(name), "cpu%d", id);
+       snprintf(name, sizeof(name), "cpu%u", id);
 
        np = sysconf(_SC_NPROCESSORS_CONF);
        if (np != 0) {
@@ -179,10 +180,18 @@ getcpuid(char **argv)
 {
        char *argp;
        u_int id;
+       long np;
 
-       id = (int)strtoul(argv[0], &argp, 0);
+       id = (u_int)strtoul(argv[0], &argp, 0);
        if (*argp != '\0')
                usage();
+
+       np = sysconf(_SC_NPROCESSORS_CONF);
+       if (id >= np) {
+               err(EXIT_FAILURE, "More than %li CPUs not configured", np);
+               /* UNREACHED */
+       }
+
        return id;
 }
 


Home | Main Index | Thread Index | Old Index