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