Introduce getfdinode to obtain inode from fd

* defs.h (getfdinode): New prototype.
* utils.c (getfdinode): New function.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
This commit is contained in:
Fabien Siron 2016-05-26 10:59:07 +00:00 committed by Dmitry V. Levin
parent e4c104ae51
commit f26c22d8b2
2 changed files with 19 additions and 0 deletions

1
defs.h
View File

@ -494,6 +494,7 @@ extern const char *signame(const int);
extern void pathtrace_select(const char *);
extern int pathtrace_match(struct tcb *);
extern int getfdpath(struct tcb *, int, char *, unsigned);
extern unsigned long getfdinode(struct tcb *, int);
extern enum sock_proto getfdproto(struct tcb *, int);
extern const char *xlookup(const struct xlat *, const uint64_t);

18
util.c
View File

@ -630,6 +630,24 @@ getfdproto(struct tcb *tcp, int fd)
#endif
}
unsigned long
getfdinode(struct tcb *tcp, int fd)
{
char path[PATH_MAX + 1];
if (getfdpath(tcp, fd, path, sizeof(path)) >= 0) {
const char *str = STR_STRIP_PREFIX(path, "socket:[");
if (str != path) {
const size_t str_len = strlen(str);
if (str_len && str[str_len - 1] == ']')
return strtoul(str, NULL, 10);
}
}
return 0;
}
void
printfd(struct tcb *tcp, int fd)
{