From 89675403d81e9e95189e7ad3c34f05716b93ee27 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 17 May 2013 15:15:37 +0200 Subject: [PATCH] Add support for service restart counter. This commit adds a statistics counter to the finit svc_t process struct which is incremented every time a process is restarted by the service monitor. Signed-off-by: Joachim Nilsson --- svc.c | 6 +++++- svc.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/svc.c b/svc.c index 4d29b2b1..e22816e7 100644 --- a/svc.c +++ b/svc.c @@ -262,8 +262,10 @@ void svc_monitor(void) procname_kill(name, SIGTERM); /* Restarting lost service. */ - if (svc_enabled(svc, 0, NULL)) + if (svc_enabled(svc, 0, NULL)) { + svc->stat_restart_counter++; svc_start(svc); + } break; } @@ -383,6 +385,7 @@ int svc_stop(svc_t *svc) if (svc->pid <= 1) { _d("Bad PID %d for %s, SIGTERM", svc->pid, svc->desc); svc->pid = 0; + svc->stat_restart_counter = 0; return 1; } @@ -391,6 +394,7 @@ int svc_stop(svc_t *svc) res = kill(svc->pid, SIGTERM); print_result(res); svc->pid = 0; + svc->stat_restart_counter = 0; return res; } diff --git a/svc.h b/svc.h index 68c73114..63a16b41 100644 --- a/svc.h +++ b/svc.h @@ -50,6 +50,7 @@ typedef enum { typedef struct svc { pid_t pid; int reload; + unsigned int stat_restart_counter; /* Incremented for each restart by service monitor. */ char cmd[MAX_ARG_LEN]; char args[MAX_NUM_SVC_ARGS][MAX_ARG_LEN]; char desc[MAX_STR_LEN];