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