]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-daemon.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / test / test-daemon.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
8c47c732 2/***
8c47c732 3 Copyright 2010 Lennart Poettering
8c47c732
LP
4***/
5
6#include <unistd.h>
7
8dd4c05b
LP
8#include "sd-daemon.h"
9
f06dcdca 10#include "parse-util.h"
8dd4c05b 11#include "strv.h"
8c47c732
LP
12
13int main(int argc, char*argv[]) {
8dd4c05b
LP
14 _cleanup_strv_free_ char **l = NULL;
15 int n, i;
f06dcdca
ZJS
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 }
8dd4c05b
LP
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]);
8c47c732 33
308d72dc
LP
34 sd_notify(0,
35 "STATUS=Starting up");
f06dcdca 36 usleep(duration);
308d72dc
LP
37
38 sd_notify(0,
39 "STATUS=Running\n"
40 "READY=1");
f06dcdca 41 usleep(duration);
308d72dc
LP
42
43 sd_notify(0,
44 "STATUS=Reloading\n"
45 "RELOADING=1");
f06dcdca 46 usleep(duration);
308d72dc 47
8c47c732
LP
48 sd_notify(0,
49 "STATUS=Running\n"
50 "READY=1");
f06dcdca 51 usleep(duration);
308d72dc
LP
52
53 sd_notify(0,
54 "STATUS=Quitting\n"
55 "STOPPING=1");
f06dcdca 56 usleep(duration);
8c47c732 57
8dd4c05b 58 return EXIT_SUCCESS;
8c47c732 59}