Add procstat(1) sigfastblock command to show process sigfastblock word address.

Tested by:	pho
Disscussed with:	cem, emaste, jilles
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D12773
This commit is contained in:
Konstantin Belousov 2020-02-09 12:30:50 +00:00
parent 48fcb46311
commit 24d57fa83e
3 changed files with 67 additions and 0 deletions

View File

@ -94,6 +94,8 @@ static const struct procstat_cmd cmd_table[] = {
PS_CMP_NORMAL },
{ "rusage", "rusage", "[-Ht]", &procstat_rusage, &cmdopt_rusage,
PS_CMP_NORMAL },
{ "sigfastblock", "sigfastblock", NULL, &procstat_sigfastblock,
&cmdopt_none, PS_CMP_NORMAL },
{ "signal", "signals", "[-n]", &procstat_sigs, &cmdopt_signals,
PS_CMP_PLURAL | PS_CMP_SUBSTR },
{ "thread", "threads", NULL, &procstat_threads, &cmdopt_none,

View File

@ -67,6 +67,8 @@ void procstat_kstack(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_ptlwpinfo(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_rlimit(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_rusage(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_sigfastblock(struct procstat *procstat,
struct kinfo_proc *kipp);
void procstat_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_threads(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_threads_sigs(struct procstat *prstat, struct kinfo_proc *kipp);

View File

@ -37,6 +37,8 @@
#include <err.h>
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -163,6 +165,7 @@ procstat_threads_sigs(struct procstat *procstat, struct kinfo_proc *kipp)
xo_open_container(threadid);
xo_emit("{e:thread_id/%6d/%d}", kipp->ki_tid);
xo_open_container("signals");
for (j = 1; j <= _SIG_MAXSIG; j++) {
xo_emit("{dk:process_id/%5d/%d} ", kipp->ki_pid);
xo_emit("{d:thread_id/%6d/%d} ", kipp->ki_tid);
@ -181,3 +184,63 @@ procstat_threads_sigs(struct procstat *procstat, struct kinfo_proc *kipp)
xo_close_container("threads");
procstat_freeprocs(procstat, kip);
}
void
procstat_sigfastblock(struct procstat *procstat, struct kinfo_proc *kipp)
{
struct kinfo_proc *kip;
char *threadid;
uintptr_t sigfastblk_addr;
int error, name[4];
unsigned int count, i;
size_t len;
bool has_sigfastblk_addr;
if ((procstat_opts & PS_OPT_NOHEADER) == 0)
xo_emit("{T:/%5s %6s %-16s %-16s}\n", "PID", "TID",
"COMM", "SIGFBLK");
kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD,
kipp->ki_pid, &count);
if (kip == NULL)
return;
xo_emit("{ek:process_id/%5d/%d}", kipp->ki_pid);
xo_emit("{e:command/%-16s/%s}", kipp->ki_comm);
xo_open_container("threads");
kinfo_proc_sort(kip, count);
for (i = 0; i < count; i++) {
kipp = &kip[i];
len = sizeof(sigfastblk_addr);
name[0] = CTL_KERN;
name[1] = KERN_PROC;
name[2] = KERN_PROC_SIGFASTBLK;
name[3] = kipp->ki_tid;
error = sysctl(name, 4, &sigfastblk_addr, &len, NULL, 0);
if (error < 0) {
if (errno != ESRCH && errno != ENOTTY) {
warn("sysctl: kern.proc.fastsigblk: %d",
kipp->ki_tid);
}
has_sigfastblk_addr = false;
} else
has_sigfastblk_addr = true;
asprintf(&threadid, "%d", kipp->ki_tid);
if (threadid == NULL)
xo_errc(1, ENOMEM, "Failed to allocate memory in "
"procstat_sigfastblock()");
xo_open_container(threadid);
xo_emit("{dk:process_id/%5d/%d} ", kipp->ki_pid);
xo_emit("{d:thread_id/%6d/%d} ", kipp->ki_tid);
xo_emit("{d:command/%-16s/%s} ", kipp->ki_comm);
xo_emit("{e:sigfastblock/%#-16jx/%#jx}", has_sigfastblk_addr ?
(uintmax_t)sigfastblk_addr : (uintmax_t)-1);
xo_emit("{d:sigfastblock/%#-16jx/%#jx}", has_sigfastblk_addr ?
(uintmax_t)sigfastblk_addr : (uintmax_t)-1);
xo_emit("\n");
xo_close_container(threadid);
free(threadid);
}
xo_close_container("threads");
procstat_freeprocs(procstat, kip);
}