31 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) 35 #include <sys/timerfd.h> 39 #include "sd-daemon.h" 50 unsigned long long wakeups_missed;
53 void wait_period (PeriodicData *info)
55 unsigned long long missed;
57 if(read (info->timer_fd, &missed, sizeof (missed)) < 0)
60 DLT_STRING(
"Could not read from timer file descriptor in watchdog.\n"));
65 info->wakeups_missed += (missed - 1);
69 int make_periodic(
unsigned int period, PeriodicData *info)
74 struct itimerspec itval;
79 DLT_STRING(
"Invalid function parameters used for function make_periodic.\n"));
84 fd = timerfd_create (CLOCK_MONOTONIC, 0);
86 info->wakeups_missed = 0;
92 DLT_STRING(
"Can't create timer filedescriptor.\n"));
98 ns = (period - (sec * 1000000)) * 1000;
99 itval.it_interval.tv_sec = sec;
100 itval.it_interval.tv_nsec = ns;
101 itval.it_value.tv_sec = sec;
102 itval.it_value.tv_nsec = ns;
104 return timerfd_settime (fd, 0, &itval,
NULL);
108 void watchdog_thread(
void *v_conf)
112 unsigned int watchdogTimeoutSeconds;
113 unsigned int notifiyPeriodNSec;
125 DLT_STRING(
"Invalid function parameters used for function watchdog_thread.\n"));
130 watchdogUSec = getenv(
"WATCHDOG_USEC");
136 watchdogTimeoutSeconds = atoi(watchdogUSec);
138 if( watchdogTimeoutSeconds > 0 ){
141 notifiyPeriodNSec = watchdogTimeoutSeconds / 2 ;
143 snprintf(str,512,
"systemd watchdog timeout: %u nsec - timer will be initialized: %u nsec\n", watchdogTimeoutSeconds, notifiyPeriodNSec );
146 if (make_periodic (notifiyPeriodNSec, &info) < 0 )
154 if(sd_notify(0,
"WATCHDOG=1") < 0)
167 snprintf(str,512,
"systemd watchdog timeout incorrect: %u\n", watchdogTimeoutSeconds);
182 static pthread_attr_t t_attr;
185 if (pthread_create(&pt, &t_attr, (
void *)watchdog_thread, conf) == 0)
#define DLT_DECLARE_CONTEXT(CONTEXT)
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION)
#define DLT_LOG(CONTEXT, LOGLEVEL, ARGS...)
static char str[DLT_DAEMON_TEXTBUFSIZE]
#define DLT_IMPORT_CONTEXT(CONTEXT)
pthread_t threads[MAX_THREADS]