]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-async.c
util-lib: split out all temporary file related calls into tmpfiles-util.c
[thirdparty/systemd.git] / src / test / test-async.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <unistd.h>
4
5 #include "async.h"
6 #include "macro.h"
7 #include "tmpfile-util.h"
8 #include "util.h"
9
10 static bool test_async = false;
11
12 static void *async_func(void *arg) {
13 test_async = true;
14
15 return NULL;
16 }
17
18 int main(int argc, char *argv[]) {
19 int fd;
20 char name[] = "/tmp/test-asynchronous_close.XXXXXX";
21
22 fd = mkostemp_safe(name);
23 assert_se(fd >= 0);
24 asynchronous_close(fd);
25
26 assert_se(asynchronous_job(async_func, NULL) >= 0);
27
28 assert_se(asynchronous_sync(NULL) >= 0);
29
30 sleep(1);
31
32 assert_se(fcntl(fd, F_GETFD) == -1);
33 assert_se(test_async);
34
35 (void) unlink(name);
36
37 return 0;
38 }