Article delegate-en/486 of [1-5169] on the server localhost:119
  upper oldest olders older1 this newer1 newers latest
search
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
[Reference:<_A378@delegate-en.ML_>]
Newsgroups: mail-lists.delegate-en

[DeleGate-En] Re: Time setting for Delegate
03 Jun 1999 03:56:36 GMT ysato@etl.go.jp (Yutaka Sato)


Hi Rupert,

I'm not sure if you are using DeleGate yet, but I made some extension
to DeleGate which has been originated by your proposal.

On 03/26/99(00:07) you "Rupert Chandler" <ppiaqbdyi-5vjbuj5zrptr.ml@ml.delegate.org> wrote
in <_A378@delegate-en.ML_>
 |> |We use it to allow employee's at our company to access the web from
 |> |their desks, the one problem is that we would like to limit theor access
 |> |to office hours. Is it possible for the PERMIT command to have a system
 |> |clock link so its possible to set hours of access?

Making arbitrary parameters be more generally conditional has been
an interesting theme and what to do in future since the early times
of DeleGate, but I've thought it should be done in future in the way
of overall restructuring of the configuration mechanism of DeleGate
which is very primitive currently.

In the current DeleGate, you have to restart DeleGate with a different
configuration script at each time when some policy changes.  One of the
most primitive ways to do so is switching configuration file and
restarting DeleGate from "cron" server.  But it is not so smart.

In the latest version of DeleGate, version 5.9.2 released yesterday,
I introduced a tentative implementation of "-exec" action for CRON
parameter, which I thought can be used to realize such configuration
switching.  But today I understand it was so incomplete to be functional,
so I modified it as the enclosed patch.  With the patch, you can
restart DeleGate with

------------ /path/of/delegate.rc --------------------------------
#!/bin/sh

case `date "+%H"` in
 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 )
    permit="*:*:listOfRestrictedHosts";;
 *) permit="*:*:*";;
esac

export DELEGATE_PID; DELEGATE_PID=$$
exec /path/of/delegated \
        CRON="0 9,17 * * * -exec /path/of/delegate.rc" \
	PERMIT=$permit \
	... other common parameters ...
------------------------------------------------------------------

The "-exec" action in CRON works like SIGHUP which causes restart
of DeleGate.  The environment variable DELEGATE_PID and exec command
in the shell script will suppress forking new DeleGate processes on
each restart (these are not mandatory).

Cheers,
Yutaka
--
Yutaka Sato <ysato@etl.go.jp> http://www.etl.go.jp/~ysato/   @ @ 
Computer Science Division, Electrotechnical Laboratory      ( - )
1-1-4 Umezono, Tsukuba, Ibaraki, 305-8568 Japan            _<   >_


diff -c ../../delegate5.9.2/src/croncom.c ./croncom.c
*** ../../delegate5.9.2/src/croncom.c	Fri Mar 26 19:44:26 1999
--- ./croncom.c	Thu Jun  3 09:27:58 1999
***************
*** 175,182 ****
  		pid = spawnv_self(ac,av);
  	}else
  	if( strcmp(act,"exec") == 0 ){
! 		pid = spawn_self("-Fsystem",arg,NULL);
! 		Finish(0);
  	}else
  	if( strcmp(act,"system") == 0 ){
  		pid = spawn_self("-Fsystem",arg,NULL);
--- 175,182 ----
  		pid = spawnv_self(ac,av);
  	}else
  	if( strcmp(act,"exec") == 0 ){
! 		DELEGATE_execs(arg);
! 		Finish(-1);
  	}else
  	if( strcmp(act,"system") == 0 ){
  		pid = spawn_self("-Fsystem",arg,NULL);
diff -c ../../delegate5.9.2/src/delegated.c ./delegated.c
*** ../../delegate5.9.2/src/delegated.c	Wed Jun  2 12:13:52 1999
--- ./delegated.c	Thu Jun  3 12:05:58 1999
***************
*** 345,359 ****
--- 345,366 ----
  	return nproc;
  }
  
