* `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"
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))) {
/* 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);
/* 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));
}
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);
time_t slept = 0;
char c;
int i;
+ char *user = NULL;
+ char *runas = NULL;
+ struct passwd *pas = NULL;
/* open file */
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");
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);
}
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 :
CF *start = NULL;
int fd = 0;
env_t *env = NULL;
+ struct passwd *pas = NULL;
if (file != NULL)
start = file;
* 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);
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');
+ }
}