]> granicus.if.org Git - strace/commitdiff
Introduce getfdinode to obtain inode from fd
authorFabien Siron <fabien.siron@epita.fr>
Thu, 26 May 2016 10:59:07 +0000 (10:59 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 5 Jun 2017 11:52:11 +0000 (11:52 +0000)
* defs.h (getfdinode): New prototype.
* utils.c (getfdinode): New function.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
defs.h
util.c

diff --git a/defs.h b/defs.h
index 0837b9cec872a9fbf5a142259ce3d3ceaadee14a..38fedfc1e998736d408cbf78c04ddf1b5fb912a5 100644 (file)
--- 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 e33b0a95f29a612654f8e771bbc24b4f40956eeb..c4128def8ad098750ea6e0d44f0f7c1f7baed877 100644 (file)
--- 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)
 {