Commit a3fd8e58 authored by Eric Dumazet's avatar Eric Dumazet Committed by Stephen Hemminger

ss: should support CONFIG_INET_UDP_DIAG=n kernels

ss -x currently fails if CONFIG_INET_UDP_DIAG=n or old kernels

Also close file descriptors while we are at it.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
parent 50c6f3ee
......@@ -2092,8 +2092,10 @@ static int unix_show_netlink(struct filter *f, FILE *dump_fp)
.msg_iovlen = f->f ? 3 : 1,
};
if (sendmsg(fd, &msg, 0) < 0)
if (sendmsg(fd, &msg, 0) < 0) {
close(fd);
return -1;
}
iov[0] = (struct iovec){
.iov_base = buf,
......@@ -2121,6 +2123,7 @@ static int unix_show_netlink(struct filter *f, FILE *dump_fp)
}
if (status == 0) {
fprintf(stderr, "EOF on netlink\n");
close(fd);
return 0;
}
......@@ -2135,22 +2138,28 @@ static int unix_show_netlink(struct filter *f, FILE *dump_fp)
h->nlmsg_seq != 123456)
goto skip_it;
if (h->nlmsg_type == NLMSG_DONE)
if (h->nlmsg_type == NLMSG_DONE) {
close(fd);
return 0;
}
if (h->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
fprintf(stderr, "ERROR truncated\n");
} else {
errno = -err->error;
perror("TCPDIAG answers");
if (errno != ENOENT)
fprintf(stderr, "UDIAG answers %d\n", errno);
}
return 0;
close(fd);
return -1;
}
if (!dump_fp) {
err = unix_show_sock(h, f);
if (err < 0)
if (err < 0) {
close(fd);
return err;
}
}
skip_it:
......@@ -2165,6 +2174,7 @@ skip_it:
exit(1);
}
}
close(fd);
return 0;
}
......@@ -2241,7 +2251,7 @@ int unix_show(struct filter *f)
cnt = 0;
}
}
fclose(fp);
if (list) {
unix_list_print(list, f);
unix_list_free(list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment