extern int is_restart_error(struct tcb *);
extern void pathtrace_select(const char *);
extern int pathtrace_match(struct tcb *);
-extern const char *getfdpath(struct tcb *, int);
+extern int getfdpath(struct tcb *, int, char *, unsigned);
extern const char *xlookup(const struct xlat *, int);
static int
fdmatch(struct tcb *tcp, int fd)
{
- const char *path = getfdpath(tcp, fd);
+ char path[PATH_MAX + 1];
+ int n = getfdpath(tcp, fd, path, sizeof(path));
- return path && pathmatch(path);
+ return n >= 0 && pathmatch(path);
}
/*
/*
* Get path associated with fd.
*/
-const char *
-getfdpath(struct tcb *tcp, int fd)
+int
+getfdpath(struct tcb *tcp, int fd, char *buf, unsigned bufsize)
{
- static char path[PATH_MAX+1];
char linkpath[sizeof("/proc/%u/fd/%u") + 2 * sizeof(int)*3];
ssize_t n;
if (fd < 0)
- return NULL;
+ return -1;
sprintf(linkpath, "/proc/%u/fd/%u", tcp->pid, fd);
- n = readlink(linkpath, path, (sizeof path) - 1);
- if (n <= 0)
- return NULL;
- path[n] = '\0';
- return path;
+ n = readlink(linkpath, buf, bufsize - 1);
+ /*
+ * NB: if buf is too small, readlink doesn't fail,
+ * it returns truncated result (IOW: n == bufsize - 1).
+ */
+ if (n >= 0)
+ buf[n] = '\0';
+ return n;
}
/*
void
printfd(struct tcb *tcp, int fd)
{
- const char *p;
+ char path[PATH_MAX + 1];
- if (show_fd_path && (p = getfdpath(tcp, fd)))
- tprintf("%d<%s>", fd, p);
+ if (show_fd_path && getfdpath(tcp, fd, path, sizeof(path)) >= 0)
+ tprintf("%d<%s>", fd, path);
else
tprintf("%d", fd);
}