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