]> granicus.if.org Git - fcron/commitdiff
*** empty log message ***
authorthib <thib>
Wed, 28 Jun 2000 14:00:51 +0000 (14:00 +0000)
committerthib <thib>
Wed, 28 Jun 2000 14:00:51 +0000 (14:00 +0000)
conf.c
fileconf.c
global.h

diff --git a/conf.c b/conf.c
index c0f9e930090a277a89c5612a1644696e3594ea21..d7081b9595ac99fa2ac6566a13dff398cf1ddefe 100644 (file)
--- 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 ;
 
index e300ba8e93770712b9099574ae3622d1d0b2c97e..c941e2e5b440062393c8e4dfdb1b984976416b3f 100644 (file)
@@ -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);
 
     }
 }
+
index 9010f04cde7d2fb05a63fee2a582a59d2abf4ba2..52bb553a4df6e86fca457ecb0d03daecc7404632 100644 (file)
--- 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