]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-daemon.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / test / test-daemon.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
8c47c732
LP
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
5430f7f2
LP
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
8c47c732
LP
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
5430f7f2 15 Lesser General Public License for more details.
8c47c732 16
5430f7f2 17 You should have received a copy of the GNU Lesser General Public License
8c47c732
LP
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
21#include <unistd.h>
22
8dd4c05b
LP
23#include "sd-daemon.h"
24
f06dcdca 25#include "parse-util.h"
8dd4c05b 26#include "strv.h"
8c47c732
LP
27
28int main(int argc, char*argv[]) {
8dd4c05b
LP
29 _cleanup_strv_free_ char **l = NULL;
30 int n, i;
f06dcdca
ZJS
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 }
8dd4c05b
LP
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]);
8c47c732 48
308d72dc
LP
49 sd_notify(0,
50 "STATUS=Starting up");
f06dcdca 51 usleep(duration);
308d72dc
LP
52
53 sd_notify(0,
54 "STATUS=Running\n"
55 "READY=1");
f06dcdca 56 usleep(duration);
308d72dc
LP
57
58 sd_notify(0,
59 "STATUS=Reloading\n"
60 "RELOADING=1");
f06dcdca 61 usleep(duration);
308d72dc 62
8c47c732
LP
63 sd_notify(0,
64 "STATUS=Running\n"
65 "READY=1");
f06dcdca 66 usleep(duration);
308d72dc
LP
67
68 sd_notify(0,
69 "STATUS=Quitting\n"
70 "STOPPING=1");
f06dcdca 71 usleep(duration);
8c47c732 72
8dd4c05b 73 return EXIT_SUCCESS;
8c47c732 74}