]> git.neil.brown.name Git - metad.git/blobdiff - daemon.c
Assorted reformating
[metad.git] / daemon.c
index 02c7c98560e875a3fbb5749011b801f687244afa..e4fd224f2ec319db1312ae3d69c6cf13abca34fd 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -13,13 +13,11 @@ typedef struct daemon_opts
 static int daemon_opt(service_t sv, char *opt)
 {
        /* understand min= period= */
-       if (strncmp(opt, "min=", 4)==0)
-       {
+       if (strncmp(opt, "min=", 4)==0) {
                c(sv)->min = atoi(opt+4);
                return 1;
        }
-       if (strncmp(opt, "period=", 7) == 0)
-       {
+       if (strncmp(opt, "period=", 7) == 0) {
                char *cp = opt+7;
                int num = atoi(cp);
                if (num==0) num=1;
@@ -63,13 +61,11 @@ static void daemon_check(service_t sv)
        env[1] = "METAD_ARG=";
        env[2] = NULL;
        while (c(sv)->min > 0 && count_procs(sv) < c(sv)->min)
-       {
                if (new_proc(sv, env)<=0)
                        break;
-       }
+
        if (c(sv)->period > 0 &&
-           c(sv)->last_start + c(sv)->period <= time(0))
-       {
+           c(sv)->last_start + c(sv)->period <= time(0)) {
                env[0] = "METAD_REASON=period";
                new_proc(sv, env);
                c(sv)->last_start = time(0); /* even if it didn't start, we tried */
@@ -78,29 +74,23 @@ static void daemon_check(service_t sv)
                waituntil(c(sv)->last_start + c(sv)->period);
 }
 
+static void daemon_init(service_t to)
+{
+       /* create ->classinfo with defaults */
+       daemon_t n;
+
+       n = (daemon_t)malloc(sizeof(struct daemon_opts));
+       n->min = 0;
+       n->period = 0;
+       n->last_start = 0;
+       to->classinfo = n;
+}
+
 static void daemon_copy(service_t from, service_t to)
 {
-       /* copy the classinfo - min and period */
-       daemon_t n; // o;
-       if (from)
-       {
-               /* no special state to copy
-                * the new service should have parsed its own args
-                * - simonb 11nov2003
-                */
-               //o = from->classinfo;
-               //n->min = o->min;
-               //n->period = o->period;
-               //n->last_start = o->last_start;
-       }
-       else
-       {
-               n = (daemon_t)malloc(sizeof(struct daemon_opts));
-               n->min = 0;
-               n->period = 0;
-               n->last_start = 0;
-               to->classinfo = n;
-       }
+       /* copy the 'state' classinfo - last_start */
+
+       c(to)->last_start = c(from)->last_start;
 }
 
 static void daemon_freestate(service_t sv)
@@ -116,7 +106,6 @@ static void daemon_newparent(service_t sv, proc_t p)
 
 static void daemon_newchild(service_t sv)
 {
-
 }
 
 static void daemon_send(service_t sv)
@@ -133,6 +122,7 @@ struct class daemon_class = {
        .c_process_opt  = daemon_opt,
        .register_service = daemon_register,
        .c_check_service= daemon_check,
+       .init_state     = daemon_init,
        .copy_state     = daemon_copy,
        .free_state     = daemon_freestate,
        .send_class     = daemon_send,