Module Name:    src
Committed By:   ozaki-r
Date:           Wed Feb 18 03:07:56 UTC 2015

Modified Files:
        src/external/cddl/osnet/dist/lib/libdtrace/common: dt_subr.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 \
    src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c
diff -u src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c:1.9 src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c:1.10
--- src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c:1.9	Sat Feb  7 20:30:03 2015
+++ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c	Wed Feb 18 03:07:56 2015
@@ -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 @@ dt_ioctl(dtrace_hdl_t *dtp, u_long val, 
 	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 @@ dt_status(dtrace_hdl_t *dtp, processorid
 #if defined(sun)
 		return (p_online(cpu, P_STATUS));
 #else
-		return 1;
+		return cpu_online(cpu) ? 1 : -1;
 #endif
 	}
 

Reply via email to