From: thib Date: Mon, 1 Jan 2007 18:49:43 +0000 (+0000) Subject: more function return code checking X-Git-Tag: ver3_0_2-rc1~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ab17a283d9a755d6cfbc33618a79581136ad95e;p=fcron more function return code checking --- diff --git a/fcron.c b/fcron.c index 4366539..5325029 100644 --- 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. diff --git a/fcrondyn.c b/fcrondyn.c index 640c54b..d48a22a 100644 --- a/fcrondyn.c +++ b/fcrondyn.c @@ -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; diff --git a/fcronsighup.c b/fcronsighup.c index a63b744..34eb01f 100644 --- a/fcronsighup.c +++ b/fcronsighup.c @@ -21,13 +21,13 @@ * `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); }