]> granicus.if.org Git - fcron/commitdiff
*** empty log message ***
authorthib <thib>
Mon, 9 Jul 2001 11:49:11 +0000 (11:49 +0000)
committerthib <thib>
Mon, 9 Jul 2001 11:49:11 +0000 (11:49 +0000)
fcron.c
fcronsighup.c
log.c

diff --git a/fcron.c b/fcron.c
index 563ced60deddcbd141b5787ce2c20ef81dc8eb45..082ee963f1b88fd4d3ebf37b83b8231634d7e14f 100644 (file)
--- a/fcron.c
+++ b/fcron.c
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcron.c,v 1.52 2001-07-07 17:52:02 thib Exp $ */
+ /* $Id: fcron.c,v 1.53 2001-07-09 11:49:24 thib Exp $ */
 
 #include "fcron.h"
 
-char rcs_info[] = "$Id: fcron.c,v 1.52 2001-07-07 17:52:02 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.53 2001-07-09 11:49:24 thib Exp $";
 
 void main_loop(void);
 void check_signal(void);
@@ -64,9 +64,6 @@ pid_t daemon_pid;
 mode_t saved_umask;           /* default root umask */
 char *prog_name = NULL;         
 
-/* locking */
-static FILE *daemon_lockfp = NULL;
-
 /* have we got a signal ? */
 char sig_conf = 0;            /* is 1 when we got a SIGHUP, 2 for a SIGUSR1 */ 
 char sig_chld = 0;            /* is 1 when we got a SIGCHLD */  
@@ -176,41 +173,29 @@ get_lock()
      * if not, write our pid to /var/run/fcron.pid in order to lock,
      * and to permit fcrontab to read our pid and signal us */
 {
-    int otherpid = 0, foreopt;
-
-    foreopt = foreground;
-    foreground = 1;
-
-    if ( ! daemon_lockfp ) {
-       int fd;
+    int otherpid = 0;
+    FILE *daemon_lockfp = NULL;
+    int fd;
 
-       if (((fd = open(pidfile, O_RDWR|O_CREAT, 0644)) == -1 )
-           || ((daemon_lockfp = fdopen(fd, "r+"))) == NULL)
-           die_e("can't open or create %s", pidfile);
+    if (((fd = open(pidfile, O_RDWR|O_CREAT, 0644)) == -1 )
+       || ((daemon_lockfp = fdopen(fd, "r+"))) == NULL)
+       die_e("can't open or create %s", pidfile);
        
 #ifdef HAVE_FLOCK
-       /* flock() seems to keep the lock over a fork() (contrary to lockf() ):
-        * we only need to lock the file once */
-       if ( flock(fd, LOCK_EX|LOCK_NB) != 0 ) {
-           fscanf(daemon_lockfp, "%d", &otherpid);
-           die("can't lock %s, running daemon's pid may be %d",
-               pidfile, otherpid);
-       }
-#endif /* HAVE_FLOCK */
-
-       fcntl(fd, F_SETFD, 1);
-
+    if ( flock(fd, LOCK_EX|LOCK_NB) != 0 ) {
+       fscanf(daemon_lockfp, "%d", &otherpid);
+       die_e("can't lock %s, running daemon's pid may be %d",
+           pidfile, otherpid);
     }
-    
-#ifndef HAVE_FLOCK
+#else /* HAVE_FLOCK */
     if ( lockf(fileno(daemon_lockfp), F_TLOCK, 0) != 0 ) {
        fscanf(daemon_lockfp, "%d", &otherpid);
-       die("can't lock %s, running daemon's pid may be %d",
-            pidfile, otherpid);
+       die_e("can't lock %s, running daemon's pid may be %d",
+           pidfile, otherpid);
     }
 #endif /* ! HAVE_FLOCK */
 
-    foreground = foreopt;
+    fcntl(fd, F_SETFD, 1);
 
     rewind(daemon_lockfp);
     fprintf(daemon_lockfp, "%d\n", (int) daemon_pid);
@@ -221,7 +206,6 @@ get_lock()
      * keep it open and locked, but we don't need the handles elsewhere.
      */
 
-
 }
 
 
@@ -459,9 +443,6 @@ main(int argc, char **argv)
        int fd, i;
        pid_t pid;
 
-       /* check if another fcron daemon is running */
-       get_lock();
-
        switch ( pid = fork() ) {
        case -1:
            die_e("fork");
@@ -473,7 +454,6 @@ main(int argc, char **argv)
            /* parent */
 /*         printf("%s[%d] " VERSION_QUOTED " : started.\n", */
 /*                prog_name, pid); */
-
            exit(0);
        }
 
@@ -491,8 +471,8 @@ main(int argc, char **argv)
        close(2); dup2(i, 2);
 
        /* close most other open fds */
-       i = fileno(daemon_lockfp);
-       for(fd = 3; fd < 250; fd++) if (fd != i) (void) close(fd);
+       xcloselog();
+       for(fd = 3; fd < 250; fd++) (void) close(fd);
 
        /* finally, create a new session */
        if ( setsid() == -1 )
@@ -500,8 +480,7 @@ main(int argc, char **argv)
 
     }
 
-    /* if we are in foreground, check if another fcron daemon
-     * is running, otherwise update value of pid in lock file */
+    /* check if another fcron daemon is running, create pid file and lock it */
     get_lock();
     
     /* this program belongs to root : we set default permission mode
index e24dccf304a8418ceadc8ef496aafbf10e1e4507..2416b98e76383c94397e8e4f5fe6eb3e82759b6e 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcronsighup.c,v 1.1 2001-07-07 17:29:51 thib Exp $ */
+ /* $Id: fcronsighup.c,v 1.2 2001-07-09 11:49:11 thib Exp $ */
 
 #include "global.h"
 
@@ -30,7 +30,7 @@
 #include "subs.h"
 #include "allow.h"
 
-char rcs_info[] = "$Id: fcronsighup.c,v 1.1 2001-07-07 17:29:51 thib Exp $";
+char rcs_info[] = "$Id: fcronsighup.c,v 1.2 2001-07-09 11:49:11 thib Exp $";
 
 void usage(void);
 void sig_daemon(void);
@@ -173,6 +173,7 @@ sig_daemon(void)
        remove(sigfile);
     }
     else
+       /* we are root */
        fprintf(stderr, "Modifications will be taken into account"
                " right now.\n");
 
diff --git a/log.c b/log.c
index 51bfba714ce6fa0e86c6a168f63e12283d17b381..3b221c43bdd8a3394e54ac305d27ba94852152c9 100644 (file)
--- a/log.c
+++ b/log.c
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: log.c,v 1.7 2001-05-15 00:42:48 thib Exp $ */
+ /* $Id: log.c,v 1.8 2001-07-09 11:49:17 thib Exp $ */
 
 /* This code is inspired by Anacron's sources of
-   Itai Tzur <itzur@actcom.co.il> ( thanks to him ) */
+   Itai Tzur <itzur@actcom.co.il> */
 
 
 #include "fcron.h"