-/* $OpenBSD: kdump.c,v 1.93 2014/12/09 00:46:43 jsg Exp $ */
+/* $OpenBSD: kdump.c,v 1.94 2014/12/15 01:48:54 guenther Exp $ */
/*-
* Copyright (c) 1988, 1993
#include "extern.h"
int timestamp, decimal, iohex, fancy = 1, maxdata = INT_MAX;
-int needtid, resolv, tail;
+int needtid, tail;
char *tracefile = DEF_TRACEFILE;
struct ktr_header ktr_header;
pid_t pid_opt = -1;
static void ktrnamei(const char *, size_t);
static void ktrpsig(struct ktr_psig *);
static void ktrsyscall(struct ktr_syscall *, size_t);
-static const char *kresolvsysctl(int, int *, int);
+static const char *kresolvsysctl(int, const int *);
static void ktrsysret(struct ktr_sysret *);
static void ktruser(struct ktr_user *, size_t);
static void setemul(const char *);
def_emul = current = &emulations[0]; /* native */
- while ((ch = getopt(argc, argv, "e:f:dHlm:nrRp:Tt:xX")) != -1)
+ while ((ch = getopt(argc, argv, "e:f:dHlm:nRp:Tt:xX")) != -1)
switch (ch) {
case 'e':
setemul(optarg);
case 'p':
pid_opt = atoi(optarg);
break;
- case 'r':
- resolv = 1;
- break;
case 'R':
timestamp = 2; /* relative timestamp */
break;
ktracefacname,
itimername,
sigset,
+ uidname,
+ gidname,
};
enum {
Ktracefacname,
Itimername,
Sigset,
+ Uidname,
+ Gidname,
};
#define Pptr Phexlong
#define Psemid Pdecint
#define Pkey_t Pdecint
#define Pucount Pdecuint
-#define Puid_t Pdecuint
-#define Pgid_t Pdecuint
#define Chflagsname Phexlong /* to be added */
#define Sockprotoname Phexlong /* to be added */
#define Swapctlname Phexlong /* to be added */
[SYS_fchdir] = { Pfd },
[SYS_mknod] = { Ppath, Modename, Pdev_t },
[SYS_chmod] = { Ppath, Modename },
- [SYS_chown] = { Ppath, Puid_t, Pgid_t },
+ [SYS_chown] = { Ppath, Uidname, Gidname },
[SYS_break] = { Pptr },
[SYS_getrusage] = { Rusagewho, Pptr },
[SYS_mount] = { Pptr, Ppath, Mountflagsname, Pptr },
[SYS_unmount] = { Ppath, Mountflagsname },
- [SYS_setuid] = { Puid_t },
+ [SYS_setuid] = { Uidname },
[SYS_ptrace] = { Ptracedecode, Ppid_t, Pptr, Pdecint },
[SYS_recvmsg] = { Pfd, Pptr, Sendrecvflagsname },
[SYS_sendmsg] = { Pfd, Pptr, Sendrecvflagsname },
[SYS_getsockopt] = { Pfd, PASS_TWO, Sockoptlevelname, Pptr, Pptr },
[SYS_readv] = { Pfd, Pptr, Pcount },
[SYS_writev] = { Pfd, Pptr, Pcount },
- [SYS_fchown] = { Pfd, Puid_t, Pgid_t },
+ [SYS_fchown] = { Pfd, Uidname, Gidname },
[SYS_fchmod] = { Pfd, Modename },
- [SYS_setreuid] = { Puid_t, Puid_t },
- [SYS_setregid] = { Pgid_t, Pgid_t },
+ [SYS_setreuid] = { Uidname, Uidname },
+ [SYS_setregid] = { Gidname, Gidname },
[SYS_rename] = { Ppath, Ppath },
[SYS_flock] = { Pfd, Flockname },
[SYS_mkfifo] = { Ppath, Modename },
[SYS_mkdir] = { Ppath, Modename },
[SYS_rmdir] = { Ppath },
[SYS_adjtime] = { Pptr, Pptr },
- [SYS_quotactl] = { Ppath, Quotactlname, Puid_t, Pptr },
+ [SYS_quotactl] = { Ppath, Quotactlname, Uidname, Pptr },
[SYS_nfssvc] = { Phexint, Pptr },
[SYS_getfh] = { Ppath, Pptr },
[SYS_sysarch] = { Pdecint, Pptr },
[SYS_pread] = { Pfd, Pptr, Pbigsize, PAD, Poff_t },
[SYS_pwrite] = { Pfd, Pptr, Pbigsize, PAD, Poff_t },
- [SYS_setgid] = { Pgid_t },
- [SYS_setegid] = { Pgid_t },
- [SYS_seteuid] = { Puid_t },
+ [SYS_setgid] = { Gidname },
+ [SYS_setegid] = { Gidname },
+ [SYS_seteuid] = { Uidname },
[SYS_pathconf] = { Ppath, Pathconfname },
[SYS_fpathconf] = { Pfd, Pathconfname },
[SYS_swapctl] = { Swapctlname, Pptr, Pdecint },
[SYS_shmdt] = { Pptr },
[SYS_minherit] = { Pptr, Pbigsize, Minheritname },
[SYS_poll] = { Pptr, Pucount, Polltimeout },
- [SYS_lchown] = { Ppath, Puid_t, Pgid_t },
+ [SYS_lchown] = { Ppath, Uidname, Gidname },
[SYS_getsid] = { Ppid_t },
[SYS_msync] = { Pptr, Pbigsize, Msyncflagsname },
[SYS_pipe] = { Pptr },
[SYS_pwritev] = { Pfd, Pptr, Pcount, PAD, Poff_t },
[SYS_mlockall] = { Mlockallname },
[SYS_getresuid] = { Pptr, Pptr, Pptr },
- [SYS_setresuid] = { Puid_t, Puid_t, Puid_t },
+ [SYS_setresuid] = { Uidname, Uidname, Uidname },
[SYS_getresgid] = { Pptr, Pptr, Pptr },
- [SYS_setresgid] = { Pgid_t, Pgid_t, Pgid_t },
+ [SYS_setresgid] = { Gidname, Gidname, Gidname },
[SYS_mquery] = { Pptr, Pbigsize, Mmapprotname, Mmapflagsname, Pfd, PAD, Poff_t },
[SYS_closefrom] = { Pfd },
[SYS_sigaltstack] = { Pptr, Pptr },
[SYS_setrtable] = { Pdecint },
[SYS_faccessat] = { Atfd, Ppath, Accessmodename, Atflagsname },
[SYS_fchmodat] = { Atfd, Ppath, Modename, Atflagsname },
- [SYS_fchownat] = { Atfd, Ppath, Puid_t, Pgid_t, Atflagsname },
+ [SYS_fchownat] = { Atfd, Ppath, Uidname, Gidname, Atflagsname },
[SYS_linkat] = { Atfd, Ppath, Atfd, Ppath, Atflagsname },
[SYS_mkdirat] = { Atfd, Ppath, Modename },
[SYS_mkfifoat] = { Atfd, Ppath, Modename },
if (ktr->ktr_code == SYS___sysctl) {
const char *s;
- int *np, n, i, *top;
+ int n, i, *top;
if (!fancy)
goto nonnative;
n = CTL_MAXNAME;
if (n < 0)
errx(1, "invalid sysctl length %d", n);
- np = top = (int *)(ap + 6);
- for (i = 0; n--; np++, i++) {
- if (sep)
- putchar(sep);
- if (resolv && (s = kresolvsysctl(i, top, *np)) != NULL)
- printf("%s", s);
- else
- printf("%d", *np);
- sep = '.';
+ if (n > 0) {
+ top = (int *)(ap + 6);
+ printf("%d", top[0]);
+ for (i = 1; i < n; i++)
+ printf(".%d", top[i]);
+ if ((s = kresolvsysctl(0, top)) != NULL) {
+ printf("<%s", s);
+ for (i = 1; i < n; i++) {
+ if ((s = kresolvsysctl(i, top)) != NULL)
+ printf(".%s", s);
+ else
+ printf(".%d", top[i]);
+ }
+ putchar('>');
+ }
}
sep = ',';
#define SETNAME(name) do { names = (name); limit = nitems(name); } while (0)
static const char *
-kresolvsysctl(int depth, int *top, int idx)
+kresolvsysctl(int depth, const int *top)
{
struct ctlname *names;
size_t limit;
+ int idx = top[depth];
names = NULL;
case SYS___thrsigdivert:
signame(ret);
break;
+ case SYS_getuid:
+ case SYS_geteuid:
+ uidname(ret);
+ break;
+ case SYS_getgid:
+ case SYS_getegid:
+ gidname(ret);
+ break;
case -1: /* non-default emulation */
default:
(void)printf("%ld", (long)ret);
-/* $OpenBSD: ktrstruct.c,v 1.7 2014/11/20 18:44:10 krw Exp $ */
+/* $OpenBSD: ktrstruct.c,v 1.8 2014/12/15 01:48:54 guenther Exp $ */
/*-
* Copyright (c) 1988, 1993
}
static void
-print_time(time_t t, int relative)
+print_time(time_t t, int relative, int have_subsec)
{
char timestr[PATH_MAX + 4];
struct tm *tm;
- if (resolv == 0 || relative)
+ if (t < 0 && have_subsec) {
+ /* negative times with non-zero subsecs require care */
+ printf("-%jd", -(intmax_t)(t + 1));
+ } else
printf("%jd", (intmax_t)t);
- else {
+
+ if (!relative) {
tm = localtime(&t);
(void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);
- printf("\"%s\"", timestr);
+ printf("<\"%s\">", timestr);
}
}
printf("UTIME_NOW");
else if (tsp->tv_nsec == UTIME_OMIT)
printf("UTIME_OMIT");
- else if ((resolv == 0 || relative) && tsp->tv_sec < 0 &&
- tsp->tv_nsec > 0) {
- /* negative relative times with non-zero nsecs require care */
- printf("-%jd.%09ld", -(intmax_t)(tsp->tv_sec+1),
- 1000000000 - tsp->tv_nsec);
- } else {
- print_time(tsp->tv_sec, relative);
+ else {
+ print_time(tsp->tv_sec, relative, tsp->tv_nsec);
if (tsp->tv_nsec != 0)
- printf(".%09ld", tsp->tv_nsec);
+ printf(".%09ld", tsp->tv_sec >= 0 ? tsp->tv_nsec :
+ 1000000000 - tsp->tv_nsec);
+ }
+}
+
+void
+uidname(int uid)
+{
+ const char *name;
+
+ if (uid == -1)
+ printf("-1");
+ else {
+ printf("%u<", (unsigned)uid);
+ if (uid > UID_MAX || (name = user_from_uid(uid, 1)) == NULL)
+ printf("unknown>");
+ else
+ printf("\"%s\">", name);
+ }
+}
+
+void
+gidname(int gid)
+{
+ const char *name;
+
+ if (gid == -1)
+ printf("-1");
+ else {
+ printf("%u<", (unsigned)gid);
+ if (gid > GID_MAX || (name = group_from_gid(gid, 1)) == NULL)
+ printf("unknown>");
+ else
+ printf("\"%s\">", name);
}
}
ktrstat(const struct stat *statp)
{
char mode[12];
- struct passwd *pwd;
- struct group *grp;
/*
* note: ktrstruct() has already verified that statp points to a
*/
printf("struct stat { ");
strmode(statp->st_mode, mode);
- printf("dev=%d, ino=%llu, mode=%s, nlink=%u, ",
+ printf("dev=%d, ino=%llu, mode=%s, nlink=%u, uid=",
statp->st_dev, (unsigned long long)statp->st_ino,
mode, statp->st_nlink);
- if (resolv == 0 || (pwd = getpwuid(statp->st_uid)) == NULL)
- printf("uid=%u, ", statp->st_uid);
- else
- printf("uid=\"%s\", ", pwd->pw_name);
- if (resolv == 0 || (grp = getgrgid(statp->st_gid)) == NULL)
- printf("gid=%u, ", statp->st_gid);
- else
- printf("gid=\"%s\", ", grp->gr_name);
- printf("rdev=%d, ", statp->st_rdev);
+ uidname(statp->st_uid);
+ printf(", gid=");
+ gidname(statp->st_gid);
+ printf(", rdev=%d, ", statp->st_rdev);
printf("atime=");
print_timespec(&statp->st_atim, 0);
printf(", mtime=");
static void
print_timeval(const struct timeval *tvp, int relative)
{
- if ((resolv == 0 || relative) && tvp->tv_sec < 0 &&
- tvp->tv_usec > 0) {
- /* negative relative times with non-zero usecs require care */
- printf("-%jd.%06ld", -(intmax_t)(tvp->tv_sec+1),
+ print_time(tvp->tv_sec, relative, tvp->tv_usec);
+ if (tvp->tv_usec != 0)
+ printf(".%06ld", tvp->tv_sec >= 0 ? tvp->tv_usec :
1000000 - tvp->tv_usec);
- } else {
- print_time(tvp->tv_sec, relative);
- if (tvp->tv_usec != 0)
- printf(".%06ld", tvp->tv_usec);
- }
}
static void
quota->dqb_bhardlimit, quota->dqb_bsoftlimit,
quota->dqb_curblocks, quota->dqb_ihardlimit,
quota->dqb_isoftlimit, quota->dqb_curinodes);
- print_time(quota->dqb_btime, 0);
+ print_time(quota->dqb_btime, 0, 0);
printf(", itime=");
- print_time(quota->dqb_itime, 0);
+ print_time(quota->dqb_itime, 0, 0);
printf(" }\n");
}