From: thib Date: Wed, 28 Jun 2000 14:00:51 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: ver1564~564 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e14bf13197ab34331d4f83dd66d435e1ee5e9f0d;p=fcron *** empty log message *** --- diff --git a/conf.c b/conf.c index c0f9e93..d7081b9 100644 --- a/conf.c +++ b/conf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: conf.c,v 1.14 2000-06-25 19:57:37 thib Exp $ */ + /* $Id: conf.c,v 1.15 2000-06-28 14:00:51 thib Exp $ */ #include "fcron.h" @@ -530,9 +530,17 @@ read_file(const char *file_name, CF *cf) cl->cl_file = cf; Alloc(cl, CL); } + /* check for an error */ + if ( ferror(ff) != 0 ) + error("file '%s' is truncated : you should reinstall it", file_name); + /* free last calloc : unused */ free(cl); + if (fgets(buf, sizeof(buf), ff) == NULL || + strncmp(buf, "eof\n", sizeof("eof\n")) != 0) + error("file '%s' is truncated : you should reinstall it", file_name); + fclose(ff); return 0; @@ -625,9 +633,7 @@ save_file(CF *file, char *path) CF *cf = NULL; CL *cl = NULL; FILE *f = NULL; - char check[FNAME_LEN]; CF *start = NULL; - int fd = 0; env_t *env = NULL; struct passwd *pas = NULL; @@ -641,10 +647,6 @@ save_file(CF *file, char *path) debug("Saving %s...", cf->cf_user); - /* create a file in order to detect unattended stop */ - snprintf(check, sizeof(check), "%s.saving", cf->cf_user); - fd = open (check, O_CREAT); - /* open file for writing */ if ( path == NULL ) { if ( (f = fopen(cf->cf_user, "w")) == NULL ) @@ -683,7 +685,7 @@ save_file(CF *file, char *path) } fprintf(f, "%c", '\0'); - /* finally, lines. */ + /* finally, lines. */ for (cl = cf->cf_line_base; cl; cl = cl->cl_next) { if ( fwrite(cl, sizeof(CL), 1, f) != 1 ) error_e("save"); @@ -696,11 +698,13 @@ save_file(CF *file, char *path) } + /* then, write the number of lines to permit to check if the file + * is complete (i.e. fcron may has been interrupted during + * save process */ + fprintf(f, "eof\n"); + fclose(f); - close(fd); - remove(check); - if (file != NULL) break ; diff --git a/fileconf.c b/fileconf.c index e300ba8..c941e2e 100644 --- a/fileconf.c +++ b/fileconf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fileconf.c,v 1.10 2000-06-25 20:03:22 thib Exp $ */ + /* $Id: fileconf.c,v 1.11 2000-06-28 14:01:05 thib Exp $ */ #include "fcrontab.h" @@ -377,7 +377,7 @@ get_nice(char *ptr, int *nice) ptr++; } - if ( (ptr = get_num(ptr, nice, 20, NULL)) == NULL ) + if ( (ptr = get_num(ptr, nice, 21, NULL)) == NULL ) return NULL; if ( negative == 1 ) { @@ -1133,7 +1133,7 @@ save_file(char *path) } fprintf(f, "%c", '\0'); - /* finally, lines. */ + /* then, lines. */ for (line = file->cf_line_base; line; line = line->cl_next) { if ( fwrite(line, sizeof(CL), 1, f) != 1 ) perror("save"); @@ -1144,8 +1144,14 @@ save_file(char *path) fprintf(f, "%s%c", pas->pw_name, '\0'); } } - + + /* finally, write the number of lines to permit to check if the file + * is complete (i.e. fcron may has been interrupted during + * save process */ + fprintf(f, "eof\n"); + fclose(f); } } + diff --git a/global.h b/global.h index 9010f04..52bb553 100644 --- a/global.h +++ b/global.h @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: global.h,v 1.13 2000-06-25 20:07:00 thib Exp $ */ + /* $Id: global.h,v 1.14 2000-06-28 14:01:13 thib Exp $ */ /* @@ -57,7 +57,7 @@ #include "option.h" -#define FILEVERSION "007" /* syntax's version of fcrontabs : +#define FILEVERSION "008" /* syntax's version of fcrontabs : * must have a length of 3 characters */ #define ERR -1