1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*
* (C) 2015 by Arturo Borrero Gonzalez <arturo@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "systemd.h"
#include "conntrackd.h"
#include "alarm.h"
#include "log.h"
#include <systemd/sd-daemon.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
static struct alarm_block sd_watchdog;
static uint64_t sd_watchdog_interval;
static void sd_ct_watchdog_alarm(struct alarm_block *a, void *data)
{
sd_notify(0, "WATCHDOG=1");
add_alarm(&sd_watchdog, 0, sd_watchdog_interval);
}
void sd_ct_watchdog_init(void)
{
int ret;
if (CONFIG(systemd) == 0)
return;
ret = sd_watchdog_enabled(0, &sd_watchdog_interval);
if (ret < 0) {
dlog(LOG_WARNING, "failed to get watchdog details from "
"systemd: %s", strerror(-ret));
return;
} else if (ret == 0) {
/* no watchdog required */
return;
}
/* from man page, recommended interval is half of set by admin */
sd_watchdog_interval = sd_watchdog_interval / 2;
init_alarm(&sd_watchdog, &sd_watchdog_interval, sd_ct_watchdog_alarm);
add_alarm(&sd_watchdog, 0, sd_watchdog_interval);
}
void sd_ct_init(void)
{
if (CONFIG(systemd) == 0)
return;
sd_notify(0, "READY=1");
}
void sd_ct_mainpid(pid_t pid)
{
if (CONFIG(systemd) == 0)
return;
sd_notifyf(0, "MAINPID=%d", pid);
}
void sd_ct_stop(void)
{
if (CONFIG(systemd) == 0)
return;
sd_notify(0, "STOPPING=1");
}
|