commit:     a3250e77d412f2290e381b9e7569930d95e4fc5b
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Thu May 11 18:52:22 2017 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Thu May 11 18:54:20 2017 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a3250e77

supervise-daemon: save start time and respawn count

This will allow rc-status to display an uptime and restart count for
supervised processes.

 src/rc/supervise-daemon.c | 17 ++++++++++++++---
 1 file 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);
 }

Reply via email to