aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasatake YAMATO <yamato@redhat.com>2024-04-02 06:34:40 +0900
committerMasatake YAMATO <yamato@redhat.com>2024-04-05 18:34:05 +0900
commit099a58dbde6b349c4b5fbebd5116337b2ef2f2fd (patch)
tree8c4a5863b07930626b0a0e8dc5126da8d72fdc17
parent497ada31ef85ae08a2a7d6c3683ce35845705793 (diff)
downloadutil-linux-099a58dbde6b349c4b5fbebd5116337b2ef2f2fd.tar.gz
tests: (test_mkfds::sockdiag) verify the recieved message to detect whether the socket is usable or not
Close #2822 again. Signed-off-by: Masatake YAMATO <yamato@redhat.com> (cherry picked from commit f98a4c12b366ae2b5e01fa30d72eef34f3bab681)
-rw-r--r--tests/helpers/test_mkfds.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c
index 15e9016963..60ebdd6761 100644
--- a/tests/helpers/test_mkfds.c
+++ b/tests/helpers/test_mkfds.c
@@ -3340,6 +3340,25 @@ static int send_diag_request(int diagsd, void *req, size_t req_size)
return 0;
}
+static int recv_diag_request(int diagsd)
+{
+ __attribute__((aligned(sizeof(void *)))) uint8_t buf[8192];
+ const struct nlmsghdr *h;
+ int r = recvfrom(diagsd, buf, sizeof(buf), 0, NULL, NULL);;
+ if (r < 0)
+ return errno;
+
+ h = (void *)buf;
+ if (!NLMSG_OK(h, (size_t)r))
+ return -1;
+
+ if (h->nlmsg_type == NLMSG_ERROR) {
+ struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(h);
+ return - e->error;
+ }
+ return 0;
+}
+
static void *make_sockdiag(const struct factory *factory, struct fdesc fdescs[],
int argc, char ** argv)
{
@@ -3384,6 +3403,16 @@ static void *make_sockdiag(const struct factory *factory, struct fdesc fdescs[],
err(EXIT_FAILURE, "failed in sendmsg()");
}
+ e = recv_diag_request(diagsd);
+ if (e != 0) {
+ close (diagsd);
+ if (e == ENOENT)
+ err(EXIT_ENOENT, "failed in recvfrom()");
+ if (e > 0)
+ err(EXIT_FAILURE, "failed in recvfrom()");
+ if (e < 0)
+ errx(EXIT_FAILURE, "failed in recvfrom() => -1");
+ }
if (diagsd != fdescs[0].fd) {
if (dup2(diagsd, fdescs[0].fd) < 0) {