FreeBSD/sys/dev/filemon/filemon.c
/* Attach the filemon to the process. */
Attach the filemon to the process.
Attach the filemon to the process .
static int
filemon_attach_proc(struct filemon *filemon, struct proc *p)
{
	struct filemon *filemon2;
	sx_assert(&filemon->lock, SA_XLOCKED);
	PROC_LOCK_ASSERT(p, MA_OWNED);
	KASSERT((p->p_flag & P_WEXIT) == 0,
	    ("%s: filemon %p attaching to exiting process %p",
	    __func__, filemon, p));
	KASSERT((p->p_flag & P_INEXEC) == 0,
	    ("%s: filemon %p attaching to execing process %p",
	    __func__, filemon, p));
	if (p->p_filemon == filemon)
		return (0);
	if (p->p_filemon != NULL && p != curproc)
		return (EBUSY);
	while (p->p_filemon != NULL) {
		PROC_UNLOCK(p);
		sx_xunlock(&filemon->lock);
		while ((filemon2 = filemon_proc_get(p)) != NULL) {
			if (p->p_filemon == filemon2)
				filemon_proc_drop(p);
			filemon_drop(filemon2);
		}
		sx_xlock(&filemon->lock);
		PROC_LOCK(p);
	}
	KASSERT(p->p_filemon == NULL,
	    ("%s: proc %p didn't detach filemon %p", __func__, p,
	    p->p_filemon));
	p->p_filemon = filemon_acquire(filemon);
	++filemon->proccnt;
	return (0);
}
static int filemon_attach_proc ( struct filemon * filemon , struct proc * p ) { struct filemon * filemon2 ; sx_assert ( & filemon -> lock , SA_XLOCKED ) ; PROC_LOCK_ASSERT ( p , MA_OWNED ) ; KASSERT ( ( p -> p_flag & P_WEXIT ) == 0 , ( " " , __func__ , filemon , p ) ) ; KASSERT ( ( p -> p_flag & P_INEXEC ) == 0 , ( " " , __func__ , filemon , p ) ) ; if ( p -> p_filemon == filemon ) return ( 0 ) ; if ( p -> p_filemon != NULL && p != curproc ) return ( EBUSY ) ; while ( p -> p_filemon != NULL ) { PROC_UNLOCK ( p ) ; sx_xunlock ( & filemon -> lock ) ; while ( ( filemon2 = filemon_proc_get ( p ) ) != NULL ) { if ( p -> p_filemon == filemon2 ) filemon_proc_drop ( p ) ; filemon_drop ( filemon2 ) ; } sx_xlock ( & filemon -> lock ) ; PROC_LOCK ( p ) ; } KASSERT ( p -> p_filemon == NULL , ( " " , __func__ , p , p -> p_filemon ) ) ; p -> p_filemon = filemon_acquire ( filemon ) ; ++ filemon -> proccnt ; return ( 0 ) ; }
Attach the filemon to the process.
Attach the filemon to the process .
/*
	 * Don't allow truncating other process traces.  It is
	 * not really intended to trace procs other than curproc
	 * anyhow.
	 */ /*
	 * Historic behavior of filemon has been to let a child initiate
	 * tracing on itself and cease existing tracing.  Bmake
	 * .META + .MAKE relies on this.  It is only relevant for attaching to
	 * curproc.
	 */ /* It may have changed. */ /*
		 * It may have been attached to, though unlikely.
		 * Try again if needed.
		 */