#include <semaphore.h>
#include <string.h>
#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "test.h"
#define TESTC(c, m) ( (c) || (t_error(#c " failed (%s, " m ")\n", cdescr), 0) )
static void cleanup_sem(void *arg)
{
- TESTR(sem_post(&sem_test), "posting semaphore");
TESTR(sem_destroy(&sem_test), "destroying semaphore");
}
static void cleanup_thread(void *arg)
{
void *res;
+ if (td_test) {
+ TESTR(sem_post(&sem_test), "posting semaphore");
+ TESTR(pthread_join(td_test, &res), "joining auxiliary thread");
+ TESTC(res == 0, "auxiliary thread exit status");
+ }
cleanup_sem(arg);
- if (!td_test)
- return;
- TESTR(pthread_join(td_test, &res), "joining auxiliary thread");
- TESTC(res == 0, "auxiliary thread exit status");
}
static void execute_thread_join(void *arg)
static void cleanup_shm(void *arg)
{
int *fd = arg;
- TESTE(close(*fd), "shm fd");
- TESTE(shm_unlink("/testshm"), "");
+ if (*fd > 0) {
+ TESTE(close(*fd), "shm fd");
+ TESTE(shm_unlink("/testshm"), "");
+ }
}
static struct {