+ /*
  static void sigHUP(sig)
+ */
+ static void sigHUPX(sig,execpath,argv)
+ 	char *execpath;
+ 	char *argv[];
  {	char *nargv[256];
  	char *arg,path[1024],port[128],nchild[32],wd[1024];
  	int ai,ac,portset;
  	int nproc;
  	char orig_av0[1024];
  
+ if( execpath == NULL ){
  	strcpy(path,EXEC_PATH);
  	wordscan(main_argv[0],orig_av0);/*av[0] may be expanded for ps_title*/
+ }
  
  	if( getpid() != ServerPID ){
  		fprintf(stderr,"\nDeleGate[%d] got SIGHUP(%d) for server=%d\n",
***************
*** 415,420 ****
--- 422,428 ----
  	strcpy(wd,"?");
  	getcwd(wd,sizeof(wd));
  	sv0log("PWD: %s\n",wd);
+ if( execpath == NULL )
  	sv0log("EXEC: %s\n",path);
  	LOG_closeall();
  
***************
*** 427,432 ****
--- 435,463 ----
  	sprintf(nchild,"%s%d/%d/%d/%d",TMP_SYM,++NUM_HUPS,NUM_CHILDREN,
  		LOG_sockio[0],LOG_sockio[1]);
  
+ if( execpath != NULL ){
+ 	char *ppid,dgpid[32],dgargs[1024];
+ 	/* maybe restarting DeleGate via shell script or so.  */
+ 	ppid = getenv("DELEGATE_PID");
+ 	sv1log("#### parent DELEGATE_PID=%s\n",ppid?ppid:"NULL");
+ 	if( ppid == NULL || atoi(ppid) != getpid() ){
+ 		/* the shell (parent) process may be waiting exit code
+ 		 * from this process rathar than "exec" this process.
+ 		 */
+ 		if( INHERENT_fork() ){
+ 			if( Fork("execs") != 0 )
+ 				exit(0);
+ 		}
+ 	}
+ 	sprintf(dgpid,"DELEGATE_PID=%d",getpid());
+ 	putenv(dgpid);
+ 	sprintf(dgargs,"DELEGATE_ARGS=%s %s",port,nchild);
+ 	putenv(dgargs);
+ 	sv1log("#### %s %s\n",dgpid,dgargs);
+ 	Execvp("execs",execpath,argv);
+ 	Finish(-1);
+ }
+ 
  	nargv[0] = orig_av0;
  	ac = 1;
  	portset = 0;
***************
*** 452,457 ****
--- 483,500 ----
  
  	Execvp("sigHUP",path,nargv);
  }
+ static void sigHUP(sig)
+ {
+ 	sigHUPX(sig,NULL,NULL);
+ }
+ DELEGATE_execs(command)
+ 	char *command;
+ {	char argb[1024],*av[128];
+ 	int ac;
+ 
+ 	ac = decomp_args(av,128,command,argb);
+ 	sigHUPX(0,av[0],av);
+ }
  
  extern char PSTITLE_PADD;
  extern int  PSTITLE_SIZE;
***************
*** 2283,2288 ****
--- 2326,2342 ----
  		/* scan_args() should be after exec() in ProcTitleInit()
  		 * to avoid repetitive script loading */
  		ac = scan_args(ac,av);
+ 
+ 		{
+ 		  char *dgargs,*dgav[128],dgargb[1024];
+ 		  int dgac,dgai;
+ 		  if( dgargs = getenv("DELEGATE_ARGS") ){
+ 			sv1log("DELEGATE_ARGS=%s\n",dgargs);
+ 			dgac = decomp_args(dgav,128,dgargs,dgargb);
+ 			scan_args(dgac,dgav);
+ 		  }
+ 		}
+ 
  		reopenLogFile(); /* reopen LOGFILE with a proper PORT number */
  
  		_setTMPDIR(getEnv(P_TMPDIR));

  admin search upper oldest olders older1 this newer1 newers latest
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
@_@V