From fdad8c8db14c87d5a64226e9372b0db7d79bcbfc Mon Sep 17 00:00:00 2001 From: Keuin Date: Tue, 28 Dec 2021 06:00:43 +0800 Subject: Log failure count when network failure is detected. Explicit boundary limiting. --- netmon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netmon.c b/netmon.c index fb8bf66..2c500d9 100644 --- a/netmon.c +++ b/netmon.c @@ -28,7 +28,7 @@ void daemonize() { } if (pid > 0) { char buf[32]; - sprintf(buf, "Child process: %d", pid); + snprintf(buf, 31, "Child process: %d", pid); log_info(logger, buf); exit(0); // exit parent process } @@ -180,8 +180,10 @@ void loop() { while (1) { log_info(logger, "Check network."); if (check_network() != 0) { - log_info(logger, "Network failure detected."); ++failures; + char buf[64]; + snprintf(buf, 63, "Network failure detected. counter=%d", failures); + log_info(logger, buf); } else { log_info(logger, "Network is OK."); failures = 0; -- cgit v1.2.3