Source-Changes-HG archive

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

[src/trunk]: src/external/cddl/osnet/dist/lib/libdtrace/common Don't return s...



details:   https://anonhg.NetBSD.org/src/rev/db15e9e08dec
branches:  trunk
changeset: 336213:db15e9e08dec
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Feb 18 03:07:56 2015 +0000

description:
Don't return success when the target CPU is offline

dt_status originally expected the behavior.

This fixes a segfault happens in dt_aggregate_go (a user of dt_status)
that depends on the behavior.

diffstat:

 external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c |  23 ++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diffs (51 lines):

diff -r 791ff3cdafd8 -r db15e9e08dec external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c
--- a/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c   Tue Feb 17 23:07:56 2015 +0000
+++ b/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c   Wed Feb 18 03:07:56 2015 +0000
@@ -41,10 +41,12 @@
 #else
 #include <sys/ioctl.h>
 #include <sys/sysctl.h>
+#include <sys/cpuio.h>
 #endif
 #include <assert.h>
 #include <libgen.h>
 #include <limits.h>
+#include <paths.h>
 
 #include <dt_impl.h>
 
@@ -497,6 +499,25 @@
        return (-1);
 }
 
+static bool
+cpu_online(processorid_t cpu)
+{
+       cpustate_t cs;
+       int fd, online = false;
+
+       if ((fd = open(_PATH_CPUCTL, O_RDONLY)) < 0)
+               return false;
+
+       cs.cs_id = cpu;
+       if (ioctl(fd, IOC_CPU_GETSTATE, &cs) == 0) {
+               if (cs.cs_online)
+                       online = true;
+       }
+
+       close(fd);
+       return online;
+}
+
 int
 dt_status(dtrace_hdl_t *dtp, processorid_t cpu)
 {
@@ -506,7 +527,7 @@
 #if defined(sun)
                return (p_online(cpu, P_STATUS));
 #else
-               return 1;
+               return cpu_online(cpu) ? 1 : -1;
 #endif
        }
 



Home | Main Index | Thread Index | Old Index