diff options
author | alfred <alfred@FreeBSD.org> | 2004-07-17 19:48:49 +0000 |
---|---|---|
committer | alfred <alfred@FreeBSD.org> | 2004-07-17 19:48:49 +0000 |
commit | f770c48d15ef2b5512bab229842e7b8501c5f89b (patch) | |
tree | 2aab56b03449877fe5d7c17ce3b50fc426abb64d | |
parent | 71eccf2cf55ca05d858bd43ea8dcf26e64a94c66 (diff) | |
download | FreeBSD-src-f770c48d15ef2b5512bab229842e7b8501c5f89b.zip FreeBSD-src-f770c48d15ef2b5512bab229842e7b8501c5f89b.tar.gz |
Support readlink(2) better. Readlink does not nul terminate the
result buffer, so we need to format it ourselves. The problem is
that the length is stored as the return value from readlink, so we
need to pass the return value from our syscall into print_arg.
Motivated by: truss garbage on my screen from reading /etc/malloc.conf.
-rw-r--r-- | usr.bin/truss/alpha-fbsd.c | 4 | ||||
-rw-r--r-- | usr.bin/truss/amd64-fbsd.c | 4 | ||||
-rw-r--r-- | usr.bin/truss/amd64-fbsd32.c | 4 | ||||
-rw-r--r-- | usr.bin/truss/amd64-linux32.c | 4 | ||||
-rw-r--r-- | usr.bin/truss/i386-fbsd.c | 4 | ||||
-rw-r--r-- | usr.bin/truss/i386-linux.c | 4 | ||||
-rw-r--r-- | usr.bin/truss/ia64-fbsd.c | 4 | ||||
-rw-r--r-- | usr.bin/truss/sparc64-fbsd.c | 4 | ||||
-rw-r--r-- | usr.bin/truss/syscall.h | 4 | ||||
-rw-r--r-- | usr.bin/truss/syscalls.c | 16 |
10 files changed, 32 insertions, 20 deletions
diff --git a/usr.bin/truss/alpha-fbsd.c b/usr.bin/truss/alpha-fbsd.c index 8bb10cb..5e7fa99 100644 --- a/usr.bin/truss/alpha-fbsd.c +++ b/usr.bin/truss/alpha-fbsd.c @@ -238,7 +238,7 @@ alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) { i < (fsc.nargs - 1) ? "," : ""); #endif if (sc && !(sc->args[i].type & OUT)) { - fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args); + fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0); } } #if DEBUG @@ -342,7 +342,7 @@ alpha_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) if (errorp) asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); else - temp = print_arg(Procfd, &sc->args[i], fsc.args); + temp = print_arg(Procfd, &sc->args[i], fsc.args, retval); fsc.s_args[i] = temp; } } diff --git a/usr.bin/truss/amd64-fbsd.c b/usr.bin/truss/amd64-fbsd.c index 0f35dd3..7fb5d26 100644 --- a/usr.bin/truss/amd64-fbsd.c +++ b/usr.bin/truss/amd64-fbsd.c @@ -223,7 +223,7 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs) { i < (fsc.nargs - 1) ? "," : ""); #endif if (sc && !(sc->args[i].type & OUT)) { - fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args); + fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0); } } #if DEBUG @@ -327,7 +327,7 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) if (errorp) asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); else - temp = print_arg(Procfd, &sc->args[i], fsc.args); + temp = print_arg(Procfd, &sc->args[i], fsc.args, retval); fsc.s_args[i] = temp; } } diff --git a/usr.bin/truss/amd64-fbsd32.c b/usr.bin/truss/amd64-fbsd32.c index bbe651a..dac6aa1 100644 --- a/usr.bin/truss/amd64-fbsd32.c +++ b/usr.bin/truss/amd64-fbsd32.c @@ -217,7 +217,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) { i < (fsc.nargs - 1) ? "," : ""); #endif if (sc && !(sc->args[i].type & OUT)) { - fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args); + fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0); } } #if DEBUG @@ -321,7 +321,7 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) if (errorp) asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); else - temp = print_arg(Procfd, &sc->args[i], fsc.args); + temp = print_arg(Procfd, &sc->args[i], fsc.args, retval); fsc.s_args[i] = temp; } } diff --git a/usr.bin/truss/amd64-linux32.c b/usr.bin/truss/amd64-linux32.c index 2164368..01703b5 100644 --- a/usr.bin/truss/amd64-linux32.c +++ b/usr.bin/truss/amd64-linux32.c @@ -200,7 +200,7 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) { i < (fsc.nargs - 1) ? "," : ""); #endif if (sc && !(sc->args[i].type & OUT)) { - fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args); + fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0); } } #if DEBUG @@ -312,7 +312,7 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) if (errorp) asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); else - temp = print_arg(Procfd, &sc->args[i], fsc.args); + temp = print_arg(Procfd, &sc->args[i], fsc.args, retval); fsc.s_args[i] = temp; } } diff --git a/usr.bin/truss/i386-fbsd.c b/usr.bin/truss/i386-fbsd.c index bbe651a..dac6aa1 100644 --- a/usr.bin/truss/i386-fbsd.c +++ b/usr.bin/truss/i386-fbsd.c @@ -217,7 +217,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) { i < (fsc.nargs - 1) ? "," : ""); #endif if (sc && !(sc->args[i].type & OUT)) { - fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args); + fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0); } } #if DEBUG @@ -321,7 +321,7 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) if (errorp) asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); else - temp = print_arg(Procfd, &sc->args[i], fsc.args); + temp = print_arg(Procfd, &sc->args[i], fsc.args, retval); fsc.s_args[i] = temp; } } diff --git a/usr.bin/truss/i386-linux.c b/usr.bin/truss/i386-linux.c index 2164368..01703b5 100644 --- a/usr.bin/truss/i386-linux.c +++ b/usr.bin/truss/i386-linux.c @@ -200,7 +200,7 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) { i < (fsc.nargs - 1) ? "," : ""); #endif if (sc && !(sc->args[i].type & OUT)) { - fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args); + fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0); } } #if DEBUG @@ -312,7 +312,7 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) if (errorp) asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); else - temp = print_arg(Procfd, &sc->args[i], fsc.args); + temp = print_arg(Procfd, &sc->args[i], fsc.args, retval); fsc.s_args[i] = temp; } } diff --git a/usr.bin/truss/ia64-fbsd.c b/usr.bin/truss/ia64-fbsd.c index 15b60bf..7ca6d7f 100644 --- a/usr.bin/truss/ia64-fbsd.c +++ b/usr.bin/truss/ia64-fbsd.c @@ -204,7 +204,7 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs) { i < (fsc.nargs - 1) ? "," : ""); #endif if (sc && !(sc->args[i].type & OUT)) { - fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args); + fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0); } } #if DEBUG @@ -308,7 +308,7 @@ ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) if (errorp) asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); else - temp = print_arg(Procfd, &sc->args[i], fsc.args); + temp = print_arg(Procfd, &sc->args[i], fsc.args, retval); fsc.s_args[i] = temp; } } diff --git a/usr.bin/truss/sparc64-fbsd.c b/usr.bin/truss/sparc64-fbsd.c index 190f8cc..375e1fa 100644 --- a/usr.bin/truss/sparc64-fbsd.c +++ b/usr.bin/truss/sparc64-fbsd.c @@ -240,7 +240,7 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) { i < (fsc.nargs - 1) ? "," : ""); #endif if (sc && !(sc->args[i].type & OUT)) { - fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args); + fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0); } } #if DEBUG @@ -343,7 +343,7 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) { if (errorp) asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); else - temp = print_arg(Procfd, &sc->args[i], fsc.args); + temp = print_arg(Procfd, &sc->args[i], fsc.args, retval); fsc.s_args[i] = temp; } } diff --git a/usr.bin/truss/syscall.h b/usr.bin/truss/syscall.h index ff57f72..838dfe2 100644 --- a/usr.bin/truss/syscall.h +++ b/usr.bin/truss/syscall.h @@ -32,7 +32,7 @@ enum Argtype { None = 1, Hex, Octal, Int, String, Ptr, Stat, Ioctl, Quad, Signal, Sockaddr, StringArray, Timespec, Timeval, Itimerval, Pollfd, - Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence }; + Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres }; #define ARG_MASK 0xff #define OUT 0x100 @@ -53,7 +53,7 @@ struct syscall { struct syscall *get_syscall(const char*); char *get_string(int, void*, int); -char *print_arg(int, struct syscall_args *, unsigned long*); +char *print_arg(int, struct syscall_args *, unsigned long*, long); void print_syscall(struct trussinfo *, const char *, int, char **); void print_syscall_ret(struct trussinfo *, const char *, int, char **, int, long); diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index 992f94f..22e79b2 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -71,7 +71,7 @@ struct syscall syscalls[] = { { "fcntl", 1, 3, { { Int, 0 } , { Fcntl, 1 }, { Hex, 2 }}}, { "readlink", 1, 3, - { { String, 0 } , { String | OUT, 1 }, { Int, 2 }}}, + { { String, 0 } , { Readlinkres | OUT, 1 }, { Int, 2 }}}, { "lseek", 2, 3, { { Int, 0 }, {Quad, 2 }, { Whence, 4 }}}, { "linux_lseek", 2, 3, @@ -271,7 +271,7 @@ remove_trailing_or(char *str) */ char * -print_arg(int fd, struct syscall_args *sc, unsigned long *args) { +print_arg(int fd, struct syscall_args *sc, unsigned long *args, long retval) { char *tmp = NULL; switch (sc->type & ARG_MASK) { case Hex: @@ -338,6 +338,18 @@ print_arg(int fd, struct syscall_args *sc, unsigned long *args) { case Ptr: asprintf(&tmp, "0x%lx", args[sc->offset]); break; + case Readlinkres: + { + char *tmp2; + if (retval == -1) { + tmp = strdup(""); + break; + } + tmp2 = get_string(fd, (void*)args[sc->offset], retval); + asprintf(&tmp, "\"%s\"", tmp2); + free(tmp2); + } + break; case Ioctl: { const char *temp = ioctlname(args[sc->offset]); |