]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-daemon.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / test / test-daemon.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <unistd.h>
4
5 #include "sd-daemon.h"
6
7 #include "parse-util.h"
8 #include "strv.h"
9
10 int main(int argc, char *argv[]) {
11 _cleanup_strv_free_ char **l = NULL;
12 int n, i;
13 usec_t duration = USEC_PER_SEC / 10;
14
15 if (argc >= 2) {
16 unsigned x;
17
18 assert_se(safe_atou(argv[1], &x) >= 0);
19 duration = x * USEC_PER_SEC;
20 }
21
22 n = sd_listen_fds_with_names(false, &l);
23 if (n < 0) {
24 log_error_errno(n, "Failed to get listening fds: %m");
25 return EXIT_FAILURE;
26 }
27
28 for (i = 0; i < n; i++)
29 log_info("fd=%i name=%s\n", SD_LISTEN_FDS_START + i, l[i]);
30
31 sd_notify(0,
32 "STATUS=Starting up");
33 usleep(duration);
34
35 sd_notify(0,
36 "STATUS=Running\n"
37 "READY=1");
38 usleep(duration);
39
40 sd_notify(0,
41 "STATUS=Reloading\n"
42 "RELOADING=1");
43 usleep(duration);
44
45 sd_notify(0,
46 "STATUS=Running\n"
47 "READY=1");
48 usleep(duration);
49
50 sd_notify(0,
51 "STATUS=Quitting\n"
52 "STOPPING=1");
53 usleep(duration);
54
55 return EXIT_SUCCESS;
56 }