Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/kdump/kdump.c
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#ifdef HAVE_LIBCASPER | #ifdef HAVE_LIBCASPER | ||||
#include <sys/nv.h> | #include <sys/nv.h> | ||||
#endif | #endif | ||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <capsicum_helpers.h> | |||||
#include <err.h> | #include <err.h> | ||||
#include <grp.h> | #include <grp.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <locale.h> | #include <locale.h> | ||||
#include <netdb.h> | #include <netdb.h> | ||||
#include <nl_types.h> | #include <nl_types.h> | ||||
#include <pwd.h> | #include <pwd.h> | ||||
#include <stddef.h> | #include <stddef.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <sysdecode.h> | #include <sysdecode.h> | ||||
#include <termios.h> | |||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <vis.h> | #include <vis.h> | ||||
#include "ktrace.h" | #include "ktrace.h" | ||||
#include "kdump_subr.h" | #include "kdump_subr.h" | ||||
#ifdef HAVE_LIBCASPER | #ifdef HAVE_LIBCASPER | ||||
#include <libcasper.h> | #include <libcasper.h> | ||||
Show All 19 Lines | |||||
void ktrcaprights(cap_rights_t *); | void ktrcaprights(cap_rights_t *); | ||||
void ktritimerval(struct itimerval *it); | void ktritimerval(struct itimerval *it); | ||||
void ktrsockaddr(struct sockaddr *); | void ktrsockaddr(struct sockaddr *); | ||||
void ktrstat(struct stat *); | void ktrstat(struct stat *); | ||||
void ktrstruct(char *, size_t); | void ktrstruct(char *, size_t); | ||||
void ktrcapfail(struct ktr_cap_fail *); | void ktrcapfail(struct ktr_cap_fail *); | ||||
void ktrfault(struct ktr_fault *); | void ktrfault(struct ktr_fault *); | ||||
void ktrfaultend(struct ktr_faultend *); | void ktrfaultend(struct ktr_faultend *); | ||||
void limitfd(int fd); | |||||
void usage(void); | void usage(void); | ||||
#define TIMESTAMP_NONE 0x0 | #define TIMESTAMP_NONE 0x0 | ||||
#define TIMESTAMP_ABSOLUTE 0x1 | #define TIMESTAMP_ABSOLUTE 0x1 | ||||
#define TIMESTAMP_ELAPSED 0x2 | #define TIMESTAMP_ELAPSED 0x2 | ||||
#define TIMESTAMP_RELATIVE 0x4 | #define TIMESTAMP_RELATIVE 0x4 | ||||
extern const char *signames[]; | extern const char *signames[]; | ||||
▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | if (cap_enter() < 0 && errno != ENOSYS) | ||||
err(1, "unable to enter capability mode"); | err(1, "unable to enter capability mode"); | ||||
} | } | ||||
#else | #else | ||||
if (resolv == 0) { | if (resolv == 0) { | ||||
if (cap_enter() < 0 && errno != ENOSYS) | if (cap_enter() < 0 && errno != ENOSYS) | ||||
err(1, "unable to enter capability mode"); | err(1, "unable to enter capability mode"); | ||||
} | } | ||||
#endif | #endif | ||||
limitfd(STDIN_FILENO); | if (caph_limit_stdio() == -1) | ||||
limitfd(STDOUT_FILENO); | err(1, "unable to limit stdio"); | ||||
limitfd(STDERR_FILENO); | |||||
TAILQ_INIT(&trace_procs); | TAILQ_INIT(&trace_procs); | ||||
drop_logged = 0; | drop_logged = 0; | ||||
while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) { | while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) { | ||||
if (ktr_header.ktr_type & KTR_DROP) { | if (ktr_header.ktr_type & KTR_DROP) { | ||||
ktr_header.ktr_type &= ~KTR_DROP; | ktr_header.ktr_type &= ~KTR_DROP; | ||||
if (!drop_logged && threads) { | if (!drop_logged && threads) { | ||||
printf( | printf( | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) { | ||||
default: | default: | ||||
printf("\n"); | printf("\n"); | ||||
break; | break; | ||||
} | } | ||||
if (tail) | if (tail) | ||||
fflush(stdout); | fflush(stdout); | ||||
} | } | ||||
return 0; | return 0; | ||||
} | |||||
void | |||||
limitfd(int fd) | |||||
{ | |||||
cap_rights_t rights; | |||||
unsigned long cmd; | |||||
cap_rights_init(&rights, CAP_FSTAT); | |||||
cmd = 0; | |||||
switch (fd) { | |||||
case STDIN_FILENO: | |||||
cap_rights_set(&rights, CAP_READ); | |||||
break; | |||||
case STDOUT_FILENO: | |||||
cap_rights_set(&rights, CAP_IOCTL, CAP_WRITE); | |||||
cmd = TIOCGETA; /* required by isatty(3) in printf(3) */ | |||||
break; | |||||
case STDERR_FILENO: | |||||
cap_rights_set(&rights, CAP_WRITE); | |||||
if (!suppressdata) { | |||||
cap_rights_set(&rights, CAP_IOCTL); | |||||
cmd = TIOCGWINSZ; | |||||
} | |||||
break; | |||||
default: | |||||
abort(); | |||||
} | |||||
if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS) | |||||
err(1, "unable to limit rights for descriptor %d", fd); | |||||
if (cmd != 0 && cap_ioctls_limit(fd, &cmd, 1) < 0 && errno != ENOSYS) | |||||
err(1, "unable to limit ioctls for descriptor %d", fd); | |||||
} | } | ||||
int | int | ||||
fread_tail(void *buf, int size, int num) | fread_tail(void *buf, int size, int num) | ||||
{ | { | ||||
int i; | int i; | ||||
while ((i = fread(buf, size, num, stdin)) == 0 && tail) { | while ((i = fread(buf, size, num, stdin)) == 0 && tail) { | ||||
▲ Show 20 Lines • Show All 1,420 Lines • Show Last 20 Lines |