Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src kern/42030 - tracking of file descriptors by ktrace/kdump
details: https://anonhg.NetBSD.org/src/rev/3a00a3e144ff
branches: trunk
changeset: 765662:3a00a3e144ff
user: alnsn <alnsn%NetBSD.org@localhost>
date: Wed Jun 01 21:24:59 2011 +0000
description:
kern/42030 - tracking of file descriptors by ktrace/kdump
diffstat:
sys/kern/kern_exec.c | 8 ++++++--
sys/kern/kern_ktrace.c | 23 +++++++++++++++++++++--
sys/kern/kern_stub.c | 5 +++--
sys/kern/subr_exec_fd.c | 33 +++++++++++++++++++++++++++++++--
sys/sys/filedesc.h | 3 ++-
sys/sys/ktrace.h | 19 ++++++++++++++++++-
usr.bin/kdump/kdump.c | 23 +++++++++++++++++++++--
usr.bin/ktrace/ktrace.1 | 4 +++-
usr.bin/ktrace/subr.c | 7 +++++--
9 files changed, 110 insertions(+), 15 deletions(-)
diffs (truncated from 340 to 300 lines):
diff -r 9f1bb179ebb6 -r 3a00a3e144ff sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Wed Jun 01 20:49:22 2011 +0000
+++ b/sys/kern/kern_exec.c Wed Jun 01 21:24:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.314 2011/04/26 16:36:42 joerg Exp $ */
+/* $NetBSD: kern_exec.c,v 1.315 2011/06/01 21:24:59 alnsn Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.314 2011/04/26 16:36:42 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.315 2011/06/01 21:24:59 alnsn Exp $");
#include "opt_ktrace.h"
#include "opt_modular.h"
@@ -979,6 +979,10 @@
cwdexec(p);
fd_closeexec(); /* handle close on exec */
+
+ if (__predict_false(ktrace_on))
+ fd_ktrexecfd();
+
execsigs(p); /* reset catched signals */
l->l_ctxlink = NULL; /* reset ucontext link */
diff -r 9f1bb179ebb6 -r 3a00a3e144ff sys/kern/kern_ktrace.c
--- a/sys/kern/kern_ktrace.c Wed Jun 01 20:49:22 2011 +0000
+++ b/sys/kern/kern_ktrace.c Wed Jun 01 21:24:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_ktrace.c,v 1.156 2011/04/27 00:00:46 joerg Exp $ */
+/* $NetBSD: kern_ktrace.c,v 1.157 2011/06/01 21:25:00 alnsn Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.156 2011/04/27 00:00:46 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.157 2011/06/01 21:25:00 alnsn Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -673,6 +673,25 @@
ktr_kmem(l, KTR_EXEC_ENV, bf, len);
}
+void
+ktr_execfd(int fd, u_int dtype)
+{
+ struct ktrace_entry *kte;
+ struct ktr_execfd* ktp;
+
+ lwp_t *l = curlwp;
+
+ if (!KTRPOINT(l->l_proc, KTR_EXEC_FD))
+ return;
+
+ if (ktealloc(&kte, (void *)&ktp, l, KTR_EXEC_FD, sizeof(*ktp)))
+ return;
+
+ ktp->ktr_fd = fd;
+ ktp->ktr_dtype = dtype;
+ ktraddentry(l, kte, KTA_WAITOK);
+}
+
static void
ktr_kmem(lwp_t *l, int type, const void *bf, size_t len)
{
diff -r 9f1bb179ebb6 -r 3a00a3e144ff sys/kern/kern_stub.c
--- a/sys/kern/kern_stub.c Wed Jun 01 20:49:22 2011 +0000
+++ b/sys/kern/kern_stub.c Wed Jun 01 21:24:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_stub.c,v 1.32 2011/05/31 23:28:53 dyoung Exp $ */
+/* $NetBSD: kern_stub.c,v 1.33 2011/06/01 21:25:01 alnsn Exp $ */
/*-
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_stub.c,v 1.32 2011/05/31 23:28:53 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_stub.c,v 1.33 2011/06/01 21:25:01 alnsn Exp $");
#include "opt_ptrace.h"
#include "opt_ktrace.h"
@@ -111,6 +111,7 @@
__weak_alias(ktr_mib,nullop);
__weak_alias(ktr_execarg,nullop);
__weak_alias(ktr_execenv,nullop);
+__weak_alias(ktr_execfd,nullop);
__weak_alias(sys_fktrace,sys_nosys); /* Syscalls */
__weak_alias(sys_ktrace,sys_nosys);
diff -r 9f1bb179ebb6 -r 3a00a3e144ff sys/kern/subr_exec_fd.c
--- a/sys/kern/subr_exec_fd.c Wed Jun 01 20:49:22 2011 +0000
+++ b/sys/kern/subr_exec_fd.c Wed Jun 01 21:24:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_exec_fd.c,v 1.5 2011/02/15 15:54:28 pooka Exp $ */
+/* $NetBSD: subr_exec_fd.c,v 1.6 2011/06/01 21:25:01 alnsn Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_exec_fd.c,v 1.5 2011/02/15 15:54:28 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_exec_fd.c,v 1.6 2011/06/01 21:25:01 alnsn Exp $");
#include <sys/param.h>
#include <sys/file.h>
@@ -36,6 +36,35 @@
#include <sys/namei.h>
#include <sys/syslog.h>
#include <sys/vnode.h>
+#include <sys/ktrace.h>
+
+void
+fd_ktrexecfd(void)
+{
+ proc_t *p;
+ filedesc_t *fdp;
+ fdfile_t *ff;
+ lwp_t *l;
+ fdtab_t *dt;
+ int fd;
+
+ l = curlwp;
+ p = l->l_proc;
+ fdp = p->p_fd;
+ dt = fdp->fd_dt;
+
+ for (fd = 0; fd <= fdp->fd_lastfile; fd++) {
+ if ((ff = dt->dt_ff[fd]) == NULL) {
+ KASSERT(fd >= NDFDFILE);
+ continue;
+ }
+ KASSERT(fd >= NDFDFILE ||
+ ff == (fdfile_t *)fdp->fd_dfdfile[fd]);
+ if (ff->ff_file == NULL)
+ continue;
+ ktr_execfd(fd, ff->ff_file->f_type);
+ }
+}
/*
* It is unsafe for set[ug]id processes to be started with file
diff -r 9f1bb179ebb6 -r 3a00a3e144ff sys/sys/filedesc.h
--- a/sys/sys/filedesc.h Wed Jun 01 20:49:22 2011 +0000
+++ b/sys/sys/filedesc.h Wed Jun 01 21:24:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: filedesc.h,v 1.59 2011/04/10 15:45:33 christos Exp $ */
+/* $NetBSD: filedesc.h,v 1.60 2011/06/01 21:25:02 alnsn Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -193,6 +193,7 @@
void fd_hold(lwp_t *);
void fd_free(void);
void fd_closeexec(void);
+void fd_ktrexecfd(void);
int fd_checkstd(void);
file_t *fd_getfile(unsigned);
file_t *fd_getfile2(proc_t *, unsigned);
diff -r 9f1bb179ebb6 -r 3a00a3e144ff sys/sys/ktrace.h
--- a/sys/sys/ktrace.h Wed Jun 01 20:49:22 2011 +0000
+++ b/sys/sys/ktrace.h Wed Jun 01 21:24:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ktrace.h,v 1.57 2011/04/27 00:00:46 joerg Exp $ */
+/* $NetBSD: ktrace.h,v 1.58 2011/06/01 21:25:02 alnsn Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -217,6 +217,14 @@
#define KTR_MIB 14
/* Record contains MIB name */
+/*
+ * KTR_EXEC_FD - Opened file descriptor from exec
+ */
+#define KTR_EXEC_FD 15
+struct ktr_execfd {
+ int ktr_fd;
+ u_int ktr_dtype; /* one of DTYPE_* constants */
+};
/*
* kernel trace points (in p_traceflag)
@@ -234,6 +242,7 @@
#define KTRFAC_EXEC_ENV (1<<KTR_EXEC_ENV)
#define KTRFAC_SAUPCALL (1<<KTR_SAUPCALL)
#define KTRFAC_MIB (1<<KTR_MIB)
+#define KTRFAC_EXEC_FD (1<<KTR_EXEC_FD)
/*
* trace flags (also in p_traceflags)
*/
@@ -286,6 +295,7 @@
void ktr_mib(const int *a , u_int b);
void ktr_execarg(const void *, size_t);
void ktr_execenv(const void *, size_t);
+void ktr_execfd(int, u_int);
void ktr_saupcall(struct lwp *, int, int, int, void *, void *, void *);
static inline bool
@@ -393,6 +403,13 @@
}
static inline void
+ktrexecfd(int fd, u_int dtype)
+{
+ if (__predict_false(ktrace_on))
+ ktr_execfd(fd, dtype);
+}
+
+static inline void
ktrsaupcall(struct lwp *a, int b, int c, int d, void *e, void *f, void *g)
{
if (__predict_false(ktrace_on))
diff -r 9f1bb179ebb6 -r 3a00a3e144ff usr.bin/kdump/kdump.c
--- a/usr.bin/kdump/kdump.c Wed Jun 01 20:49:22 2011 +0000
+++ b/usr.bin/kdump/kdump.c Wed Jun 01 21:24:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kdump.c,v 1.111 2011/04/27 00:00:47 joerg Exp $ */
+/* $NetBSD: kdump.c,v 1.112 2011/06/01 21:28:32 alnsn Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -39,12 +39,14 @@
#if 0
static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: kdump.c,v 1.111 2011/04/27 00:00:47 joerg Exp $");
+__RCSID("$NetBSD: kdump.c,v 1.112 2011/06/01 21:28:32 alnsn Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
+#include <sys/proc.h> /* XXX #include <sys/file.h> fails without this header */
#define _KERNEL
+#include <sys/file.h>
#include <sys/errno.h>
#undef _KERNEL
#include <sys/time.h>
@@ -115,6 +117,7 @@
static void ktrcsw(struct ktr_csw *);
static void ktruser(struct ktr_user *, int);
static void ktrmib(int *, int);
+static void ktrexecfd(struct ktr_execfd *);
static void usage(void) __dead;
static void eprint(int);
static void rprint(register_t);
@@ -294,6 +297,9 @@
case KTR_EXEC_ENV:
visdump_buf(m, ktrlen, col);
break;
+ case KTR_EXEC_FD:
+ ktrexecfd(m);
+ break;
case KTR_MIB:
ktrmib(m, ktrlen);
break;
@@ -363,6 +369,9 @@
case KTR_EXEC_ARG:
type = "ARG";
break;
+ case KTR_EXEC_FD:
+ type = "FD";
+ break;
case KTR_SAUPCALL:
type = "SAU";
break;
@@ -632,6 +641,16 @@
}
static void
+ktrexecfd(struct ktr_execfd *ktr)
+{
+ static const char *dnames[] = { DTYPE_NAMES };
+ if (ktr->ktr_dtype < __arraycount(dnames))
+ printf("%s %d\n", dnames[ktr->ktr_dtype], ktr->ktr_fd);
+ else
+ printf("UNKNOWN(%u) %d\n", ktr->ktr_dtype, ktr->ktr_fd);
+}
+
+static void
rprint(register_t ret)
{
diff -r 9f1bb179ebb6 -r 3a00a3e144ff usr.bin/ktrace/ktrace.1
--- a/usr.bin/ktrace/ktrace.1 Wed Jun 01 20:49:22 2011 +0000
+++ b/usr.bin/ktrace/ktrace.1 Wed Jun 01 21:24:59 2011 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: ktrace.1,v 1.40 2011/04/27 00:00:47 joerg Exp $
+.\" $NetBSD: ktrace.1,v 1.41 2011/06/01 21:28:33 alnsn Exp $
Home |
Main Index |
Thread Index |
Old Index