This should be the first really usable version. Everything seems to work and
the stress test went pretty well.
This commit is contained in:
		
							parent
							
								
									a53cbcbde3
								
							
						
					
					
						commit
						6f5719745a
					
				
					 3 changed files with 20 additions and 47 deletions
				
			
		
							
								
								
									
										5
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										5
									
								
								Makefile
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -21,8 +21,9 @@ clean:
 | 
			
		|||
	rm core *.o $(TARGETS)
 | 
			
		||||
 | 
			
		||||
install: $(TARGETS)
 | 
			
		||||
	install --strip $(TARGETS) gild.conf $(HOMEDIR)
 | 
			
		||||
	install handlers/* $(HOMEDIR)/handlers
 | 
			
		||||
	install --strip $(TARGETS) $(HOMEDIR)
 | 
			
		||||
	install gild.conf $(HOMEDIR)
 | 
			
		||||
	cd handlers; make install
 | 
			
		||||
 | 
			
		||||
version: $(TARGETS)
 | 
			
		||||
	cvs commit gild.c wrapper.c config.c log.c Makefile gild.h \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								gild.c
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								gild.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -119,6 +119,8 @@ int main( int argc, char * argv[])
 | 
			
		|||
     setsid();			/* release the controlling tty */
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
     signal( SIGCHLD, SIG_IGN); /* allow chidren to die naturally */
 | 
			
		||||
 | 
			
		||||
     if ( listen( keyhole, MAX_PENDING_REQUESTS) == -1)
 | 
			
		||||
     {
 | 
			
		||||
	  sprintf( errorBuff, "failed in listen()?");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										58
									
								
								wrapper.c
									
										
									
									
									
								
							
							
						
						
									
										58
									
								
								wrapper.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -14,6 +14,8 @@
 | 
			
		|||
*                                                                          *
 | 
			
		||||
\**************************************************************************/
 | 
			
		||||
 | 
			
		||||
/* $Header */
 | 
			
		||||
 | 
			
		||||
#include "gild.h"
 | 
			
		||||
 | 
			
		||||
extern char errorBuff[ 1024];
 | 
			
		||||
| 
						 | 
				
			
			@ -35,8 +37,6 @@ void wrapper( int conversation, char * client_id)
 | 
			
		|||
     char firstln[ 1024];
 | 
			
		||||
     char * exec_args[1];	/* 'arguments' to pass to execve */
 | 
			
		||||
     handler * command = null;
 | 
			
		||||
     pid_t child_pid;		/* the process number of the spawned child */
 | 
			
		||||
     int child_status;		/* the status returned by wait() */
 | 
			
		||||
 | 
			
		||||
     recv( conversation, firstln, 80, MSG_PEEK);
 | 
			
		||||
				/* get the first thing the client
 | 
			
		||||
| 
						 | 
				
			
			@ -71,54 +71,24 @@ void wrapper( int conversation, char * client_id)
 | 
			
		|||
	  setenv( "REMOTE_HOST", client_id, 1);
 | 
			
		||||
				/* set up the handler environment */
 | 
			
		||||
 | 
			
		||||
	  if ( command->timeout != 0)
 | 
			
		||||
				/* prevent runaway processes; if a
 | 
			
		||||
				   timeout has been specified for this
 | 
			
		||||
				   handler, enforce it */
 | 
			
		||||
	  {
 | 
			
		||||
	       signal( SIGALRM,(void (*)())die);
 | 
			
		||||
	       alarm( command->timeout);
 | 
			
		||||
	  } 
 | 
			
		||||
 | 
			
		||||
	  child_pid = fork();
 | 
			
		||||
 | 
			
		||||
	  switch ( child_pid)
 | 
			
		||||
	  {
 | 
			
		||||
	  case -1:		/* blew it; whinge and die */
 | 
			
		||||
	       sprintf( errorBuff, "failed to fork in wrapper()");
 | 
			
		||||
	       error( LOG_ERR);
 | 
			
		||||
	       break;
 | 
			
		||||
	  case 0:		/* we're the child process */
 | 
			
		||||
	       sprintf( errorBuff, 
 | 
			
		||||
		       "using handler '%s' [%d] to handle %s request from %s", 
 | 
			
		||||
		       command->command, ( int)getpid(), command->protocol, 
 | 
			
		||||
		       client_id);
 | 
			
		||||
	       error( LOG_NOTICE);
 | 
			
		||||
	  sprintf( errorBuff, 
 | 
			
		||||
		  "using handler '%s' [%d] to handle %s request from %s", 
 | 
			
		||||
		  command->command, ( int)getpid(), command->protocol, 
 | 
			
		||||
		  client_id);
 | 
			
		||||
	  error( LOG_NOTICE);
 | 
			
		||||
				/* log the request, and... */
 | 
			
		||||
 | 
			
		||||
	       exec_args[ 0] = command->command;
 | 
			
		||||
	       exec_args[ 1] = null;
 | 
			
		||||
	  exec_args[ 0] = command->command;
 | 
			
		||||
	  exec_args[ 1] = null;
 | 
			
		||||
				/* set up the dummy arguments */
 | 
			
		||||
 | 
			
		||||
	       if ( execve( command->command, 
 | 
			
		||||
			   exec_args, environ) == -1)
 | 
			
		||||
	  if ( execve( command->command, exec_args, environ) == -1)
 | 
			
		||||
				/* ...execute the command (shouldn't return) */
 | 
			
		||||
	       {		/* if it did we've got an error */
 | 
			
		||||
		    sprintf( errorBuff, 
 | 
			
		||||
			"error [errno %d] whislt execing handler '%s' [%d]\n",
 | 
			
		||||
			    errno, command->command, child_pid),
 | 
			
		||||
		    error( LOG_ERR);
 | 
			
		||||
	       }		    
 | 
			
		||||
	       break;
 | 
			
		||||
 | 
			
		||||
	  default:		/* we're the parent */
 | 
			
		||||
	       wait( &child_status);
 | 
			
		||||
				/* hang around for the child to die */
 | 
			
		||||
	  {			/* if it did we've got an error */
 | 
			
		||||
	       sprintf( errorBuff, 
 | 
			
		||||
		       "handler '%s' [%d] completed; wrapper exiting normally",
 | 
			
		||||
		       command->command, child_pid),
 | 
			
		||||
	       error( LOG_NOTICE);
 | 
			
		||||
	       break;
 | 
			
		||||
		       "error [errno %d] whislt execing handler '%s' [%d]\n",
 | 
			
		||||
		       errno, command->command, ( int)getpid()),
 | 
			
		||||
	       error( LOG_ERR);
 | 
			
		||||
	  }		    
 | 
			
		||||
     }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue