lkml.org 
[lkml]   [2002]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Subjectsoftdog doesn't work on 2.4.20-pre10?
Date
hi

I have the softdog running on some of my machines, and I noticed it didn't
work very well. I've got this little program feeding the dog (attached), so
if it gets killed, the machine should reboot.

but - this doesn't happen!

can anyone take a look at this?

roy
--
Roy Sigurd Karlsbakk, Datavaktmester
ProntoTV AS - http://www.pronto.tv/
Tel: +47 9801 3356

Computers are like air conditioners.
They stop working when you open Windows.
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <syslog.h>
#include "watchdog.h"

#define TIMEOUT_DEFAULT 60

int fd;

void sig_any() {
syslog(LOG_EMERG, "feedthedog killed by untrapped signal. System will be rebooted by watchdog.");
exit(0);
}

void sig_term() {
syslog(LOG_NOTICE, "Exiting, shutting down watchdog...");
if (write(fd, "V", 1) == -1) {
syslog(LOG_NOTICE, "Failed!");
exit(1);
}
if (close(fd) == -1) {
syslog(LOG_NOTICE, "Failed!");
exit(1);
}
syslog(LOG_NOTICE, "Watchdog successfully shut down!");
exit(0);
}

void get_info() {
int timeout;
struct watchdog_info info;

ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
syslog(LOG_INFO, "Watchdog timeout is %d seconds\n", timeout);

ioctl(fd, WDIOC_GETSUPPORT, &info);
syslog(LOG_INFO, "Watchdog options: 0x%04x", info.options);
syslog(LOG_INFO, "Watchdog firmware ver: %d", info.firmware_version);
syslog(LOG_INFO, "Watchdog type:%s", info.identity);
}

int main() {
int i,timeout;

openlog("feedthedog", LOG_PID, LOG_DAEMON);

if ((fd = open("/dev/watchdog", O_WRONLY)) == -1) {
perror("open");
exit(1);
}

timeout = atoi(getenv("WATCHDOG_TIMEOUT"));
if (timeout <= 0) {
syslog(LOG_WARNING, "Timeout set to %d. Using default.", timeout);
timeout = TIMEOUT_DEFAULT;
}

get_info();
for (i=1;i<=_NSIG;i++) {
switch (i) {
case SIGSTOP:
case SIGKILL:
break;
case SIGTERM:
signal(SIGTERM, sig_term);
break;
default:
signal(i, sig_any);
break;
}
}

if (fork())
exit(0);

syslog(LOG_INFO, "Watchdog feeder started");

while (1) {
write(fd, "\0", 1);
sleep(10);
}

return 0;
}
\
 
 \ /
  Last update: 2005-03-22 13:29    [W:0.076 / U:0.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site