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
5
Makefile
5
Makefile
|
@ -21,8 +21,9 @@ clean:
|
||||||
rm core *.o $(TARGETS)
|
rm core *.o $(TARGETS)
|
||||||
|
|
||||||
install: $(TARGETS)
|
install: $(TARGETS)
|
||||||
install --strip $(TARGETS) gild.conf $(HOMEDIR)
|
install --strip $(TARGETS) $(HOMEDIR)
|
||||||
install handlers/* $(HOMEDIR)/handlers
|
install gild.conf $(HOMEDIR)
|
||||||
|
cd handlers; make install
|
||||||
|
|
||||||
version: $(TARGETS)
|
version: $(TARGETS)
|
||||||
cvs commit gild.c wrapper.c config.c log.c Makefile gild.h \
|
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 */
|
setsid(); /* release the controlling tty */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
signal( SIGCHLD, SIG_IGN); /* allow chidren to die naturally */
|
||||||
|
|
||||||
if ( listen( keyhole, MAX_PENDING_REQUESTS) == -1)
|
if ( listen( keyhole, MAX_PENDING_REQUESTS) == -1)
|
||||||
{
|
{
|
||||||
sprintf( errorBuff, "failed in listen()?");
|
sprintf( errorBuff, "failed in listen()?");
|
||||||
|
|
60
wrapper.c
60
wrapper.c
|
@ -14,6 +14,8 @@
|
||||||
* *
|
* *
|
||||||
\**************************************************************************/
|
\**************************************************************************/
|
||||||
|
|
||||||
|
/* $Header */
|
||||||
|
|
||||||
#include "gild.h"
|
#include "gild.h"
|
||||||
|
|
||||||
extern char errorBuff[ 1024];
|
extern char errorBuff[ 1024];
|
||||||
|
@ -35,8 +37,6 @@ void wrapper( int conversation, char * client_id)
|
||||||
char firstln[ 1024];
|
char firstln[ 1024];
|
||||||
char * exec_args[1]; /* 'arguments' to pass to execve */
|
char * exec_args[1]; /* 'arguments' to pass to execve */
|
||||||
handler * command = null;
|
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);
|
recv( conversation, firstln, 80, MSG_PEEK);
|
||||||
/* get the first thing the client
|
/* get the first thing the client
|
||||||
|
@ -71,55 +71,25 @@ void wrapper( int conversation, char * client_id)
|
||||||
setenv( "REMOTE_HOST", client_id, 1);
|
setenv( "REMOTE_HOST", client_id, 1);
|
||||||
/* set up the handler environment */
|
/* set up the handler environment */
|
||||||
|
|
||||||
if ( command->timeout != 0)
|
sprintf( errorBuff,
|
||||||
/* prevent runaway processes; if a
|
"using handler '%s' [%d] to handle %s request from %s",
|
||||||
timeout has been specified for this
|
command->command, ( int)getpid(), command->protocol,
|
||||||
handler, enforce it */
|
client_id);
|
||||||
{
|
error( LOG_NOTICE);
|
||||||
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);
|
|
||||||
/* log the request, and... */
|
/* log the request, and... */
|
||||||
|
|
||||||
exec_args[ 0] = command->command;
|
exec_args[ 0] = command->command;
|
||||||
exec_args[ 1] = null;
|
exec_args[ 1] = null;
|
||||||
/* set up the dummy arguments */
|
/* set up the dummy arguments */
|
||||||
|
|
||||||
if ( execve( command->command,
|
if ( execve( command->command, exec_args, environ) == -1)
|
||||||
exec_args, environ) == -1)
|
|
||||||
/* ...execute the command (shouldn't return) */
|
/* ...execute the command (shouldn't return) */
|
||||||
{ /* if it did we've got an error */
|
{ /* 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 */
|
|
||||||
sprintf( errorBuff,
|
sprintf( errorBuff,
|
||||||
"handler '%s' [%d] completed; wrapper exiting normally",
|
"error [errno %d] whislt execing handler '%s' [%d]\n",
|
||||||
command->command, child_pid),
|
errno, command->command, ( int)getpid()),
|
||||||
error( LOG_NOTICE);
|
error( LOG_ERR);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit( 0);
|
exit( 0);
|
||||||
|
|
Loading…
Reference in a new issue