From: Thibault Godouet Date: Sun, 25 Jun 2000 19:57:37 +0000 (+0000) Subject: log explanation "update configuration from" use the complete path, X-Git-Tag: ver2_9_4~645 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=361f7c8252ee12736bb18ea1aaa47b6bb614ac85;p=thirdparty%2Ffcron.git log explanation "update configuration from" use the complete path, not just "." "adding file" "removing file" are explanation (used to be debug) runas added bootrun : bug fix --- diff --git a/conf.c b/conf.c index ef5625d..c0f9e93 100644 --- a/conf.c +++ b/conf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: conf.c,v 1.13 2000-06-22 12:29:49 thib Exp $ */ + /* $Id: conf.c,v 1.14 2000-06-25 19:57:37 thib Exp $ */ #include "fcron.h" @@ -80,7 +80,10 @@ synchronize_dir(const char *dir_name) DIR *dir; struct dirent *den; - explain("update configuration from '%s'", dir_name); + if ( strcmp(dir_name, ".") == 0 ) + explain("update configuration from " FCRONTABS ); + else + explain("update configuration from '%s'", dir_name); if ((dir = opendir("."))) { while ((den = readdir(dir))) { @@ -125,16 +128,16 @@ synchronize_dir(const char *dir_name) /* begin by adding normal files, if any, to database */ for (list_cur = file_list; list_cur; list_cur = list_cur->next ) { if ( getpwnam(list_cur->str) ) { - debug("adding file '%s'", list_cur->str); + explain("adding file '%s'", list_cur->str); synchronize_file(list_cur->str); } else - warn("ignoring file '%s' : not in passwd file.", list_cur->str); + error("ignoring file '%s' : not in passwd file.", list_cur->str); } /* then remove files which are no longer wanted */ for (list_cur = rm_list; list_cur; list_cur = list_cur->next ) { - debug("removing file '%s'", list_cur->str + 3); + explain("removing file '%s'", list_cur->str + 3); delete_file(list_cur->str + 3); /* len("rm.") = 3 */ remove(list_cur->str + 3); remove(list_cur->str); @@ -143,11 +146,11 @@ synchronize_dir(const char *dir_name) /* finally add new files */ for (list_cur = new_list; list_cur; list_cur = list_cur->next ) { if ( getpwnam(list_cur->str + 4) ) { /* len("new.") = 4 */ - debug("adding new file '%s'", list_cur->str + 4); + explain("adding new file '%s'", list_cur->str + 4); synchronize_file(list_cur->str); } else - warn("ignoring file '%s' : not in passwd file.", + error("ignoring file '%s' : not in passwd file.", (list_cur->str + 4)); } @@ -260,7 +263,8 @@ synchronize_file(char *file_name) size)==0 ) ) ) { - new_l->cl_remain = old_l->cl_remain; + if ( new_l->cl_runfreq == old_l->cl_runfreq ) + new_l->cl_remain = old_l->cl_remain; new_l->cl_nextexe = old_l->cl_nextexe; insert_nextexe(new_l); @@ -382,6 +386,9 @@ read_file(const char *file_name, CF *cf) time_t slept = 0; char c; int i; + char *user = NULL; + char *runas = NULL; + struct passwd *pas = NULL; /* open file */ @@ -401,14 +408,19 @@ read_file(const char *file_name, CF *cf) strncmp(buf, "fcrontab-"FILEVERSION"\n", sizeof("fcrontab-"FILEVERSION"\n")) != 0) { - error("File is not valid: ignored."); + error("File '%s' is not valid: ignored.", file_name); error("Maybe this file has been generated by an old version" " of fcron. In this case, you should install it again" " using fcrontab."); return 1; } + /* get the owner's name */ + user = read_str(ff, buf, sizeof(buf)); + + /* get the time & date of the saving */ + /* a new file generated by fcrontab has t_save set to 0 */ if ( fscanf(ff, "%ld", &t_save) != 1 ) error("could not get time and date of saving"); @@ -452,10 +464,16 @@ read_file(const char *file_name, CF *cf) if ( is_td(cl->cl_option) ) { /* set the time and date of the next execution */ if ( cl->cl_nextexe <= now ) { - if ( is_bootrun(cl->cl_option) ) { - debug(" boot-run %s", cl->cl_shell); - set_serial_once(cl->cl_option); - cl->cl_pid = -1; + if ( is_bootrun(cl->cl_option) && t_save != 0) { + if ( --cl->cl_remain > 0 ) { + debug(" cl_remain: %d", cl->cl_remain); + } + else { + cl->cl_remain = cl->cl_runfreq; + debug(" boot-run %s", cl->cl_shell); + set_serial_once(cl->cl_option); + cl->cl_pid = -1; + } } set_next_exe(cl, 1); } @@ -471,6 +489,21 @@ read_file(const char *file_name, CF *cf) add_serial_job(cl); } + /* set the uid */ + if ( is_runas(cl->cl_option) ) { + struct passwd *p = NULL; + runas = read_str(ff, buf, sizeof(buf)); + if ( (p = getpwnam(runas)) == NULL ) + die_e("could not getpwnam() %s", runas); + cl->cl_runas = p->pw_uid; + } + else { + if ( pas == NULL && (pas = getpwnam(user)) == NULL ) + die_e("could not getpwnam() %s", user); + cl->cl_runas = pas->pw_uid; + } + + /* check if the task has not been stopped during execution */ if (cl->cl_pid > 0) { /* job has been stopped during execution : @@ -596,6 +629,7 @@ save_file(CF *file, char *path) CF *start = NULL; int fd = 0; env_t *env = NULL; + struct passwd *pas = NULL; if (file != NULL) start = file; @@ -628,6 +662,9 @@ save_file(CF *file, char *path) * if the syntax has changed */ fprintf(f, "fcrontab-" FILEVERSION "\n"); + /* put the user's name : it is used to check his uid has not changed */ + fprintf(f, "%s%c", cf->cf_user, '\0'); + /* put the time & date of saving : this is use for calcutating * the system down time */ fprintf(f, "%ld", now); @@ -651,6 +688,11 @@ save_file(CF *file, char *path) if ( fwrite(cl, sizeof(CL), 1, f) != 1 ) error_e("save"); fprintf(f, "%s%c", cl->cl_shell, '\0'); + if ( is_runas(cl->cl_option) ) { + if ( (pas = getpwuid(cl->cl_runas)) == NULL ) + die_e("could not getpwuid() %d", cl->cl_runas); + fprintf(f, "%s%c", pas->pw_name, '\0'); + } }