Minimal changes (needed for merging resolver changes)

This commit is contained in:
Florian Westphal 2005-09-11 11:42:48 +00:00
parent 0aae3ec5d7
commit 4db29b0076
3 changed files with 21 additions and 38 deletions

View File

@ -17,7 +17,7 @@
#include "portab.h" #include "portab.h"
#include "io.h" #include "io.h"
static char UNUSED id[] = "$Id: conn.c,v 1.179 2005/09/05 09:10:08 fw Exp $"; static char UNUSED id[] = "$Id: conn.c,v 1.180 2005/09/11 11:42:48 fw Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@ -1283,7 +1283,8 @@ Check_Connections( void )
CONN_ID i; CONN_ID i;
for( i = 0; i < Pool_Size; i++ ) { for( i = 0; i < Pool_Size; i++ ) {
if( My_Connections[i].sock == NONE ) continue; if (My_Connections[i].sock < 0)
continue;
c = Client_GetFromConn( i ); c = Client_GetFromConn( i );
if( c && (( Client_Type( c ) == CLIENT_USER ) || ( Client_Type( c ) == CLIENT_SERVER ) || ( Client_Type( c ) == CLIENT_SERVICE ))) if( c && (( Client_Type( c ) == CLIENT_USER ) || ( Client_Type( c ) == CLIENT_SERVER ) || ( Client_Type( c ) == CLIENT_SERVICE )))
@ -1365,16 +1366,17 @@ Check_Servers( void )
} }
/* Check last connect attempt? */ /* Check last connect attempt? */
if( Conf_Server[i].lasttry > time( NULL ) - Conf_ConnectRetry ) continue; if( Conf_Server[i].lasttry > time( NULL ) - Conf_ConnectRetry )
continue;
/* Okay, try to connect now */ /* Okay, try to connect now */
Conf_Server[i].lasttry = time( NULL ); Conf_Server[i].lasttry = time( NULL );
/* Search free connection structure */ /* Search free connection structure */
for( idx = 0; idx < Pool_Size; idx++ ) if( My_Connections[idx].sock == NONE ) break; for( idx = 0; idx < Pool_Size; idx++ ) if( My_Connections[idx].sock == NONE ) break;
if( idx >= Pool_Size ) if (idx >= Pool_Size) {
{ Log( LOG_ALERT, "Can't establist server connection: connection limit reached (%d)!",
Log( LOG_ALERT, "Can't establist server connection: connection limit reached (%d)!", Pool_Size ); Pool_Size );
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
@ -1566,8 +1568,7 @@ void Read_Resolver_Result( int r_fd )
&& ( My_Connections[i].res_stat->pipe[0] == r_fd )) && ( My_Connections[i].res_stat->pipe[0] == r_fd ))
break; break;
} }
if( i >= Pool_Size ) if( i >= Pool_Size ) {
{
/* Ops, none found? Probably the connection has already /* Ops, none found? Probably the connection has already
* been closed!? We'll ignore that ... */ * been closed!? We'll ignore that ... */
io_close( r_fd ); io_close( r_fd );
@ -1706,8 +1707,7 @@ Count_Connections( struct sockaddr_in addr_in )
int i, cnt; int i, cnt;
cnt = 0; cnt = 0;
for( i = 0; i < Pool_Size; i++ ) for( i = 0; i < Pool_Size; i++ ) {
{
if(( My_Connections[i].sock > NONE ) && ( My_Connections[i].addr.sin_addr.s_addr == addr_in.sin_addr.s_addr )) cnt++; if(( My_Connections[i].sock > NONE ) && ( My_Connections[i].addr.sin_addr.s_addr == addr_in.sin_addr.s_addr )) cnt++;
} }
return cnt; return cnt;

View File

@ -14,7 +14,7 @@
#include "portab.h" #include "portab.h"
static char UNUSED id[] = "$Id: resolve.c,v 1.19 2005/09/03 11:17:16 fw Exp $"; static char UNUSED id[] = "$Id: resolve.c,v 1.20 2005/09/11 11:42:48 fw Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@ -83,8 +83,7 @@ Resolve_Addr( struct sockaddr_in *Addr )
/* For sub-process */ /* For sub-process */
pid = fork( ); pid = fork( );
if( pid > 0 ) if (pid > 0) {
{
close( s->pipe[1] ); close( s->pipe[1] );
/* Main process */ /* Main process */
Log( LOG_DEBUG, "Resolver for %s created (PID %d).", inet_ntoa( Addr->sin_addr ), pid ); Log( LOG_DEBUG, "Resolver for %s created (PID %d).", inet_ntoa( Addr->sin_addr ), pid );
@ -99,9 +98,7 @@ Resolve_Addr( struct sockaddr_in *Addr )
} }
s->pid = pid; s->pid = pid;
return s; return s;
} } else if( pid == 0 ) {
else if( pid == 0 )
{
close( s->pipe[0] ); close( s->pipe[0] );
/* Sub process */ /* Sub process */
Log_Init_Resolver( ); Log_Init_Resolver( );
@ -111,7 +108,7 @@ Resolve_Addr( struct sockaddr_in *Addr )
Do_ResolveAddr( Addr, s->pipe[1] ); Do_ResolveAddr( Addr, s->pipe[1] );
#endif #endif
Log_Exit_Resolver( ); Log_Exit_Resolver( );
exit( 0 ); exit(0);
} }
Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno )); Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
@ -138,8 +135,7 @@ Resolve_Name( char *Host )
/* Fork sub-process */ /* Fork sub-process */
pid = fork( ); pid = fork( );
if( pid > 0 ) if (pid > 0) {
{
close( s->pipe[1] ); close( s->pipe[1] );
/* Main process */ /* Main process */
Log( LOG_DEBUG, "Resolver for \"%s\" created (PID %d).", Host, pid ); Log( LOG_DEBUG, "Resolver for \"%s\" created (PID %d).", Host, pid );
@ -154,15 +150,13 @@ Resolve_Name( char *Host )
} }
s->pid = pid; s->pid = pid;
return s; return s;
} } else if( pid == 0 ) {
else if( pid == 0 )
{
close( s->pipe[0] ); close( s->pipe[0] );
/* Sub process */ /* Sub process */
Log_Init_Resolver( ); Log_Init_Resolver( );
Do_ResolveName( Host, s->pipe[1] ); Do_ResolveName( Host, s->pipe[1] );
Log_Exit_Resolver( ); Log_Exit_Resolver( );
exit( 0 ); exit(0);
} }
Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno )); Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
@ -286,13 +280,10 @@ Do_ResolveName( char *Host, int w_fd )
/* Resolve hostname */ /* Resolve hostname */
h = gethostbyname( Host ); h = gethostbyname( Host );
if( h ) if( h ) {
{
addr = (struct in_addr *)h->h_addr; addr = (struct in_addr *)h->h_addr;
strlcpy( ip, inet_ntoa( *addr ), sizeof( ip )); strlcpy( ip, inet_ntoa( *addr ), sizeof( ip ));
} } else {
else
{
#ifdef h_errno #ifdef h_errno
Log_Resolver( LOG_WARNING, "Can't resolve \"%s\": %s!", Host, Get_Error( h_errno )); Log_Resolver( LOG_WARNING, "Can't resolve \"%s\": %s!", Host, Get_Error( h_errno ));
#else #else
@ -305,8 +296,7 @@ Do_ResolveName( char *Host, int w_fd )
/* Write result into pipe to parent */ /* Write result into pipe to parent */
len = strlen( ip ); len = strlen( ip );
ip[len] = '\n'; len++; ip[len] = '\n'; len++;
if( (size_t)write( w_fd, ip, len ) != (size_t)len ) if( (size_t)write( w_fd, ip, len ) != (size_t)len ) {
{
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno )); Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
close( w_fd ); close( w_fd );
} }

View File

@ -8,7 +8,7 @@
* (at your option) any later version. * (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information. * Please read the file COPYING, README and AUTHORS for more information.
* *
* $Id: resolve.h,v 1.9 2005/07/28 16:13:09 fw Exp $ * $Id: resolve.h,v 1.10 2005/09/11 11:42:48 fw Exp $
* *
* Asynchronous resolver (header) * Asynchronous resolver (header)
*/ */
@ -35,11 +35,6 @@ typedef struct _Res_Stat
} RES_STAT; } RES_STAT;
GLOBAL fd_set Resolver_FDs;
GLOBAL void Resolve_Init PARAMS(( void ));
#ifdef IDENTAUTH #ifdef IDENTAUTH
GLOBAL RES_STAT *Resolve_Addr PARAMS(( struct sockaddr_in *Addr, int Sock )); GLOBAL RES_STAT *Resolve_Addr PARAMS(( struct sockaddr_in *Addr, int Sock ));
#else #else
@ -50,6 +45,4 @@ GLOBAL RES_STAT *Resolve_Name PARAMS(( char *Host ));
#endif #endif
/* -eof- */ /* -eof- */