/*
SSSD
Timer Watchdog routines
Copyright (C) Simo Sorce 2016
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.
*/
/* this is intentionally a global variable */
struct watchdog_ctx {
volatile int ticks;
/* To detect time shift. */
int input_interval;
} watchdog_ctx;
static bool watchdog_detect_timeshift(void)
{
/* Time shift detected. We need to restart watchdog. */
"restarting watchdog!\n");
orderly_shutdown(1);
}
return true;
}
return false;
}
/* the watchdog is purposefully *not* handled by the tevent
* signal handler as it is meant to check if the daemon is
* still processing the event queue itself. A stuck process
* may not handle the event queue at all and thus not handle
* signals either */
{
/* Do not count ticks if time shift was detected
* since watchdog was restarted. */
if (watchdog_detect_timeshift()) {
return;
}
/* if a pre-defined number of ticks passed by kills itself */
"Watchdog timer overflow, killing process!\n");
orderly_shutdown(1);
}
}
static void watchdog_reset(void)
{
}
struct tevent_timer *te,
struct timeval current_time,
void *private_data)
{
/* first thing reset the watchdog ticks */
/* then set a new watchodg event */
/* if the function fails the watchdog will kill the
* process soon enough, so we just warn */
if (!watchdog_ctx.te) {
"Failed to create a watchdog timer event!\n");
}
}
{
int ret;
errno = 0;
if (ret == -1) {
"Failed to create watchdog timer (%d) [%s]\n",
return ret;
}
if (interval == 0) {
}
/* Start the timer */
/* we give 1 second head start to the watchdog event */
errno = 0;
if (ret == -1) {
"Failed to create watchdog timer (%d) [%s]\n",
return ret;
}
/* Add the watchdog event and make it fire as fast as the timer */
return EOK;
}
void teardown_watchdog(void)
{
int ret;
/* Disarm the timer */
errno = 0;
if (ret == -1) {
"Failed to destroy watchdog timer (%d) [%s]\n",
}
/* and kill the watchdog event */
}