summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.txt12
-rw-r--r--logging.c9
-rw-r--r--netmon.c29
3 files changed, 36 insertions, 14 deletions
diff --git a/README.txt b/README.txt
index 4d11242..9e43406 100644
--- a/README.txt
+++ b/README.txt
@@ -1,15 +1,19 @@
Usage:
- netmon [-t <check_interval>] [-n <max_failure>] [-l <log_file>] [-c <cmd>] [-p <ping_host>] [-d]
+ netmon [-t <check_interval>] [-n <max_failure>] [-l <log_file>]
+ [-c <cmd>] [-p <ping_host>] [-d]
-t <check_interval> specify how many seconds to wait between two checks
- -n <max_failure> specify how many continous network failures we get until we reboot the system
+ -n <max_failure> specify how many continuous network failures we get
+ before we reboot the system
-l <log_file> specify the log file
- -c <cmd> the command line to be executed when network failure is detected
+ -c <cmd> the command line to be executed when
+ network failure is detected
-p <ping_host> test the network by pinging given host
-d run as a daemon process
Debugging:
- Declare macro `DEBUG` to enable debug level logging. This is enabled in CMake task by default.
+ Declare macro `DEBUG` to enable debug level logging.
+ This is enabled in CMake task by default.
diff --git a/logging.c b/logging.c
index 90ccf23..b5f8907 100644
--- a/logging.c
+++ b/logging.c
@@ -17,15 +17,18 @@ void log_free(void *logger) {
fclose(logger);
}
-void log_print(void *logger, const char *level, time_t ts, const char *filename, int lineno, const char *msg) {
+void log_print(void *logger, const char *level, time_t ts, const char *filename,
+ int lineno, const char *msg) {
NOTNULL(logger);
NOTNULL(level);
NOTNULL(filename);
NOTNULL(msg);
char timestr[32];
strftime(timestr, 31, "%Y-%m-%d %H:%M:%S", localtime(&ts));
- if (fprintf(logger, "[%s][%s][%s][%d] %s\n", timestr, level, filename, lineno, msg))
+ if (fprintf(logger, "[%s][%s][%s][%d] %s\n", timestr, level, filename,
+ lineno, msg))
fflush(logger);
- if (fprintf(stderr, "[%s][%s][%s][%d] %s\n", timestr, level, filename, lineno, msg))
+ if (fprintf(stderr, "[%s][%s][%s][%d] %s\n", timestr, level, filename,
+ lineno, msg))
fflush(stderr);
}
diff --git a/netmon.c b/netmon.c
index 38cf800..aa478e6 100644
--- a/netmon.c
+++ b/netmon.c
@@ -12,15 +12,29 @@
#include "optparse.h"
const char *logfile = "netmon.log";
-const char *pingdest = NULL; // which host to ping. If NULL, test tcp instead
-const char *failcmd = "reboot"; // cmd to be executed. If NULL, reboot // TODO support blanks
-unsigned int check_interval_seconds = 30; // seconds to sleep between checks
-int max_check_failure = 5; // how many failures to reboot the system
-int as_daemon = 0; // should run as a daemon process
-unsigned int failure_sleep_seconds = 60; // seconds to sleep before resuming check after a network failure is detected
+
+// which host to ping. If NULL, test tcp instead
+const char *pingdest = NULL;
+
+// TODO support blanks
+// cmd to be executed. If NULL, reboot
+const char *failcmd = "reboot";
+
+// seconds to sleep between checks
+unsigned int check_interval_seconds = 30;
+
+// how many failures to reboot the system
+int max_check_failure = 5;
+
+// should run as a daemon process
+int as_daemon = 0;
+
// TODO make failure_sleep_seconds configurable
+// seconds to sleep before resuming check after a network failure is detected
+unsigned int failure_sleep_seconds = 60;
volatile int failure_detected = 0;
+
void *logger = NULL;
void daemonize() {
@@ -128,7 +142,8 @@ void loop() {
log_info(logger, tmp);
system(failcmd);
- snprintf(tmp, 255, "Wait %d secs before resume checking.\n", failure_sleep_seconds);
+ snprintf(tmp, 255, "Wait %d secs before resume checking.\n",
+ failure_sleep_seconds);
log_debug(logger, tmp);
unsigned t = failure_sleep_seconds;
while ((t = sleep(t)));