2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-30 13:58:22 +00:00

tests: fix exiting without closing/removing mqueue

When the setup of the notify options failed, they were exiting the
program without cleaning up the mqueue. Fix this by returning instead
of exiting, since the main function does the cleanup in case of any
failures. If the test succeeds, then it exits successfully.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
This commit is contained in:
Georgia Garcia
2024-03-28 10:50:41 -03:00
parent 0738a2964d
commit 2ff19c8d9c

View File

@@ -120,12 +120,12 @@ void receive_mq_notify(mqd_t mqd)
if (mq_notify(mqd, &sev) == -1) {
perror("FAIL - could not mq_notify");
exit(EXIT_FAILURE);
return;
}
if (write_to_pipe(pipepath) == -1) { // let sender know mq_notify is ready
fprintf(stderr, "FAIL - could not write to pipe\n");
exit(EXIT_FAILURE);
return;
}
sleep(timeout);
@@ -144,7 +144,7 @@ void receive_select(mqd_t mqd)
if (select(mqd + 1, &read_fds, NULL, NULL, &tv) == -1) {
perror("FAIL - could not select");
exit(EXIT_FAILURE);
return;
} else {
if (FD_ISSET(mqd, &read_fds))
receive_message(mqd, 0);
@@ -159,7 +159,7 @@ void receive_poll(mqd_t mqd)
if (poll(fds, 1, timeout * 1000) == -1) {
perror("FAIL - could not poll");
exit(EXIT_FAILURE);
return;
} else {
if (fds[0].revents & POLLIN)
receive_message(mqd, 0);
@@ -171,7 +171,7 @@ void receive_epoll(mqd_t mqd)
int epfd = epoll_create(1);
if (epfd == -1) {
perror("FAIL - could not create epoll");
exit(EXIT_FAILURE);
return;
}
struct epoll_event ev, rev[1];
@@ -179,12 +179,12 @@ void receive_epoll(mqd_t mqd)
ev.data.fd = mqd;
if (epoll_ctl(epfd, EPOLL_CTL_ADD, mqd, &ev) == -1) {
perror("FAIL - could not add mqd to epoll");
exit(EXIT_FAILURE);
return;
}
if (epoll_wait(epfd, rev, 1, timeout * 1000) == -1) {
perror("FAIL - could not epoll_wait");
exit(EXIT_FAILURE);
return;
} else {
if (rev[0].data.fd == mqd && rev[0].events & EPOLLIN)
receive_message(mqd, 0);
@@ -306,7 +306,7 @@ int main(int argc, char *argv[])
int pid = fork();
if (pid == -1) {
perror("FAIL - could not fork");
exit(EXIT_FAILURE);
goto out;
} else if (!pid) {
if (client == NULL) {
usage(argv[0], "client not specified");