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