<< | Thread Index | >> ]    [ << | Date Index | >> ]

Subject: Re: CIPE Logging/Running in the foreground
From: Keith Smith <keith,AT,ksmith,DOT,com>
Date: Thu, 31 Jan 2002 02:29:10 +0100
In-reply-to: <000001c1a84b$e2c1a680$73980e44@cx351466a>

Kevin Herzig wrote:

>>>The simplest way to do this is in inittab:
>>>cp00:345:respawn:/usr/local/sbin/ciped-cb -f -o /etc/cipe/peers/bam-bam
>>>
> 
> This looks awesome.  I tried to run ciped from inittab before but gave up.

You can run any job only once with:

ci00:345:once:/usr/local/sbin/ciped-cb -o /etc/cipe/peers/mybuddy

This will always fly, if your maxerr is set to -1.  Of course then you don't 
neccesarily know it's crying and dying, ie init won't shut it down.

Also hacking on several different distributions, it's often simpler just to 
throw your own inittab entry in than try and find the right spot to load the 
module, and fire up the tunnel.  We had a kernel panic loading the ciped 
module 
on one machine until we moved it after the networks were all up and running.  
I 
haven't had time to further investigate. But we were *very* confused since it 
ran fine when we did everyting by hand AFTER the machine was up :).

> I want it!  Can you post a patch?

Oh sure, now you want a patch :)!

Well, This obviously won't be in the next release :), but here it is for what 
it's worth sans even the first comment.  YMMV, use '-f' on the command line 
to 
hold it in the foreground as in the above example:

---------------------------- cut here ------------------------------
diff -r --context cipe-1.5.2/cipe/ciped.c cipe-1.5.2.1/cipe/ciped.c
*** cipe-1.5.2/cipe/ciped.c     Sun Feb 11 14:42:39 2001
--- cipe-1.5.2.1/cipe/ciped.c   Tue Jan 22 12:19:02 2002
***************
*** 886,892 ****

   int main(int argc, char *argv[])
   {
!     int i=1, ur, fd, sd=-1;
       time_t t;
       pid_t pa=0;
       char *st;
--- 886,892 ----

   int main(int argc, char *argv[])
   {
!     int i=1, ur, fd, sd=-1, foreground=0;
       time_t t;
       pid_t pa=0;
       char *st;
***************
*** 913,920 ****
       /* Snarf options from: standard options file, user-supplied file and
          finally, command line */
       setopt_file(CTLDIR "/options", 0);
!     while ((i=getopt(argc, argv, "is:S:o:"))!=EOF) {
           switch(i) {
           case 'i': inetd=1; break;
         case 's': usesock=atoi(optarg); break;
         case 'S': sd=atoi(optarg); break;
--- 913,921 ----
       /* Snarf options from: standard options file, user-supplied file and
          finally, command line */
       setopt_file(CTLDIR "/options", 0);
!     while ((i=getopt(argc, argv, "fis:S:o:"))!=EOF) {
           switch(i) {
+         case 'f': foreground=1; break;
           case 'i': inetd=1; break;
         case 's': usesock=atoi(optarg); break;
         case 'S': sd=atoi(optarg); break;
***************
*** 940,963 ****
         gotsig=0;
         setsig(SIGUSR1, sighandexit);
         setsig(SIGCHLD, sighand);
!       if ((i=fork())<0) {
!           perror("fork"); exit(1);
!       }
!       if (i) {
!             /* wait until the child is ready - will send SIGUSR1 */
!             while (1) {
!                 pause();
!                 if (gotsig==SIGCHLD) {
!                     int s;
!                     wait(&s);
!                     exit(WIFEXITED(s)?WEXITSTATUS(s):255);
                   }
               }
-           exit(0);
-         }
           /* re-lock after fork */
!         xmlock(LM, sizeof(struct lockmem));
!         pa=getppid();
         openlog(pn, LOG_CONS|LOG_NDELAY|LOG_PID, LOGFAC);
         /* don't let the syslog socket get in the way of the standard fds */
         close(0); close(1); close(2);
--- 941,966 ----
         gotsig=0;
         setsig(SIGUSR1, sighandexit);
         setsig(SIGCHLD, sighand);
!         if(foreground == 0) {
!           if ((i=fork())<0) {
!                 perror("fork"); exit(1);
!             }
!           if (i) {
!                 /* wait until the child is ready - will send SIGUSR1 */
!                 while (1) {
!                     pause();
!                     if (gotsig==SIGCHLD) {
!                         int s;
!                         wait(&s);
!                         exit(WIFEXITED(s)?WEXITSTATUS(s):255);
!                     }
                   }
+               exit(0);
               }
           /* re-lock after fork */
!             xmlock(LM, sizeof(struct lockmem));
!             pa=getppid();
!         }
         openlog(pn, LOG_CONS|LOG_NDELAY|LOG_PID, LOGFAC);
         /* don't let the syslog socket get in the way of the standard fds */
         close(0); close(1); close(2);

---------------------------- cut here ------------------------------

-- 
Keith Smith                 keith,AT,ksmith,DOT,com
655 W Fremont Dr
Tempe AZ 85282              it's hot





<< | Thread Index | >> ]    [ << | Date Index | >> ]