From 5bd5a8ed16bded8b3032ecc38ac9de0d02568ac5 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 15 Mar 2024 12:55:23 +0100 Subject: [PATCH] Make sure socket file is created in socket_close testcase If the socket file already existed the path name wouldn't be recorded. Explicitly unlink it before opening and binding the socket. Adjust none/tests/socket_close.stderr.exp for new path name and line numbers. --- none/tests/socket_close.c | 10 +++++----- none/tests/socket_close.stderr.exp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/none/tests/socket_close.c b/none/tests/socket_close.c index 99d277229f..402c0a5d55 100644 --- a/none/tests/socket_close.c +++ b/none/tests/socket_close.c @@ -6,21 +6,21 @@ #include #include - +const char *SPATH = "/tmp/vgtest-foofrob"; int socket_fd; -void *open_socket() +void open_socket() { + unlink (SPATH); /* Make sure socket path doesn't exist yet. */ + socket_fd = socket(AF_UNIX, SOCK_STREAM, 0); fprintf (stderr, "Open socket %d\n", socket_fd); struct sockaddr_un my_addr; memset(&my_addr, 0, sizeof(my_addr)); my_addr.sun_family = AF_UNIX; - strncpy(my_addr.sun_path, "/tmp/foofrob", sizeof(my_addr.sun_path) - 1); + strncpy(my_addr.sun_path, SPATH, sizeof(my_addr.sun_path) - 1); bind(socket_fd, (struct sockaddr *) &my_addr, sizeof(my_addr)); - - return NULL; } int main () diff --git a/none/tests/socket_close.stderr.exp b/none/tests/socket_close.stderr.exp index bec4d63701..74b06244d6 100644 --- a/none/tests/socket_close.stderr.exp +++ b/none/tests/socket_close.stderr.exp @@ -1,7 +1,7 @@ Open socket 3 close socket_fd 3 and close the socket again 3 -File descriptor 3: AF_UNIX socket 3: is already closed +File descriptor 3: AF_UNIX socket 3: /tmp/vgtest-foofrob is already closed at 0x........: close (in /...libc...) by 0x........: main (socket_close.c:37) Previously closed @@ -9,5 +9,5 @@ File descriptor 3: AF_UNIX socket 3: is already closed by 0x........: main (socket_close.c:33) Originally opened at 0x........: socket (in /...libc...) - by 0x........: open_socket (socket_close.c:14) + by 0x........: open_socket (socket_close.c:16) by 0x........: main (socket_close.c:28) -- 2.43.5