performance improvement by omitting a redundant getcwd.
This commit is contained in:
parent
98c03e54fd
commit
c27faa29c9
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: intercept.c,v 1.10 2002/10/30 17:39:34 provos Exp $ */
|
||||
/* $NetBSD: intercept.c,v 1.11 2002/11/02 19:57:02 provos Exp $ */
|
||||
/* $OpenBSD: intercept.c,v 1.29 2002/08/28 03:30:27 itojun Exp $ */
|
||||
/*
|
||||
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
||||
@ -30,7 +30,7 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: intercept.c,v 1.10 2002/10/30 17:39:34 provos Exp $");
|
||||
__RCSID("$NetBSD: intercept.c,v 1.11 2002/11/02 19:57:02 provos Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
@ -565,26 +565,37 @@ intercept_filename(int fd, pid_t pid, void *addr, int userp)
|
||||
static char cwd[2*MAXPATHLEN];
|
||||
struct intercept_pid *icpid;
|
||||
char *name;
|
||||
int havecwd = 0;
|
||||
|
||||
name = intercept_get_string(fd, pid, addr);
|
||||
if (name == NULL)
|
||||
goto abort;
|
||||
|
||||
if (intercept.getcwd(fd, pid, cwd, sizeof(cwd)) == NULL) {
|
||||
if (intercept.setcwd(fd, pid) == -1) {
|
||||
if (errno == EBUSY)
|
||||
goto abort;
|
||||
getcwderr:
|
||||
if (strcmp(name, "/") == 0)
|
||||
return (name);
|
||||
|
||||
err(1, "%s: getcwd", __func__);
|
||||
}
|
||||
|
||||
/* Update cwd for process */
|
||||
icpid = intercept_getpid(pid);
|
||||
if (strlcpy(icpid->cwd, cwd, sizeof(icpid->cwd)) >= sizeof(icpid->cwd))
|
||||
errx(1, "cwd too long");
|
||||
if (userp == ICLINK_NONE) {
|
||||
if (getcwd(cwd, sizeof(cwd)) == NULL)
|
||||
goto getcwderr;
|
||||
havecwd = 1;
|
||||
}
|
||||
|
||||
if (name[0] != '/') {
|
||||
if (havecwd) {
|
||||
/* Update cwd for process */
|
||||
icpid = intercept_getpid(pid);
|
||||
if (strlcpy(icpid->cwd, cwd, sizeof(icpid->cwd)) >= sizeof(icpid->cwd))
|
||||
errx(1, "cwd too long");
|
||||
}
|
||||
|
||||
/* Need concatenated path for simplifypath */
|
||||
if (havecwd && name[0] != '/') {
|
||||
if (strlcat(cwd, "/", sizeof(cwd)) >= sizeof(cwd))
|
||||
goto error;
|
||||
if (strlcat(cwd, name, sizeof(cwd)) >= sizeof(cwd))
|
||||
@ -666,12 +677,13 @@ intercept_filename(int fd, pid_t pid, void *addr, int userp)
|
||||
|
||||
return (name);
|
||||
|
||||
error:
|
||||
errx(1, "%s: filename too long", __func__);
|
||||
/* NOTREACHED */
|
||||
|
||||
abort:
|
||||
ic_abort = 1;
|
||||
return (NULL);
|
||||
|
||||
error:
|
||||
errx(1, "%s: filename too long", __func__);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: intercept.h,v 1.6 2002/10/11 21:54:57 provos Exp $ */
|
||||
/* $NetBSD: intercept.h,v 1.7 2002/11/02 19:57:02 provos Exp $ */
|
||||
/* $OpenBSD: intercept.h,v 1.11 2002/08/04 04:15:50 provos Exp $ */
|
||||
/*
|
||||
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
||||
@ -48,7 +48,7 @@ struct intercept_system {
|
||||
int (*report)(int, pid_t);
|
||||
int (*read)(int);
|
||||
int (*getsyscallnumber)(const char *, const char *);
|
||||
char *(*getcwd)(int, pid_t, char *, size_t);
|
||||
int (*setcwd)(int, pid_t);
|
||||
int (*restcwd)(int);
|
||||
int (*io)(int, pid_t, int, void *, u_char *, size_t);
|
||||
int (*getarg)(int, void *, int, void **);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: netbsd-syscalls.c,v 1.9 2002/10/11 21:54:58 provos Exp $ */
|
||||
/* $NetBSD: netbsd-syscalls.c,v 1.10 2002/11/02 19:57:02 provos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
||||
@ -31,7 +31,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: netbsd-syscalls.c,v 1.9 2002/10/11 21:54:58 provos Exp $");
|
||||
__RCSID("$NetBSD: netbsd-syscalls.c,v 1.10 2002/11/02 19:57:02 provos Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
@ -160,7 +160,7 @@ static int nbsd_assignpolicy(int, pid_t, int);
|
||||
static int nbsd_modifypolicy(int, int, int, short);
|
||||
static int nbsd_replace(int, pid_t, struct intercept_replace *);
|
||||
static int nbsd_io(int, pid_t, int, void *, u_char *, size_t);
|
||||
static char *nbsd_getcwd(int, pid_t, char *, size_t);
|
||||
static int nbsd_setcwd(int, pid_t);
|
||||
static int nbsd_restcwd(int);
|
||||
static int nbsd_argument(int, void *, int, void **);
|
||||
static int nbsd_read(int);
|
||||
@ -510,19 +510,10 @@ nbsd_io(int fd, pid_t pid, int op, void *addr, u_char *buf, size_t size)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static char *
|
||||
nbsd_getcwd(int fd, pid_t pid, char *buf, size_t size)
|
||||
static int
|
||||
nbsd_setcwd(int fd, pid_t pid)
|
||||
{
|
||||
char *path;
|
||||
|
||||
if (ioctl(fd, STRIOCGETCWD, &pid) == -1)
|
||||
return (NULL);
|
||||
|
||||
path = getcwd(buf, size);
|
||||
if (path == NULL)
|
||||
nbsd_restcwd(fd);
|
||||
|
||||
return (path);
|
||||
return (ioctl(fd, STRIOCGETCWD, &pid));
|
||||
}
|
||||
|
||||
static int
|
||||
@ -655,7 +646,7 @@ struct intercept_system intercept = {
|
||||
nbsd_report,
|
||||
nbsd_read,
|
||||
nbsd_syscall_number,
|
||||
nbsd_getcwd,
|
||||
nbsd_setcwd,
|
||||
nbsd_restcwd,
|
||||
nbsd_io,
|
||||
nbsd_argument,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: openbsd-syscalls.c,v 1.6 2002/10/16 14:56:11 itojun Exp $ */
|
||||
/* $NetBSD: openbsd-syscalls.c,v 1.7 2002/11/02 19:57:02 provos Exp $ */
|
||||
/* $OpenBSD: openbsd-syscalls.c,v 1.12 2002/08/28 03:30:27 itojun Exp $ */
|
||||
/*
|
||||
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
||||
@ -135,7 +135,7 @@ static int obsd_assignpolicy(int, pid_t, int);
|
||||
static int obsd_modifypolicy(int, int, int, short);
|
||||
static int obsd_replace(int, pid_t, struct intercept_replace *);
|
||||
static int obsd_io(int, pid_t, int, void *, u_char *, size_t);
|
||||
static char *obsd_getcwd(int, pid_t, char *, size_t);
|
||||
static int obsd_setcwd(int, pid_t);
|
||||
static int obsd_restcwd(int);
|
||||
static int obsd_argument(int, void *, int, void **);
|
||||
static int obsd_read(int);
|
||||
@ -492,19 +492,10 @@ obsd_io(int fd, pid_t pid, int op, void *addr, u_char *buf, size_t size)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static char *
|
||||
obsd_getcwd(int fd, pid_t pid, char *buf, size_t size)
|
||||
static int
|
||||
obsd_setcwd(int fd, pid_t pid)
|
||||
{
|
||||
char *path;
|
||||
|
||||
if (ioctl(fd, STRIOCGETCWD, &pid) == -1)
|
||||
return (NULL);
|
||||
|
||||
path = getcwd(buf, size);
|
||||
if (path == NULL)
|
||||
obsd_restcwd(fd);
|
||||
|
||||
return (path);
|
||||
return (ioctl(fd, STRIOCGETCWD, &pid));
|
||||
}
|
||||
|
||||
static int
|
||||
@ -637,7 +628,7 @@ struct intercept_system intercept = {
|
||||
obsd_report,
|
||||
obsd_read,
|
||||
obsd_syscall_number,
|
||||
obsd_getcwd,
|
||||
obsd_setcwd,
|
||||
obsd_restcwd,
|
||||
obsd_io,
|
||||
obsd_argument,
|
||||
|
Loading…
Reference in New Issue
Block a user