and sched_setaffinity syscalls.
* Enhanced decoding of getxpid, getxuid, and getxgid syscalls on alpha.
* Added decoding of bind, listen, and setsockopt direct syscalls on sparc.
+ * Implemented caching of netlink conversations to reduce amount of time
+ spent in decoding socket details in -yy mode.
* Bug fixes
* Fixed build on arc, metag, nios2, or1k, and tile architectures.
#define QUOTE_0_TERMINATED 0x01
#define QUOTE_OMIT_LEADING_TRAILING_QUOTES 0x02
+extern int string_quote(const char *, char *, unsigned int, unsigned int);
extern int print_quoted_string(const char *, unsigned int, unsigned int);
/* a refers to the lower numbered u_arg,
(sizeof(intmax_t)*3 * 2 + sizeof("{tv_sec=%jd, tv_nsec=%jd}"))
extern void printfd(struct tcb *, int);
extern bool print_sockaddr_by_inode(const unsigned long, const char *);
+extern bool print_sockaddr_by_inode_cached(const unsigned long);
extern void print_dirfd(struct tcb *, int);
extern void printsock(struct tcb *, long, int);
extern void print_sock_optmgmt(struct tcb *, long, int);
# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *) 0)->sun_path)
#endif
+typedef struct {
+ unsigned long inode;
+ char *details;
+} cache_entry;
+
+#define CACHE_SIZE 1024U
+static cache_entry cache[CACHE_SIZE];
+#define CACHE_MASK (CACHE_SIZE - 1)
+
+static int
+cache_and_print_inode_details(const unsigned long inode, char *details)
+{
+ cache_entry *e = &cache[inode & CACHE_MASK];
+ free(e->details);
+ e->inode = inode;
+ e->details = details;
+
+ tprints(details);
+ return 1;
+}
+
+bool
+print_sockaddr_by_inode_cached(const unsigned long inode)
+{
+ const cache_entry *e = &cache[inode & CACHE_MASK];
+ if (e && inode == e->inode) {
+ tprints(e->details);
+ return true;
+ }
+ return false;
+}
+
static bool
inet_send_query(const int fd, const int family, const int proto)
{
}
char src_buf[text_size];
+ char *details;
if (!inet_ntop(diag_msg->idiag_family, diag_msg->id.idiag_src,
src_buf, text_size))
dst_buf, text_size))
return -1;
- tprintf("%s:[%s:%u->%s:%u]",
- proto_name,
- src_buf, ntohs(diag_msg->id.idiag_sport),
- dst_buf, ntohs(diag_msg->id.idiag_dport));
+ if (asprintf(&details, "%s:[%s:%u->%s:%u]", proto_name,
+ src_buf, ntohs(diag_msg->id.idiag_sport),
+ dst_buf, ntohs(diag_msg->id.idiag_dport)) < 0)
+ return false;
} else {
- tprintf("%s:[%s:%u]", proto_name, src_buf,
- ntohs(diag_msg->id.idiag_sport));
+ if (asprintf(&details, "%s:[%s:%u]", proto_name, src_buf,
+ ntohs(diag_msg->id.idiag_sport)) < 0)
+ return false;
}
- return 1;
+ return cache_and_print_inode_details(inode, details);
}
static bool
* print obtained information in the following format:
* "UNIX:[" SELF_INODE [ "->" PEER_INODE ][ "," SOCKET_FILE ] "]"
*/
- if (peer || path_len) {
- tprintf("%s:[%lu", proto_name, inode);
- if (peer)
- tprintf("->%u", peer);
- if (path_len) {
- if (path[0] == '\0') {
- tprints(",@");
- print_quoted_string(path + 1, path_len,
- QUOTE_0_TERMINATED);
- } else {
- tprints(",");
- print_quoted_string(path, path_len + 1,
- QUOTE_0_TERMINATED);
- }
+ if (!peer && !path_len)
+ return -1;
+
+ char peer_str[3 + sizeof(peer) * 3];
+ if (peer)
+ snprintf(peer_str, sizeof(peer_str), "->%u", peer);
+ else
+ peer_str[0] = '\0';
+
+ const char *path_str;
+ if (path_len) {
+ char *outstr = alloca(4 * path_len + 4);
+
+ outstr[0] = ',';
+ if (path[0] == '\0') {
+ outstr[1] = '@';
+ string_quote(path + 1, outstr + 2,
+ path_len - 1, QUOTE_0_TERMINATED);
+ } else {
+ string_quote(path, outstr + 1,
+ path_len, QUOTE_0_TERMINATED);
}
- tprints("]");
- return 1;
+ path_str = outstr;
+ } else {
+ path_str = "";
}
- else
+
+ char *details;
+ if (asprintf(&details, "%s:[%lu%s%s]", proto_name, inode,
+ peer_str, path_str) < 0)
return -1;
+
+ return cache_and_print_inode_details(inode, details);
}
static bool
connect_fd, connect_inode, accept_inode);
assert(close(accept_fd) == 0);
- printf("close(%d<UNIX:[%lu,\"%s\"]>) = 0\n",
- accept_fd, accept_inode, av[1]);
+ printf("close(%d<UNIX:[%lu->%lu,\"%s\"]>) = 0\n",
+ accept_fd, accept_inode, connect_inode, av[1]);
connect_fd = socket(PF_LOCAL, SOCK_STREAM, 0);
if (connect_fd < 0)
connect_fd, connect_inode, accept_inode, sun_path1);
assert(close(accept_fd) == 0);
- printf("close(%d<UNIX:[%lu,\"%s\"]>) = 0\n",
- accept_fd, accept_inode, av[1]);
+ printf("close(%d<UNIX:[%lu->%lu,\"%s\"]>) = 0\n",
+ accept_fd, accept_inode, connect_inode, av[1]);
assert(unlink(av[1]) == 0);
if (show_fd_path > 1 &&
strncmp(path, socket_prefix, socket_prefix_len) == 0 &&
path[path_len - 1] == ']') {
- unsigned long inodenr =
+ unsigned long inode =
strtoul(path + socket_prefix_len, NULL, 10);
-#define PROTO_NAME_LEN 32
- char proto_buf[PROTO_NAME_LEN];
- const char *proto =
- getfdproto(tcp, fd, proto_buf, PROTO_NAME_LEN);
- if (!print_sockaddr_by_inode(inodenr, proto))
- tprints(path);
+
+ if (!print_sockaddr_by_inode_cached(inode)) {
+ char buf[256];
+ const char *proto =
+ getfdproto(tcp, fd, buf, sizeof(buf));
+ if (!print_sockaddr_by_inode(inode, proto))
+ tprints(path);
+ }
} else {
print_quoted_string(path, path_len,
QUOTE_OMIT_LEADING_TRAILING_QUOTES);
* Returns 0 if QUOTE_0_TERMINATED is set and NUL was seen, 1 otherwise.
* Note that if QUOTE_0_TERMINATED is not set, always returns 1.
*/
-static int
+int
string_quote(const char *instr, char *outstr, const unsigned int size,
const unsigned int style)
{