diff options
author | William Hubbs <w.d.hubbs@gmail.com> | 2017-05-11 13:52:22 -0500 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2017-05-11 13:54:20 -0500 |
commit | a3250e77d412f2290e381b9e7569930d95e4fc5b (patch) | |
tree | f80c4b953ceb73e550346e8d1e2a7d798226ebd5 | |
parent | df027ca4722c8755b23a65db75728b835ccca807 (diff) |
supervise-daemon: save start time and respawn count
This will allow rc-status to display an uptime and restart count for
supervised processes.
-rw-r--r-- | src/rc/supervise-daemon.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c index 13aba1a3..bc5fd3d0 100644 --- a/src/rc/supervise-daemon.c +++ b/src/rc/supervise-daemon.c @@ -171,7 +171,8 @@ static pid_t get_pid(const char *pidfile) return pid; } -static void child_process(char *exec, char **argv) +static void child_process(char *exec, char **argv, char *svcname, + int start_count) { RC_STRINGLIST *env_list; RC_STRING *env; @@ -183,6 +184,9 @@ static void child_process(char *exec, char **argv) char *np; char **c; char cmdline[PATH_MAX]; + time_t start_time; + char start_time_string[20]; + char start_count_string[20]; #ifdef HAVE_PAM pam_handle_t *pamh = NULL; @@ -338,6 +342,13 @@ static void child_process(char *exec, char **argv) c++; } syslog(LOG_INFO, "Running command line: %s", cmdline); + if (svcname) { +start_time = time(NULL); +strftime(start_time_string, 20, "%Y-%m-%d %H:%M:%S", localtime(&start_time)); + rc_service_value_set(svcname, "start_time", start_time_string); +sprintf(start_count_string, "%i", start_count); + rc_service_value_set(svcname, "start_count", start_count_string); + } execvp(exec, argv); #ifdef HAVE_PAM @@ -778,7 +789,7 @@ int main(int argc, char **argv) if (child_pid == -1) eerrorx("%s: fork: %s", applet, strerror(errno)); if (child_pid == 0) - child_process(exec, argv); + child_process(exec, argv, svcname, respawn_count); } } @@ -792,5 +803,5 @@ int main(int argc, char **argv) } exit(EXIT_SUCCESS); } else if (child_pid == 0) - child_process(exec, argv); + child_process(exec, argv, svcname, respawn_count); } |