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:
parent
e4c104ae51
commit
f26c22d8b2
1
defs.h
1
defs.h
@ -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
18
util.c
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user