mirror of
https://sourceware.org/git/glibc.git
synced 2025-05-31 15:01:17 +03:00
sunrpc: Properly clean up if tst-udp-timeout fails
The macro TEST_VERIFY_EXIT is used several times on sunrpc/tst-udp-timeout to exit the test if a condition evaluates to false. The side effect is that the code to terminate the RPC server process is not executed when the program calls exit, so that sub-process stays alive. This commit registers a clean up function with atexit to kill the server process before exiting the main program. Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
This commit is contained in:
parent
0a8ce6a096
commit
f34c4d0f10
@ -29,6 +29,9 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static pid_t server_pid;
|
||||||
|
|
||||||
/* Test data serialization and deserialization. */
|
/* Test data serialization and deserialization. */
|
||||||
|
|
||||||
@ -177,6 +180,14 @@ server_dispatch (struct svc_req *request, SVCXPRT *transport)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Function to be called before exit to make sure the
|
||||||
|
server process is properly killed. */
|
||||||
|
static void
|
||||||
|
kill_server (void)
|
||||||
|
{
|
||||||
|
kill (server_pid, SIGTERM);
|
||||||
|
}
|
||||||
|
|
||||||
/* Implementation of the test client. */
|
/* Implementation of the test client. */
|
||||||
|
|
||||||
static struct test_response
|
static struct test_response
|
||||||
@ -381,16 +392,17 @@ do_test (void)
|
|||||||
TEST_VERIFY_EXIT (transport != NULL);
|
TEST_VERIFY_EXIT (transport != NULL);
|
||||||
TEST_VERIFY (svc_register (transport, PROGNUM, VERSNUM, server_dispatch, 0));
|
TEST_VERIFY (svc_register (transport, PROGNUM, VERSNUM, server_dispatch, 0));
|
||||||
|
|
||||||
pid_t pid = xfork ();
|
server_pid = xfork ();
|
||||||
if (pid == 0)
|
if (server_pid == 0)
|
||||||
{
|
{
|
||||||
svc_run ();
|
svc_run ();
|
||||||
FAIL_EXIT1 ("supposed to be unreachable");
|
FAIL_EXIT1 ("supposed to be unreachable");
|
||||||
}
|
}
|
||||||
|
atexit (kill_server);
|
||||||
test_udp_server (transport->xp_port);
|
test_udp_server (transport->xp_port);
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
xwaitpid (pid, &status, 0);
|
xwaitpid (server_pid, &status, 0);
|
||||||
TEST_VERIFY (WIFEXITED (status) && WEXITSTATUS (status) == EXIT_MARKER);
|
TEST_VERIFY (WIFEXITED (status) && WEXITSTATUS (status) == EXIT_MARKER);
|
||||||
|
|
||||||
SVC_DESTROY (transport);
|
SVC_DESTROY (transport);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user