From f26c22d8b261c80fbc2462a90018cc69b8dfc584 Mon Sep 17 00:00:00 2001 From: Fabien Siron Date: Thu, 26 May 2016 10:59:07 +0000 Subject: [PATCH] Introduce getfdinode to obtain inode from fd * defs.h (getfdinode): New prototype. * utils.c (getfdinode): New function. Co-authored-by: Dmitry V. Levin --- defs.h | 1 + util.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/defs.h b/defs.h index 0837b9ce..38fedfc1 100644 --- a/defs.h +++ b/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); diff --git a/util.c b/util.c index e33b0a95..c4128def 100644 --- a/util.c +++ b/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) { -- 2.40.0