From 25a661b0ae6f8c11cee9e887922241fa850c87af Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Mon, 24 Aug 2009 13:04:04 -0400 Subject: [PATCH] only ReadTimestamps for updated crontabs Signed-off-by: Jim Pryor --- database.c | 22 ++++++++++------------ main.c | 7 +++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/database.c b/database.c index 0b7050d..13702cb 100644 --- a/database.c +++ b/database.c @@ -9,9 +9,9 @@ #include "defs.h" -Prototype int CheckUpdates(const char *dpath, const char *user_override, time_t t1, time_t t2); +Prototype void CheckUpdates(const char *dpath, const char *user_override, time_t t1, time_t t2); Prototype void SynchronizeDir(const char *dpath, const char *user_override, int initial_scan); -Prototype void ReadTimestamps(int initial_scan); +Prototype void ReadTimestamps(const char *user); Prototype int TestJobs(time_t t1, time_t t2); Prototype int TestStartupJobs(void); Prototype int ArmJob(CronFile *file, CronLine *line, time_t t1, time_t t2); @@ -90,7 +90,7 @@ const char *FreqAry[] = { * is NULL then the files in the directory belong to the user whose name is * the file, otherwise they belong to the user_override user. */ -int +void CheckUpdates(const char *dpath, const char *user_override, time_t t1, time_t t2) { FILE *fi; @@ -98,12 +98,10 @@ CheckUpdates(const char *dpath, const char *user_override, time_t t1, time_t t2) char *fname, *ptok, *job; char *path; - if (DebugOpt) - logn(LOG_DEBUG, "CheckUpdates on %s/%s\n", dpath, CRONUPDATE); - asprintf(&path, "%s/%s", dpath, CRONUPDATE); if ((fi = fopen(path, "r")) != NULL) { remove(path); + logn(LOG_INFO, "reading %s/%s\n", dpath, CRONUPDATE); while (fgets(buf, sizeof(buf), fi) != NULL) { /* * if buf has only sep chars, return NULL and point ptok at buf's terminating 0 @@ -117,9 +115,10 @@ CheckUpdates(const char *dpath, const char *user_override, time_t t1, time_t t2) SynchronizeFile(dpath, fname, user_override); else if (!getpwnam(fname)) logn(LOG_WARNING, "ignoring %s/%s (non-existent user)\n", dpath, fname); - else if (*ptok == 0 || *ptok == '\n') + else if (*ptok == 0 || *ptok == '\n') { SynchronizeFile(dpath, fname, fname); - else { + ReadTimestamps(fname); + } else { /* if fname is followed by whitespace, we prod any following jobs */ CronFile *file = FileBase; while (file) { @@ -158,7 +157,6 @@ CheckUpdates(const char *dpath, const char *user_override, time_t t1, time_t t2) fclose(fi); } free(path); - return (fi != NULL); } void @@ -220,7 +218,7 @@ SynchronizeDir(const char *dpath, const char *user_override, int initial_scan) void -ReadTimestamps(int initial_scan) +ReadTimestamps(const char *user) { CronFile *file; CronLine *line; @@ -232,7 +230,7 @@ ReadTimestamps(int initial_scan) file = FileBase; while (file != NULL) { - if (file->cf_Deleted == 0) { + if (file->cf_Deleted == 0 && (!user || strcmp(user, file->cf_UserName) == 0)) { line = file->cf_LineBase; while (line != NULL) { if (line->cl_Timestamp) { @@ -253,7 +251,7 @@ ReadTimestamps(int initial_scan) } } fclose(fi); - } else if (initial_scan) { + } else { logn(LOG_NOTICE, "no timestamp found (user %s job %s)\n", file->cf_UserName, line->cl_JobName); /* softerror, do not exit the program */ } diff --git a/main.c b/main.c index 3323e75..d4f38fb 100644 --- a/main.c +++ b/main.c @@ -243,7 +243,7 @@ main(int ac, char **av) logn(LOG_INFO,"%s " VERSION " yacron, started with loglevel %s\n", av[0], LevelAry[LogLevel]); SynchronizeDir(CDir, NULL, 1); SynchronizeDir(SCDir, "root", 1); - ReadTimestamps(1); + ReadTimestamps(NULL); TestStartupJobs(); /* @startup jobs only run when crond is started, not when their crontab is loaded */ { @@ -280,10 +280,9 @@ main(int ac, char **av) rescan = 60; SynchronizeDir(CDir, NULL, 0); SynchronizeDir(SCDir, "root", 0); - ReadTimestamps(0); + ReadTimestamps(NULL); } else { - if (CheckUpdates(CDir, NULL, t1, t2)) - ReadTimestamps(0); + CheckUpdates(CDir, NULL, t1, t2); CheckUpdates(SCDir, "root", t1, t2); } if (DebugOpt) -- 2.11.4.GIT