]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-async.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / test / test-async.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
e6b5c5d0
RC
2
3#include <unistd.h>
4
5#include "async.h"
e6b5c5d0 6#include "macro.h"
e4de7287 7#include "tmpfile-util.h"
0d39fa9c 8#include "util.h"
e6b5c5d0
RC
9
10static bool test_async = false;
11
12static void *async_func(void *arg) {
13 test_async = true;
14
15 return NULL;
16}
17
18int main(int argc, char *argv[]) {
19 int fd;
20 char name[] = "/tmp/test-asynchronous_close.XXXXXX";
21
646853bd 22 fd = mkostemp_safe(name);
e6b5c5d0
RC
23 assert_se(fd >= 0);
24 asynchronous_close(fd);
c1d630d5 25
e6b5c5d0 26 assert_se(asynchronous_job(async_func, NULL) >= 0);
c1d630d5 27
d00c2631 28 assert_se(asynchronous_sync(NULL) >= 0);
e6b5c5d0
RC
29
30 sleep(1);
31
32 assert_se(fcntl(fd, F_GETFD) == -1);
33 assert_se(test_async);
34
f4f84a8a 35 (void) unlink(name);
1f532d7e 36
e6b5c5d0
RC
37 return 0;
38}