]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-daemon.c
test-daemon: sleep just a little bit by default
[thirdparty/systemd.git] / src / test / test-daemon.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <unistd.h>
21
22 #include "sd-daemon.h"
23
24 #include "parse-util.h"
25 #include "strv.h"
26
27 int main(int argc, char*argv[]) {
28 _cleanup_strv_free_ char **l = NULL;
29 int n, i;
30 usec_t duration = USEC_PER_SEC / 10;
31
32 if (argc >= 2) {
33 unsigned x;
34
35 assert_se(safe_atou(argv[1], &x) >= 0);
36 duration = x * USEC_PER_SEC;
37 }
38
39 n = sd_listen_fds_with_names(false, &l);
40 if (n < 0) {
41 log_error_errno(n, "Failed to get listening fds: %m");
42 return EXIT_FAILURE;
43 }
44
45 for (i = 0; i < n; i++)
46 log_info("fd=%i name=%s\n", SD_LISTEN_FDS_START + i, l[i]);
47
48 sd_notify(0,
49 "STATUS=Starting up");
50 usleep(duration);
51
52 sd_notify(0,
53 "STATUS=Running\n"
54 "READY=1");
55 usleep(duration);
56
57 sd_notify(0,
58 "STATUS=Reloading\n"
59 "RELOADING=1");
60 usleep(duration);
61
62 sd_notify(0,
63 "STATUS=Running\n"
64 "READY=1");
65 usleep(duration);
66
67 sd_notify(0,
68 "STATUS=Quitting\n"
69 "STOPPING=1");
70 usleep(duration);
71
72 return EXIT_SUCCESS;
73 }