Also, don't bother unloading entries right before we exit.
---
 crond.c | 40 +++++++++++-----------------------------
 1 file changed, 11 insertions(+), 29 deletions(-)

diff --git a/crond.c b/crond.c
index 7974b1f..ca339ea 100644
--- a/crond.c
+++ b/crond.c
@@ -73,18 +73,6 @@ loginfo(const char *fmt, ...)
 }
 
 static void
-logwarn(const char *fmt, ...)
-{
-       va_list ap;
-       va_start(ap, fmt);
-       if (nflag == 0)
-               vsyslog(LOG_WARNING, fmt, ap);
-       else
-               vfprintf(stderr, fmt, ap);
-       va_end(ap);
-}
-
-static void
 logerr(const char *fmt, ...)
 {
        va_list ap;
@@ -391,7 +379,7 @@ freecte(struct ctabentry *cte, int nfields)
 }
 
 static void
-unloadentries(void)
+unloadentries(struct ctabentry *ctab)
 {
        struct ctabentry *cte, *tmp;
 
@@ -399,13 +387,12 @@ unloadentries(void)
                tmp = cte->next;
                freecte(cte, 6);
        }
-       ctab = NULL;
 }
 
 static int
 loadentries(void)
 {
-       struct ctabentry *cte;
+       struct ctabentry *cte, *newctab = NULL;
        FILE *fp;
        char *line = NULL, *p, *col;
        int r = 0, y;
@@ -478,12 +465,16 @@ loadentries(void)
                        r = -1;
                        break;
                }
-               cte->next = ctab;
-               ctab = cte;
+               cte->next = newctab;
+               newctab = cte;
        }
 
-       if (r < 0)
-               unloadentries();
+       if (r < 0) {
+               unloadentries(newctab);
+       } else {
+               unloadentries(ctab);
+               ctab = newctab;
+       }
 
        free(line);
        fclose(fp);
@@ -492,14 +483,6 @@ loadentries(void)
 }
 
 static void
-reloadentries(void)
-{
-       unloadentries();
-       if (loadentries() < 0)
-               logwarn("warning: discarding old crontab entries\n");
-}
-
-static void
 sighandler(int sig)
 {
        switch (sig) {
@@ -576,14 +559,13 @@ main(int argc, char *argv[])
                if (quit == 1) {
                        if (nflag == 0)
                                unlink(pidfile);
-                       unloadentries();
                        /* Don't wait or kill forked processes, just exit */
                        break;
                }
 
                if (reload == 1 || chldreap == 1) {
                        if (reload == 1) {
-                               reloadentries();
+                               loadentries();
                                reload = 0;
                        }
                        if (chldreap == 1) {
-- 
2.13.2


Reply via email to