Move the ktrace (and systrace) in namei() inside the retry loop for

emulation lookups.
If doing a lookup relative to the emulation root, prepend the emulation root
to the traced filename.
While here pass the filename length through to the ktrace code since namei()
knows the length and ktr_namei() would have to call strlen().
Note: that if namei() is being called during execve processing, the emulation
root name isn't available and "/emul/???" is used.  Also namei() has to use
strlen() to get the lenght on the emulatoon root - even though it is a
compile-time constant string.
This commit is contained in:
dsl 2007-04-26 16:27:32 +00:00
parent 0c835d6548
commit 7a81c4d42e
3 changed files with 43 additions and 20 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_ktrace.c,v 1.121 2007/03/29 17:37:13 ad Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.122 2007/04/26 16:27:32 dsl Exp $ */
/*
* Copyright (c) 1989, 1993
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.121 2007/03/29 17:37:13 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.122 2007/04/26 16:27:32 dsl Exp $");
#include "opt_ktrace.h"
#include "opt_compat_mach.h"
@ -566,14 +566,25 @@ ktrsysret(struct lwp *l, register_t code, int error, register_t *retval)
ktraddentry(l, kte, KTA_WAITOK);
}
/*
* XXX: ndp->ni_pathlen should be passed.
*/
void
ktrnamei(struct lwp *l, char *path)
ktrnamei(struct lwp *l, const char *path, size_t pathlen)
{
ktrkmem(l, KTR_NAMEI, path, pathlen);
}
ktrkmem(l, KTR_NAMEI, path, strlen(path));
void
ktrnamei2(struct lwp *l, const char *eroot, size_t erootlen,
const char *path, size_t pathlen)
{
struct ktrace_entry *kte;
void *buf;
if (ktealloc(&kte, &buf, l, KTR_NAMEI, erootlen + pathlen))
return;
memcpy(buf, eroot, erootlen);
buf = (char *)buf + erootlen;
memcpy(buf, path, pathlen);
ktraddentry(l, kte, KTA_WAITOK);
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_lookup.c,v 1.87 2007/04/25 20:41:42 dsl Exp $ */
/* $NetBSD: vfs_lookup.c,v 1.88 2007/04/26 16:27:32 dsl Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.87 2007/04/25 20:41:42 dsl Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.88 2007/04/26 16:27:32 dsl Exp $");
#include "opt_ktrace.h"
#include "opt_systrace.h"
@ -310,15 +310,6 @@ namei(struct nameidata *ndp)
}
ndp->ni_loopcnt = 0;
#ifdef KTRACE
if (KTRPOINT(cnp->cn_lwp->l_proc, KTR_NAMEI))
ktrnamei(cnp->cn_lwp, cnp->cn_pnbuf);
#endif
#ifdef SYSTRACE
if (ISSET(cnp->cn_lwp->l_proc->p_flag, PK_SYSTRACE))
systrace_namei(ndp);
#endif
/*
* Get root directory for the translation.
*/
@ -354,6 +345,26 @@ namei(struct nameidata *ndp)
ndp->ni_erootdir = NULL;
}
#ifdef KTRACE
if (KTRPOINT(cnp->cn_lwp->l_proc, KTR_NAMEI)) {
if (cnp->cn_flags & TRYEMULROOT) {
if (cnp->cn_flags & EMULROOTSET)
ktrnamei2(cnp->cn_lwp, "/emul/???", 9,
cnp->cn_pnbuf, ndp->ni_pathlen);
else
ktrnamei2(cnp->cn_lwp,
cnp->cn_lwp->l_proc->p_emul->e_path,
strlen(cnp->cn_lwp->l_proc->p_emul->e_path),
cnp->cn_pnbuf, ndp->ni_pathlen);
} else
ktrnamei(cnp->cn_lwp, cnp->cn_pnbuf, ndp->ni_pathlen);
}
#endif
#ifdef SYSTRACE
if (ISSET(cnp->cn_lwp->l_proc->p_flag, PK_SYSTRACE))
systrace_namei(ndp);
#endif
VREF(dp);
vn_lock(dp, LK_EXCLUSIVE | LK_RETRY);
/* Loop through symbolic links */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ktrace.h,v 1.46 2007/02/09 21:55:37 ad Exp $ */
/* $NetBSD: ktrace.h,v 1.47 2007/04/26 16:27:32 dsl Exp $ */
/*
* Copyright (c) 1988, 1993
@ -282,7 +282,8 @@ void ktrinit(void);
void ktrcsw(struct lwp *, int, int);
void ktremul(struct lwp *);
void ktrgenio(struct lwp *, int, enum uio_rw, struct iovec *, int, int);
void ktrnamei(struct lwp *, char *);
void ktrnamei(struct lwp *, const char *, size_t);
void ktrnamei2(struct lwp *, const char *, size_t, const char *, size_t);
void ktrpsig(struct lwp *, int, sig_t, const sigset_t *, const ksiginfo_t *);
void ktrsyscall(struct lwp *, register_t, register_t,
const struct sysent *, register_t []);