]>
git.proxmox.com Git - mirror_frr.git/blob - lib/systemd.c
341de9eabe0e0584719ca24abff9c50badc132c5
2 * Copyright (C) 2016 Cumulus Networks, Inc.
5 * This file is part of Quagga.
7 * Quagga is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * Quagga 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 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #if defined HAVE_SYSTEMD
28 #include <systemd/sd-daemon.h>
32 * Wrapper this silliness if we
36 systemd_send_information (const char *info
)
38 #if defined HAVE_SYSTEMD
46 * A return of 0 means that we are not watchdoged
49 systemd_get_watchdog_time (int the_process
)
51 #if defined HAVE_SYSTEMD
53 char *watchdog
= NULL
;
56 ret
= sd_watchdog_enabled (0, &usec
);
59 * If return is 0 -> we don't want watchdog
60 * if return is < 0, some sort of failure occurred
66 * systemd can return that this process
67 * is not the expected sender of the watchdog timer
68 * If we set the_process = 0 then we expect to
69 * be able to send the watchdog to systemd
70 * irrelevant of the pid of this process.
72 if (ret
== 0 && the_process
)
75 if (ret
== 0 && !the_process
)
77 watchdog
= getenv ("WATCHDOG_USEC");
81 usec
= atol (watchdog
);
84 return (usec
/ 1000000)/ 3;
91 systemd_send_stopping (void)
93 systemd_send_information ("STOPPING=1");
97 * How many seconds should we wait between watchdog sends
100 struct thread_master
*systemd_master
= NULL
;
103 systemd_send_watchdog (struct thread
*t
)
105 systemd_send_information ("WATCHDOG=1");
107 thread_add_timer(systemd_master
, systemd_send_watchdog
, NULL
, wsecs
, NULL
);
113 systemd_send_started (struct thread_master
*m
, int the_process
)
117 wsecs
= systemd_get_watchdog_time(the_process
);
120 systemd_send_information ("READY=1");
122 thread_add_timer(m
, systemd_send_watchdog
, m
, wsecs
, NULL
);