コード例 #1
0
ファイル: util.c プロジェクト: MoroJr/strace
void
printfd(struct tcb *tcp, int fd)
{
	char path[PATH_MAX + 1];
	if (show_fd_path && getfdpath(tcp, fd, path, sizeof(path)) >= 0) {
		static const char socket_prefix[] = "socket:[";
		const size_t socket_prefix_len = sizeof(socket_prefix) - 1;
		const size_t path_len = strlen(path);

		tprintf("%d<", fd);
		if (show_fd_path > 1 &&
		    strncmp(path, socket_prefix, socket_prefix_len) == 0 &&
		    path[path_len - 1] == ']') {
			unsigned long inodenr;
#define PROTO_NAME_LEN 32
			char proto_buf[PROTO_NAME_LEN];
			const char *proto =
				getfdproto(tcp, fd, proto_buf, PROTO_NAME_LEN);
			inodenr = strtoul(path + socket_prefix_len, NULL, 10);
			if (!print_sockaddr_by_inode(inodenr, proto)) {
				if (proto)
					tprintf("%s:[%lu]", proto, inodenr);
				else
					tprints(path);
			}
		} else {
			print_quoted_string(path, path_len,
					    QUOTE_OMIT_LEADING_TRAILING_QUOTES);
		}
		tprints(">");
	} else
		tprintf("%d", fd);
}
コード例 #2
0
ファイル: util.c プロジェクト: masatake/strace
void
printfd(struct tcb *tcp, int fd)
{
	char path[PATH_MAX + 1];
	if (show_fd_path && getfdpath(tcp, fd, path, sizeof(path)) >= 0) {
		const char *str;
		size_t len;
		unsigned long inode;

		tprintf("%d<", fd);
		if (show_fd_path <= 1
		    || (str = STR_STRIP_PREFIX(path, "socket:[")) == path
		    || !(len = strlen(str))
		    || str[len - 1] != ']'
		    || !(inode = strtoul(str, NULL, 10))
		    || !print_sockaddr_by_inode(tcp, fd, inode)) {
			print_quoted_string(path, strlen(path),
					    QUOTE_OMIT_LEADING_TRAILING_QUOTES);
		}
		tprints(">");
	} else
		tprintf("%d", fd);
}