#include "portab.h"
-static char UNUSED id[] = "$Id: resolve.c,v 1.11 2005/03/19 18:43:49 fw Exp $";
+static char UNUSED id[] = "$Id: resolve.c,v 1.13 2005/07/07 18:39:08 fw Exp $";
#include "imp.h"
#include <assert.h>
#include "exp.h"
#include "resolve.h"
+#include "io.h"
#ifdef IDENTAUTH
LOCAL RES_STAT *New_Res_Stat PARAMS(( void ));
-GLOBAL void
-Resolve_Init( void )
-{
- /* Initialize module */
-
- FD_ZERO( &Resolver_FDs );
-} /* Resolve_Init */
+static void
+cb_resolver(int fd, short unused) {
+ (void) unused; /* shut up compiler warning */
+ Read_Resolver_Result(fd);
+}
#ifdef IDENTAUTH
pid = fork( );
if( pid > 0 )
{
+ close( s->pipe[1] );
/* Main process */
Log( LOG_DEBUG, "Resolver for %s created (PID %d).", inet_ntoa( Addr->sin_addr ), pid );
- FD_SET( s->pipe[0], &Resolver_FDs );
- if( s->pipe[0] > Conn_MaxFD ) Conn_MaxFD = s->pipe[0];
+ if (!io_setnonblock( s->pipe[0] )) {
+ Log( LOG_DEBUG, "Could not set Non-Blocking mode for pipefd %d", s->pipe[0] );
+ goto out;
+ }
+ if (!io_event_create( s->pipe[0], IO_WANTREAD, cb_resolver )) {
+ Log( LOG_DEBUG, "Could not add pipefd %dto event watchlist: %s",
+ s->pipe[0], strerror(errno) );
+ goto out;
+ }
s->pid = pid;
return s;
}
else if( pid == 0 )
{
+ close( s->pipe[0] );
/* Sub process */
Log_Init_Resolver( );
#ifdef IDENTAUTH
Log_Exit_Resolver( );
exit( 0 );
}
- else
- {
- /* Error! */
- free( s );
- Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
- return NULL;
- }
+
+ Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
+
+out: /* Error! */
+ close( s->pipe[0] );
+ free( s );
+return NULL;
} /* Resolve_Addr */
pid = fork( );
if( pid > 0 )
{
+ close( s->pipe[1] );
/* Main process */
Log( LOG_DEBUG, "Resolver for \"%s\" created (PID %d).", Host, pid );
- FD_SET( s->pipe[0], &Resolver_FDs );
- if( s->pipe[0] > Conn_MaxFD ) Conn_MaxFD = s->pipe[0];
+ if (!io_setnonblock( s->pipe[0] )) {
+ Log( LOG_DEBUG, "Could not set Non-Blocking mode for pipefd %d", s->pipe[0] );
+ goto out;
+ }
+ if (!io_event_create( s->pipe[0], IO_WANTREAD, cb_resolver )) {
+ Log( LOG_DEBUG, "Could not add pipefd %dto event watchlist: %s",
+ s->pipe[0], strerror(errno) );
+ goto out;
+ }
s->pid = pid;
return s;
}
else if( pid == 0 )
{
+ close( s->pipe[0] );
/* Sub process */
Log_Init_Resolver( );
Do_ResolveName( Host, s->pipe[1] );
Log_Exit_Resolver( );
exit( 0 );
}
- else
- {
- /* Error! */
- free( s );
- Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
- return NULL;
- }
+
+ Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
+
+out: /* Error! */
+ close( s->pipe[0] );
+ free( s );
+ return NULL;
} /* Resolve_Name */
char hostname[HOST_LEN];
struct hostent *h;
- int len;
+ size_t len;
#ifdef IDENTAUTH
char *res;
#endif
Log_Resolver( LOG_DEBUG, "Ok, IDENT lookup on socket %d done: \"%s\"", Sock, res ? res : "" );
/* Write IDENT result into pipe to parent */
- len = strlen( res ? res : "" );
- if( res != NULL ) res[len] = '\n';
- len++;
+ if (res) {
+ len = strlen(res);
+ res[len] = '\n';
+ len++;
+ } else len = 1;
+
if( (size_t)write( w_fd, res ? res : "\n", len ) != (size_t)len )
{
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent (IDENT): %s!", strerror( errno ));