summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorsef <sef@FreeBSD.org>1997-12-06 04:11:14 +0000
committersef <sef@FreeBSD.org>1997-12-06 04:11:14 +0000
commitc7d273eccbdbad69eed3ca880a3956ca804a83c8 (patch)
tree213faf73090825488ed9bc01587c6f942d45f53e /sys/kern
parent9821c0958535e623d28d6d4fc1d1ac205a20ec36 (diff)
downloadFreeBSD-src-c7d273eccbdbad69eed3ca880a3956ca804a83c8.zip
FreeBSD-src-c7d273eccbdbad69eed3ca880a3956ca804a83c8.tar.gz
Changes to allow event-based process monitoring and control.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_main.c8
-rw-r--r--sys/kern/kern_exec.c5
-rw-r--r--sys/kern/kern_exit.c12
-rw-r--r--sys/kern/kern_sig.c27
-rw-r--r--sys/kern/subr_trap.c13
-rw-r--r--sys/kern/sys_process.c21
-rw-r--r--sys/kern/vfs_vnops.c5
7 files changed, 78 insertions, 13 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index fa381e2..e56531e 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -39,7 +39,7 @@
* SUCH DAMAGE.
*
* @(#)init_main.c 8.9 (Berkeley) 1/21/94
- * $Id: init_main.c,v 1.75 1997/11/24 18:35:04 bde Exp $
+ * $Id: init_main.c,v 1.76 1997/11/25 07:07:41 julian Exp $
*/
#include "opt_devfs.h"
@@ -415,6 +415,12 @@ proc0_init(dummy)
* Charge root for one process.
*/
(void)chgproccnt(0, 1);
+
+ /*
+ * Initialize the procfs flags (to 0, of course)
+ */
+ p->p_stops = p->p_stype = p->p_step = 0;
+
}
SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL)
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index bdad7d9..4d4f05a 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: kern_exec.c,v 1.67 1997/10/15 18:28:34 guido Exp $
+ * $Id: kern_exec.c,v 1.68 1997/11/06 19:29:08 phk Exp $
*/
#include <sys/param.h>
@@ -40,6 +40,7 @@
#include <sys/imgact_elf.h>
#include <sys/wait.h>
#include <sys/proc.h>
+#include <sys/pioctl.h>
#include <sys/malloc.h>
#include <sys/namei.h>
#include <sys/sysent.h>
@@ -338,6 +339,8 @@ interpret:
* If tracing the process, trap to debugger so breakpoints
* can be set before the program executes.
*/
+ STOPEVENT(p, S_EXEC, 0);
+
if (p->p_flag & P_TRACED)
psignal(p, SIGTRAP);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index dd1a54e..d282d22 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_exit.c 8.7 (Berkeley) 2/12/94
- * $Id: kern_exit.c,v 1.59 1997/11/06 19:29:08 phk Exp $
+ * $Id: kern_exit.c,v 1.60 1997/11/20 19:09:43 bde Exp $
*/
#include "opt_ktrace.h"
@@ -46,6 +46,7 @@
#include <sys/sysproto.h>
#include <sys/malloc.h>
#include <sys/proc.h>
+#include <sys/pioctl.h>
#include <sys/tty.h>
#include <sys/wait.h>
#include <sys/vnode.h>
@@ -113,6 +114,7 @@ exit1(p, rv)
register struct proc *q, *nq;
register struct vmspace *vm;
ele_p ep = exit_list;
+ extern void procfs_exit(pid_t);
if (p->p_pid == 1) {
printf("init died (signal %d, exit %d)\n",
@@ -155,6 +157,14 @@ exit1(p, rv)
#ifdef PGINPROF
vmsizmon();
#endif
+ STOPEVENT(p, S_EXIT, rv);
+
+ /*
+ * Now that we're back from stopevent(), force a close
+ * of all open procfs files for this process.
+ */
+ procfs_exit(p->p_pid);
+
/*
* Check if any LKMs need anything done at process exit.
* e.g. SYSV IPC stuff
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 8a378a1..3200080 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
- * $Id: kern_sig.c,v 1.34 1997/09/13 19:42:12 joerg Exp $
+ * $Id: kern_sig.c,v 1.35 1997/11/06 19:29:14 phk Exp $
*/
#include "opt_ktrace.h"
@@ -49,6 +49,7 @@
#include <sys/namei.h>
#include <sys/vnode.h>
#include <sys/proc.h>
+#include <sys/pioctl.h>
#include <sys/systm.h>
#include <sys/acct.h>
#include <sys/fcntl.h>
@@ -743,15 +744,19 @@ psignal(p, signum)
register sig_t action;
int mask;
- if ((u_int)signum >= NSIG || signum == 0)
+ if ((u_int)signum >= NSIG || signum == 0) {
+ printf("psignal: signum %d\n", signum);
panic("psignal signal number");
+ }
mask = sigmask(signum);
prop = sigprop[signum];
/*
- * If proc is traced, always give parent a chance.
+ * If proc is traced, always give parent a chance;
+ * if signal event is tracked by procfs, give *that*
+ * a chance, as well.
*/
- if (p->p_flag & P_TRACED)
+ if ((p->p_flag & P_TRACED) || (p->p_stops & S_SIG))
action = SIG_DFL;
else {
/*
@@ -948,6 +953,8 @@ issignal(p)
register int signum, mask, prop;
for (;;) {
+ int traced = (p->p_flag & P_TRACED) || (p->p_stops & S_SIG);
+
mask = p->p_siglist & ~p->p_sigmask;
if (p->p_flag & P_PPWAIT)
mask &= ~stopsigmask;
@@ -956,11 +963,14 @@ issignal(p)
signum = ffs((long)mask);
mask = sigmask(signum);
prop = sigprop[signum];
+
+ STOPEVENT(p, S_SIG, signum);
+
/*
* We should see pending but ignored signals
* only if P_TRACED was on when they were posted.
*/
- if (mask & p->p_sigignore && (p->p_flag & P_TRACED) == 0) {
+ if ((mask & p->p_sigignore) && (traced == 0)) {
p->p_siglist &= ~mask;
continue;
}
@@ -974,7 +984,8 @@ issignal(p)
do {
stop(p);
mi_switch();
- } while (!trace_req(p) && p->p_flag & P_TRACED);
+ } while (!trace_req(p)
+ && p->p_flag & P_TRACED);
/*
* If the traced bit got turned off, go back up
@@ -1118,6 +1129,8 @@ postsig(signum)
signum, action, ps->ps_flags & SAS_OLDMASK ?
ps->ps_oldmask : p->p_sigmask, 0);
#endif
+ STOPEVENT(p, S_SIG, signum);
+
if (action == SIG_DFL) {
/*
* Default action, where the default is to kill
@@ -1236,6 +1249,8 @@ coredump(p)
int error, error1;
char name[MAXCOMLEN+6]; /* progname.core */
+ STOPEVENT(p, S_CORE, 0);
+
if (p->p_flag & P_SUGID)
return (EFAULT);
if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >=
diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c
index 8c45d1f..f936fd6 100644
--- a/sys/kern/subr_trap.c
+++ b/sys/kern/subr_trap.c
@@ -35,7 +35,7 @@
* SUCH DAMAGE.
*
* from: @(#)trap.c 7.4 (Berkeley) 5/13/91
- * $Id: trap.c,v 1.117 1997/12/04 14:35:40 jkh Exp $
+ * $Id: trap.c,v 1.118 1997/12/04 21:21:26 jmg Exp $
*/
/*
@@ -50,6 +50,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
+#include <sys/pioctl.h>
#include <sys/kernel.h>
#include <sys/resourcevar.h>
#include <sys/signalvar.h>
@@ -987,6 +988,8 @@ syscall(frame)
p->p_retval[0] = 0;
p->p_retval[1] = frame.tf_edx;
+ STOPEVENT(p, S_SCE, callp->sy_narg);
+
error = (*callp->sy_call)(p, args);
switch (error) {
@@ -1037,6 +1040,14 @@ bad:
if (KTRPOINT(p, KTR_SYSRET))
ktrsysret(p->p_tracep, code, error, p->p_retval[0]);
#endif
+
+ /*
+ * This works because errno is findable through the
+ * register set. If we ever support an emulation where this
+ * is not the case, this code will need to be revisited.
+ */
+ STOPEVENT(p, S_SCX, code);
+
}
/*
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index 28007f72..c289115 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -28,7 +28,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: sys_process.c,v 1.31 1997/11/06 19:29:22 phk Exp $
+ * $Id: sys_process.c,v 1.32 1997/11/12 12:28:12 tegge Exp $
*/
#include <sys/param.h>
@@ -503,3 +503,22 @@ trace_req(p)
{
return 1;
}
+
+/*
+ * stopevent()
+ * Stop a process because of a procfs event;
+ * stay stopped until p->p_step is cleared
+ * (cleared by PIOCCONT in procfs).
+ */
+
+void
+stopevent(struct proc *p, unsigned int event, unsigned int val) {
+ p->p_step = 1;
+
+ do {
+ p->p_xstat = val;
+ p->p_stype = event; /* Which event caused the stop? */
+ wakeup(&p->p_stype); /* Wake up any PIOCWAIT'ing procs */
+ tsleep(&p->p_step, PWAIT, "stopevent", 0);
+ } while (p->p_step);
+}
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index dd12e9f..58dfad5 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94
- * $Id: vfs_vnops.c,v 1.41 1997/11/07 08:53:11 phk Exp $
+ * $Id: vfs_vnops.c,v 1.42 1997/11/29 01:33:10 dyson Exp $
*/
#include <sys/param.h>
@@ -454,8 +454,9 @@ vn_ioctl(fp, com, data, p)
/* fall into ... */
default:
+#if 0
return (ENOTTY);
-
+#endif
case VFIFO:
case VCHR:
case VBLK:
OpenPOWER on IntegriCloud