* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: conf.c,v 1.41 2001-04-21 08:48:14 thib Exp $ */
+ /* $Id: conf.c,v 1.42 2001-04-29 22:16:11 thib Exp $ */
#include "fcron.h"
/* proceed to adds or removes */
- /* 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) ) {
- explain("adding file %s", list_cur->str);
- synchronize_file(list_cur->str);
- }
- else
- error("ignoring file \"%s\" : not in passwd file.", list_cur->str);
- }
-
- /* then remove files which are no longer wanted */
+ /* begin by removing files which are no longer wanted */
for (list_cur = rm_list; list_cur; list_cur = list_cur->next ) {
explain("removing file %s", list_cur->str + 3);
delete_file(list_cur->str + 3); /* len("rm.") = 3 */
error_e("Could not remove %s", list_cur->str);
}
+ /* then add normal files, if any, to database */
+ for (list_cur = file_list; list_cur; list_cur = list_cur->next ) {
+ if ( getpwnam(list_cur->str) ) {
+ explain("adding file %s", list_cur->str);
+ synchronize_file(list_cur->str);
+ }
+ else
+ error("ignoring file \"%s\" : not in passwd file.", 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 */
error("Line is not valid (empty shell, runas or mailto field)"
" : ignored");
bzero(cl, sizeof(cl));
+ if (cl->cl_shell) free(cl->cl_shell);
+ if (cl->cl_runas) free(cl->cl_runas);
+ if (cl->cl_mailto) free(cl->cl_mailto);
continue;
}
cl->cl_runas = strdup2(runas_str);
}
- /* we need that here because the user's name (contained in the
+ /* we need that here because the user's name contained in the
* struct CF may be required */
cl->cl_file = cf;
}
if (file == NULL)
- /* file not in list */
+ /* file not in the file list */
return;
/* remove file from file list */
/* save_file() error management */
-#define Save_type(file, type) \
+#define Save_type(f, type) \
{ \
- if ( save_type(file, type) != OK ) { \
+ if ( save_type(f, type) != OK ) { \
error_e("Could not write type : file has not been saved."); \
- fclose(file); \
- remove(cf->cf_user); \
+ fclose(f); \
+ remove(file->cf_user); \
goto next_file; \
} \
}
-#define Save_str(file, type, str) \
+#define Save_str(f, type, str) \
{ \
- if ( save_str(file, type, str) != OK ) { \
+ if ( save_str(f, type, str) != OK ) { \
error_e("Could not write str : file has not been saved."); \
- fclose(file); \
- remove(cf->cf_user); \
+ fclose(f); \
+ remove(file->cf_user); \
goto next_file; \
} \
}
-#define Save_strn(file, type, str, size) \
+#define Save_strn(f, type, str, size) \
{ \
- if ( save_strn(file, type, str, size) != OK ) { \
+ if ( save_strn(f, type, str, size) != OK ) { \
error_e("Could not write strn : file has not been saved."); \
- fclose(file); \
- remove(cf->cf_user); \
+ fclose(f); \
+ remove(file->cf_user); \
goto next_file; \
} \
}
-#define Save_lint(file, type, value) \
+#define Save_lint(f, type, value) \
{ \
- if ( save_lint(file, type, value) != OK ) { \
+ if ( save_lint(f, type, value) != OK ) { \
error_e("Could not write lint : file has not been saved."); \
- fclose(file); \
- remove(cf->cf_user); \
+ fclose(f); \
+ remove(file->cf_user); \
goto next_file; \
} \
}
* a file using a depreciated format generated by an old fcrontab,
* if the syntax has changed */
/* an binary fcrontab *must* start by such a header */
- save_lint(f, S_HEADER_T, S_FILEVERSION );
+ Save_lint(f, S_HEADER_T, S_FILEVERSION );
/* put the user's name : needed to check if his uid has not changed */
/* S_USER_T *must* be the 2nd field of a binary fcrontab */
- save_str(f, S_USER_T, file->cf_user);
+ Save_str(f, S_USER_T, file->cf_user);
/* put the time & date of saving : this is use for calcutating
* the system down time. As it is a new file, we set it to 0 */
/* S_USER_T *must* be the 3rd field of a binary fcrontab */
- save_lint(f, S_TIMEDATE_T, 0);
+ Save_lint(f, S_TIMEDATE_T, now);
/* env variables, */
for (env = file->cf_env_base; env; env = env->e_next)
- save_str(f, S_ENVVAR_T, env->e_val);
+ Save_str(f, S_ENVVAR_T, env->e_val);
/* then, lines. */
for (line = file->cf_line_base; line; line = line->cl_next) {
/* this ones are saved for every lines */
- save_str(f, S_SHELL_T, line->cl_shell);
- save_str(f, S_RUNAS_T, line->cl_runas);
- save_str(f, S_MAILTO_T, line->cl_mailto);
- save_lint(f, S_NEXTEXE_T, line->cl_nextexe);
- save_strn(f, S_OPTION_T, line->cl_option, OPTION_SIZE);
+ Save_str(f, S_SHELL_T, line->cl_shell);
+ Save_str(f, S_RUNAS_T, line->cl_runas);
+ Save_str(f, S_MAILTO_T, line->cl_mailto);
+ Save_lint(f, S_NEXTEXE_T, line->cl_nextexe);
+ Save_strn(f, S_OPTION_T, line->cl_option, OPTION_SIZE);
/* the following are saved only if needed */
if ( line->cl_numexe )
- save_strn(f, S_NUMEXE_T, &line->cl_numexe, 1);
+ Save_strn(f, S_NUMEXE_T, &line->cl_numexe, 1);
if ( is_lavg(line->cl_option) )
- save_strn(f, S_LAVG_T, line->cl_lavg, LAVG_SIZE);
+ Save_strn(f, S_LAVG_T, line->cl_lavg, LAVG_SIZE);
if ( line->cl_until > 0 )
- save_lint(f, S_UNTIL_T, line->cl_until);
+ Save_lint(f, S_UNTIL_T, line->cl_until);
if ( line->cl_nice != 0 )
- save_strn(f, S_NICE_T, &line->cl_nice, 1);
+ Save_strn(f, S_NICE_T, &line->cl_nice, 1);
if ( line->cl_runfreq > 0 ) {
- save_lint(f, S_RUNFREQ_T, line->cl_runfreq);
- save_lint(f, S_REMAIN_T, line->cl_remain);
+ Save_lint(f, S_RUNFREQ_T, line->cl_runfreq);
+ Save_lint(f, S_REMAIN_T, line->cl_remain);
}
- if ( is_freq(line->cl_option) )
+ if ( is_freq(line->cl_option) ) {
/* save the frequency to run the line */
- save_lint(f, S_TIMEFREQ_T, line->cl_timefreq);
+ Save_lint(f, S_TIMEFREQ_T, line->cl_timefreq)
+ }
else {
/* save the time and date bit fields */
- save_strn(f, S_MINS_T, line->cl_mins, bitstr_size(60));
- save_strn(f, S_HRS_T, line->cl_hrs, bitstr_size(24));
- save_strn(f, S_DAYS_T, line->cl_days, bitstr_size(32));
- save_strn(f, S_MONS_T, line->cl_mons, bitstr_size(12));
- save_strn(f, S_DOW_T, line->cl_dow, bitstr_size(8));
+ Save_strn(f, S_MINS_T, line->cl_mins, bitstr_size(60));
+ Save_strn(f, S_HRS_T, line->cl_hrs, bitstr_size(24));
+ Save_strn(f, S_DAYS_T, line->cl_days, bitstr_size(32));
+ Save_strn(f, S_MONS_T, line->cl_mons, bitstr_size(12));
+ Save_strn(f, S_DOW_T, line->cl_dow, bitstr_size(8));
}
/* This field *must* be the last of each line */
- save_type(f, S_ENDLINE_T);
+ Save_type(f, S_ENDLINE_T);
}
fclose(f);