]> granicus.if.org Git - fcron/commitdiff
more function return code checking
authorthib <thib>
Mon, 1 Jan 2007 18:49:43 +0000 (18:49 +0000)
committerthib <thib>
Mon, 1 Jan 2007 18:49:43 +0000 (18:49 +0000)
fcron.c
fcrondyn.c
fcronsighup.c

diff --git a/fcron.c b/fcron.c
index 436653928048af164e6a28ae32f1ab2234bd6a45..5325029753adff02888625238bc01ac9f42b3719 100644 (file)
--- a/fcron.c
+++ b/fcron.c
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcron.c,v 1.78 2006-05-20 16:27:10 thib Exp $ */
+ /* $Id: fcron.c,v 1.79 2007-01-01 18:51:15 thib Exp $ */
 
 #include "fcron.h"
 
@@ -33,7 +33,7 @@
 #include "socket.h"
 #endif
 
-char rcs_info[] = "$Id: fcron.c,v 1.78 2006-05-20 16:27:10 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.79 2007-01-01 18:51:15 thib Exp $";
 
 void main_loop(void);
 void check_signal(void);
@@ -258,9 +258,12 @@ get_lock()
        if ( lockf(fileno(daemon_lockfp), F_TLOCK, 0) != 0 )
 #endif /* ! HAVE_FLOCK */
            {
-               fscanf(daemon_lockfp, "%d", &otherpid);
-               die_e("can't lock %s, running daemon's pid may be %d",
-                     pidfile, otherpid);
+               if ( fscanf(daemon_lockfp, "%d", &otherpid) >= 1 )
+                   die_e("can't lock %s, running daemon's pid may be %d",
+                         pidfile, otherpid);
+               else
+                   die_e("can't lock %s, and unable to read running"
+                         " daemon's pid", pidfile);
            }
 
     fcntl(fd, F_SETFD, 1);
@@ -268,7 +271,8 @@ get_lock()
     rewind(daemon_lockfp);
     fprintf(daemon_lockfp, "%d\n", (int) daemon_pid);
     fflush(daemon_lockfp);
-    ftruncate(fileno(daemon_lockfp), ftell(daemon_lockfp));
+    if ( ftruncate(fileno(daemon_lockfp), ftell(daemon_lockfp)) < 0 )
+       error_e("Unable to ftruncate(fileno(daemon_lockfp), ftell(daemon_lockfp))");
 
     /* abandon fd and daemon_lockfp even though the file is open. we need to
      * keep it open and locked, but we don't need the handles elsewhere.
index 640c54b5f52085dc41acce7f9b7247e32a35c6de..d48a22adedf3369bcde8ac08c995618edce4f2ca 100644 (file)
@@ -22,7 +22,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcrondyn.c,v 1.16 2006-06-05 20:00:48 thib Exp $ */
+ /* $Id: fcrondyn.c,v 1.17 2007-01-01 18:50:38 thib Exp $ */
 
 /* fcrondyn : interact dynamically with running fcron process :
  *     - list jobs, with their status, next time of execution, etc
@@ -35,7 +35,7 @@
 #include "allow.h"
 #include "read_string.h"
 
-char rcs_info[] = "$Id: fcrondyn.c,v 1.16 2006-06-05 20:00:48 thib Exp $";
+char rcs_info[] = "$Id: fcrondyn.c,v 1.17 2007-01-01 18:50:38 thib Exp $";
 
 void info(void);
 void usage(void);
@@ -533,7 +533,8 @@ talk_fcron(char *cmd_str, int fd)
            return ERR;
        }
        else {
-           write(STDOUT_FILENO, buf, read_len);
+           if ( write(STDOUT_FILENO, buf, read_len) < 0 )
+               error_e("unable to write() to STDOUT_FILENO");
            if ( read_len >= sizeof(END_STR) &&
                 strncmp(&buf[read_len-sizeof(END_STR)], END_STR, sizeof(END_STR)) == 0)
                break;
index a63b7449ac688150ea9499d762b850ebf98436f0..34eb01fe2a310260fd1940ea9dbfc3d754cd81c6 100644 (file)
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcronsighup.c,v 1.10 2006-05-20 16:22:37 thib Exp $ */
+ /* $Id: fcronsighup.c,v 1.11 2007-01-01 18:49:43 thib Exp $ */
 
 #include "fcronsighup.h"
 #include "global.h"
 #include "allow.h"
 
-char rcs_info[] = "$Id: fcronsighup.c,v 1.10 2006-05-20 16:22:37 thib Exp $";
+char rcs_info[] = "$Id: fcronsighup.c,v 1.11 2007-01-01 18:49:43 thib Exp $";
 
 void usage(void);
 void sig_daemon(void);
@@ -83,7 +83,8 @@ read_pid(void)
     pid_t pid = 0;
     
     if ((fp = fopen(pidfile, "r")) != NULL) {
-       fscanf(fp, "%d", (int *) &pid);    
+       if ( fscanf(fp, "%d", (int *) &pid) < 1 )
+           error("Unable to read fcron daemon's pid (fscanf(fp,...))");
        fclose(fp);
     }