]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-async.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
10 #include "path-util.h"
11 #include "process-util.h"
12 #include "signal-util.h"
14 #include "tmpfile-util.h"
16 TEST(asynchronous_sync
) {
17 assert_se(asynchronous_sync(NULL
) >= 0);
20 TEST(asynchronous_close
) {
21 _cleanup_(unlink_tempfilep
) char name
[] = "/tmp/test-asynchronous_close.XXXXXX";
24 fd
= mkostemp_safe(name
);
26 asynchronous_close(fd
);
30 assert_se(fcntl(fd
, F_GETFD
) == -1);
31 assert_se(errno
== EBADF
);
33 r
= safe_fork("(subreaper)", FORK_RESET_SIGNALS
|FORK_CLOSE_ALL_FDS
|FORK_DEATHSIG_SIGKILL
|FORK_LOG
|FORK_WAIT
, NULL
);
39 assert(make_reaper_process(true) >= 0);
41 fd
= open("/dev/null", O_RDONLY
|O_CLOEXEC
);
43 asynchronous_close(fd
);
47 assert_se(fcntl(fd
, F_GETFD
) == -1);
48 assert_se(errno
== EBADF
);
54 TEST(asynchronous_rm_rf
) {
55 _cleanup_free_
char *t
= NULL
, *k
= NULL
;
58 assert_se(mkdtemp_malloc(NULL
, &t
) >= 0);
59 assert_se(k
= path_join(t
, "somefile"));
60 assert_se(touch(k
) >= 0);
61 assert_se(asynchronous_rm_rf(t
, REMOVE_ROOT
|REMOVE_PHYSICAL
) >= 0);
63 /* Do this once more, form a subreaper. Which is nice, because we can watch the async child even
66 r
= safe_fork("(subreaper)", FORK_RESET_SIGNALS
|FORK_CLOSE_ALL_FDS
|FORK_DEATHSIG_SIGTERM
|FORK_LOG
|FORK_WAIT
, NULL
);
70 _cleanup_free_
char *tt
= NULL
, *kk
= NULL
;
74 assert_se(sigprocmask_many(SIG_BLOCK
, NULL
, SIGCHLD
) >= 0);
75 assert_se(make_reaper_process(true) >= 0);
77 assert_se(mkdtemp_malloc(NULL
, &tt
) >= 0);
78 assert_se(kk
= path_join(tt
, "somefile"));
79 assert_se(touch(kk
) >= 0);
80 assert_se(asynchronous_rm_rf(tt
, REMOVE_ROOT
|REMOVE_PHYSICAL
) >= 0);
85 assert_se(waitid(P_ALL
, 0, &si
, WEXITED
) >= 0);
87 if (access(tt
, F_OK
) < 0) {
88 assert_se(errno
== ENOENT
);
92 /* wasn't the rm_rf() call. let's wait longer */
100 DEFINE_TEST_MAIN(LOG_DEBUG
);