Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/procstat/procstat_sigs.c
Show All 29 Lines | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/user.h> | #include <sys/user.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdint.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <libprocstat.h> | #include <libprocstat.h> | ||||
#include "procstat.h" | #include "procstat.h" | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | procstat_sigs(struct procstat *prstat __unused, struct kinfo_proc *kipp) | ||||
} | } | ||||
xo_close_container("signals"); | xo_close_container("signals"); | ||||
} | } | ||||
void | void | ||||
procstat_threads_sigs(struct procstat *procstat, struct kinfo_proc *kipp) | procstat_threads_sigs(struct procstat *procstat, struct kinfo_proc *kipp) | ||||
{ | { | ||||
struct kinfo_proc *kip; | struct kinfo_proc *kip; | ||||
uintmax_t fastsigblk_addr; | |||||
int error, name[4], j, has_fastsigblk_addr; | |||||
pid_t pid; | |||||
int j; | int j; | ||||
unsigned int count, i; | unsigned int count, i; | ||||
size_t len; | |||||
char *threadid; | char *threadid; | ||||
if ((procstat_opts & PS_OPT_NOHEADER) == 0) | if ((procstat_opts & PS_OPT_NOHEADER) == 0) | ||||
xo_emit("{T:/%5s %6s %-16s %-7s %4s}\n", "PID", "TID", "COMM", | xo_emit("{T:/%5s %6s %-16s %-7s %4s %-18s}\n", "PID", "TID", "COMM", | ||||
"SIG", "FLAGS"); | "SIG", "FLAGS", "FSIGBLK"); | ||||
kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD, | kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD, | ||||
kipp->ki_pid, &count); | kipp->ki_pid, &count); | ||||
if (kip == NULL) | if (kip == NULL) | ||||
return; | return; | ||||
xo_emit("{ek:process_id/%5d/%d}", kipp->ki_pid); | xo_emit("{ek:process_id/%5d/%d}", kipp->ki_pid); | ||||
xo_emit("{e:command/%-16s/%s}", kipp->ki_comm); | xo_emit("{e:command/%-16s/%s}", kipp->ki_comm); | ||||
xo_open_container("threads"); | xo_open_container("threads"); | ||||
kinfo_proc_sort(kip, count); | kinfo_proc_sort(kip, count); | ||||
for (i = 0; i < count; i++) { | for (i = 0; i < count; i++) { | ||||
kipp = &kip[i]; | kipp = &kip[i]; | ||||
len = sizeof(fastsigblk_addr); | |||||
name[2] = KERN_PROC_FASTSIGBLK; | |||||
name[3] = kipp->ki_tid; | |||||
error = sysctl(name, 4, &fastsigblk_addr, &len, NULL, 0); | |||||
if (error < 0) { | |||||
if (errno != ESRCH && errno != ENOTTY) { | |||||
warn("sysctl: kern.proc.fastsigblk: %d", | |||||
kipp->ki_tid); | |||||
} | |||||
has_fastsigblk_addr = 0; | |||||
} else | |||||
has_fastsigblk_addr = 1; | |||||
asprintf(&threadid, "%d", kipp->ki_tid); | asprintf(&threadid, "%d", kipp->ki_tid); | ||||
if (threadid == NULL) | if (threadid == NULL) | ||||
xo_errc(1, ENOMEM, "Failed to allocate memory in " | xo_errc(1, ENOMEM, "Failed to allocate memory in " | ||||
"procstat_threads_sigs()"); | "procstat_threads_sigs()"); | ||||
xo_open_container(threadid); | xo_open_container(threadid); | ||||
xo_emit("{e:thread_id/%6d/%d}", kipp->ki_tid); | xo_emit("{e:thread_id/%6d/%d}", kipp->ki_tid); | ||||
xo_open_container("signals"); | xo_open_container("signals"); | ||||
for (j = 1; j <= _SIG_MAXSIG; j++) { | for (j = 1; j <= _SIG_MAXSIG; j++) { | ||||
xo_emit("{dk:process_id/%5d/%d} ", kipp->ki_pid); | xo_emit("{dk:process_id/%5d/%d} ", kipp->ki_pid); | ||||
xo_emit("{d:thread_id/%6d/%d} ", kipp->ki_tid); | xo_emit("{d:thread_id/%6d/%d} ", kipp->ki_tid); | ||||
xo_emit("{d:command/%-16s/%s} ", kipp->ki_comm); | xo_emit("{d:command/%-16s/%s} ", kipp->ki_comm); | ||||
procstat_print_signame(j); | procstat_print_signame(j); | ||||
xo_emit(" "); | xo_emit(" "); | ||||
procstat_print_sig(&kipp->ki_siglist, j, 'P'); | procstat_print_sig(&kipp->ki_siglist, j, 'P'); | ||||
procstat_print_sig(&kipp->ki_sigmask, j, 'B'); | procstat_print_sig(&kipp->ki_sigmask, j, 'B'); | ||||
xo_emit(" "); | |||||
/* XXXKIB */ | |||||
xo_emit("{ek:%#jx/%#jx", has_fastsigblk_addr ? | |||||
(uintmax_t)fastsigblk_addr : -1); | |||||
procstat_close_signame(j); | procstat_close_signame(j); | ||||
xo_emit("\n"); | xo_emit("\n"); | ||||
} | } | ||||
xo_close_container("signals"); | xo_close_container("signals"); | ||||
xo_close_container(threadid); | xo_close_container(threadid); | ||||
free(threadid); | free(threadid); | ||||
} | } | ||||
xo_close_container("threads"); | xo_close_container("threads"); | ||||
procstat_freeprocs(procstat, kip); | procstat_freeprocs(procstat, kip); | ||||
} | } | ||||
brooks: I don't understand how this can work. uintmax_t is always __uint64_t, but for 32-bit ABIs the… | |||||
Done Inline ActionsRight, this should be uintptr_t. Thanks for noting. kib: Right, this should be uintptr_t. Thanks for noting. |
I don't understand how this can work. uintmax_t is always __uint64_t, but for 32-bit ABIs the sysctl outputs 32-bits.