X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fconn.c;h=d8df6274ab7ac376db618a44c6bd77e02d9d8ad4;hp=0d82d530b80733dc23fd18e827b5142bfd06ca54;hb=cf93881dfbd7b6317d2a41f87e9751b74354203b;hpb=d4632a727fbee65cb1585c6f6e9968d830f23a19 diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index 0d82d530..d8df6274 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -68,7 +68,6 @@ #include "log.h" #include "ng_ipaddr.h" #include "parse.h" -#include "proc.h" #include "resolve.h" #include "tool.h" @@ -420,6 +419,23 @@ Conn_Exit( void ) } /* Conn_Exit */ +/** + * Close all sockets (file descriptors) of open connections. + * This is useful in forked child processes, for example, to make sure that + * they don't hold connections open that the main process wants to close. + */ +GLOBAL void +Conn_CloseAllSockets(void) +{ + CONN_ID idx; + + for(idx = 0; idx < Pool_Size; idx++) { + if(My_Connections[idx].sock > NONE) + close(My_Connections[idx].sock); + } +} + + static unsigned int ports_initlisteners(array *a, const char *listen_addr, void (*func)(int,short)) { @@ -1953,7 +1969,7 @@ cb_Connect_to_Server(int fd, UNUSED short events) } /* Read result from pipe */ - len = Resolve_Read(&Conf_Server[i].res_stat, dest_addrs, sizeof(dest_addrs)); + len = Proc_Read(&Conf_Server[i].res_stat, dest_addrs, sizeof(dest_addrs)); if (len == 0) return; @@ -1986,7 +2002,7 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events ) * IDENT user name.*/ CLIENT *c; - int i; + CONN_ID i; size_t len; char *identptr; #ifdef IDENTAUTH @@ -1996,14 +2012,8 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events ) #endif LogDebug("Resolver: Got callback on fd %d, events %d", r_fd, events ); - - /* Search associated connection ... */ - for( i = 0; i < Pool_Size; i++ ) { - if(( My_Connections[i].sock != NONE ) - && (Proc_GetPipeFd(&My_Connections[i].proc_stat) == r_fd)) - break; - } - if( i >= Pool_Size ) { + i = Conn_GetFromProc(r_fd); + if (i == NONE) { /* Ops, none found? Probably the connection has already * been closed!? We'll ignore that ... */ io_close( r_fd ); @@ -2012,7 +2022,7 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events ) } /* Read result from pipe */ - len = Resolve_Read(&My_Connections[i].proc_stat, readbuf, sizeof readbuf -1); + len = Proc_Read(&My_Connections[i].proc_stat, readbuf, sizeof readbuf -1); if (len == 0) return; @@ -2055,8 +2065,6 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events ) #ifdef DEBUG else Log( LOG_DEBUG, "Resolver: discarding result for already registered connection %d.", i ); #endif - /* Reset penalty time */ - Conn_ResetPenalty( i ); } /* cb_Read_Resolver_Result */ @@ -2107,6 +2115,42 @@ Conn_GetClient( CONN_ID Idx ) return c ? c->client : NULL; } +/** + * Get PROC_STAT sub-process structure of a connection. + * @param Idx Connection index number + * @return PROC_STAT structure + */ +GLOBAL PROC_STAT * +Conn_GetProcStat(CONN_ID Idx) +{ + CONNECTION *c; + + assert(Idx >= 0); + c = array_get(&My_ConnArray, sizeof (CONNECTION), (size_t)Idx); + assert(c != NULL); + return &c->proc_stat; +} /* Conn_GetProcStat */ + + +/** + * Get CONN_ID from file descriptor associated to a subprocess structure. + * @param fd File descriptor + * @return CONN_ID or NONE (-1) + */ +GLOBAL CONN_ID +Conn_GetFromProc(int fd) +{ + int i; + + assert(fd > 0); + for (i = 0; i < Pool_Size; i++) { + if ((My_Connections[i].sock != NONE) + && (Proc_GetPipeFd(&My_Connections[i].proc_stat) == fd)) + return i; + } + return NONE; +} /* Conn_GetFromProc */ + #ifdef SSL_SUPPORT