summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2015-06-01 18:05:30 +0000
committerjhb <jhb@FreeBSD.org>2015-06-01 18:05:30 +0000
commited437ec23ce9e663b9b89d839cade53697620378 (patch)
tree060daaec3e5160ed5404cdd5b1cef72f80d80201 /usr.sbin
parent7a2aa2a780fad093e89f575f957bc61e536735c4 (diff)
downloadFreeBSD-src-ed437ec23ce9e663b9b89d839cade53697620378.zip
FreeBSD-src-ed437ec23ce9e663b9b89d839cade53697620378.tar.gz
MFC 282643:
Use the kern.bootfile sysctl to set the default kernel path rather than hardcoding /boot/kernel. This allows pmcstat(8) to work without -k when using nextboot -k or 'boot foo' at the loader to boot alternate kernels. Sponsored by: Norse Corp, Inc.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pmcstat/pmcstat.87
-rw-r--r--usr.sbin/pmcstat/pmcstat.c59
2 files changed, 36 insertions, 30 deletions
diff --git a/usr.sbin/pmcstat/pmcstat.8 b/usr.sbin/pmcstat/pmcstat.8
index 81572b2..af54cea 100644
--- a/usr.sbin/pmcstat/pmcstat.8
+++ b/usr.sbin/pmcstat/pmcstat.8
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd Oct 27, 2014
+.Dd May 8, 2015
.Dt PMCSTAT 8
.Os
.Sh NAME
@@ -279,8 +279,9 @@ Set the pathname of the kernel directory to argument
This directory specifies where
.Nm
should look for the kernel and its modules.
-The default is
-.Pa /boot/kernel .
+The default is to use the path of the running kernel obtained from the
+.Va kern.bootfile
+sysctl.
.It Fl l Ar secs
Set system-wide performance measurement duration for
.Ar secs
diff --git a/usr.sbin/pmcstat/pmcstat.c b/usr.sbin/pmcstat/pmcstat.c
index 94d0a08..05dffaa 100644
--- a/usr.sbin/pmcstat/pmcstat.c
+++ b/usr.sbin/pmcstat/pmcstat.c
@@ -557,7 +557,7 @@ main(int argc, char **argv)
int c, check_driver_stats, current_sampling_count;
int do_callchain, do_descendants, do_logproccsw, do_logprocexit;
int do_print, do_read;
- size_t dummy;
+ size_t len;
int graphdepth;
int pipefd[2], rfd;
int use_cumulative_counts;
@@ -586,7 +586,6 @@ main(int argc, char **argv)
args.pa_verbosity = 1;
args.pa_logfd = -1;
args.pa_fsroot = "";
- args.pa_kernel = strdup("/boot/kernel");
args.pa_samplesdir = ".";
args.pa_printfile = stderr;
args.pa_graphdepth = DEFAULT_CALLGRAPH_DEPTH;
@@ -610,12 +609,20 @@ main(int argc, char **argv)
ev = NULL;
CPU_ZERO(&cpumask);
+ /* Default to using the running system kernel. */
+ len = 0;
+ if (sysctlbyname("kern.bootfile", NULL, &len, NULL, 0) == -1)
+ err(EX_OSERR, "ERROR: Cannot determine path of running kernel");
+ args.pa_kernel = malloc(len + 1);
+ if (sysctlbyname("kern.bootfile", args.pa_kernel, &len, NULL, 0) == -1)
+ err(EX_OSERR, "ERROR: Cannot determine path of running kernel");
+
/*
* The initial CPU mask specifies all non-halted CPUS in the
* system.
*/
- dummy = sizeof(int);
- if (sysctlbyname("hw.ncpu", &ncpu, &dummy, NULL, 0) < 0)
+ len = sizeof(int);
+ if (sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0) < 0)
err(EX_OSERR, "ERROR: Cannot determine the number of CPUs");
for (hcpu = 0; hcpu < ncpu; hcpu++)
CPU_SET(hcpu, &cpumask);
@@ -1061,33 +1068,31 @@ main(int argc, char **argv)
);
/*
- * Check if "-k kerneldir" was specified, and if whether
- * 'kerneldir' actually refers to a file. If so, use
- * `dirname path` to determine the kernel directory.
+ * Check if 'kerneldir' refers to a file rather than a
+ * directory. If so, use `dirname path` to determine the
+ * kernel directory.
*/
- if (args.pa_flags & FLAG_HAS_KERNELPATH) {
- (void) snprintf(buffer, sizeof(buffer), "%s%s", args.pa_fsroot,
- args.pa_kernel);
+ (void) snprintf(buffer, sizeof(buffer), "%s%s", args.pa_fsroot,
+ args.pa_kernel);
+ if (stat(buffer, &sb) < 0)
+ err(EX_OSERR, "ERROR: Cannot locate kernel \"%s\"",
+ buffer);
+ if (!S_ISREG(sb.st_mode) && !S_ISDIR(sb.st_mode))
+ errx(EX_USAGE, "ERROR: \"%s\": Unsupported file type.",
+ buffer);
+ if (!S_ISDIR(sb.st_mode)) {
+ tmp = args.pa_kernel;
+ args.pa_kernel = strdup(dirname(args.pa_kernel));
+ free(tmp);
+ (void) snprintf(buffer, sizeof(buffer), "%s%s",
+ args.pa_fsroot, args.pa_kernel);
if (stat(buffer, &sb) < 0)
- err(EX_OSERR, "ERROR: Cannot locate kernel \"%s\"",
+ err(EX_OSERR, "ERROR: Cannot stat \"%s\"",
buffer);
- if (!S_ISREG(sb.st_mode) && !S_ISDIR(sb.st_mode))
- errx(EX_USAGE, "ERROR: \"%s\": Unsupported file type.",
+ if (!S_ISDIR(sb.st_mode))
+ errx(EX_USAGE,
+ "ERROR: \"%s\" is not a directory.",
buffer);
- if (!S_ISDIR(sb.st_mode)) {
- tmp = args.pa_kernel;
- args.pa_kernel = strdup(dirname(args.pa_kernel));
- free(tmp);
- (void) snprintf(buffer, sizeof(buffer), "%s%s",
- args.pa_fsroot, args.pa_kernel);
- if (stat(buffer, &sb) < 0)
- err(EX_OSERR, "ERROR: Cannot stat \"%s\"",
- buffer);
- if (!S_ISDIR(sb.st_mode))
- errx(EX_USAGE,
- "ERROR: \"%s\" is not a directory.",
- buffer);
- }
}
/*
OpenPOWER on IntegriCloud