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