Systemd/src/test/test-async.c

40 lines
760 B
C
Raw Normal View History

/* SPDX-License-Identifier: LGPL-2.1-or-later */
2014-06-21 22:07:11 +02:00
#include <fcntl.h>
2014-06-21 22:07:11 +02:00
#include <unistd.h>
#include "async.h"
#include "macro.h"
#include "tmpfile-util.h"
#include "util.h"
2014-06-21 22:07:11 +02:00
static bool test_async = false;
static void *async_func(void *arg) {
test_async = true;
return NULL;
}
int main(int argc, char *argv[]) {
int fd;
char name[] = "/tmp/test-asynchronous_close.XXXXXX";
fd = mkostemp_safe(name);
2014-06-21 22:07:11 +02:00
assert_se(fd >= 0);
asynchronous_close(fd);
2014-06-21 22:07:11 +02:00
assert_se(asynchronous_job(async_func, NULL) >= 0);
assert_se(asynchronous_sync(NULL) >= 0);
2014-06-21 22:07:11 +02:00
sleep(1);
assert_se(fcntl(fd, F_GETFD) == -1);
assert_se(test_async);
2018-11-30 21:15:57 +01:00
(void) unlink(name);
2014-08-16 14:19:06 +02:00
2014-06-21 22:07:11 +02:00
return 0;
}