about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2011-09-07 14:51:16 +0200
committerAlexander Barton <alex@barton.de>2011-09-07 14:51:16 +0200
commit30796698a9fca0037ea48f70ceafac1e783d06fb (patch)
tree2c8eecd6ae905840fc54588351ad5f47ef7c0fbb /src
parentf173a974bee5181d8131519ed07b3b5261bf6366 (diff)
downloadngircd-30796698a9fca0037ea48f70ceafac1e783d06fb.tar.gz
ngircd-30796698a9fca0037ea48f70ceafac1e783d06fb.zip
Only close "unrelated" sockets in forked child processes
This fixes the problem that ngIRCd can't do any IDENT lookups because
of the socket has already been closed in the child process.

The bug has been introduced starting with ngIRCd 17 ... :-(
(commit ID 6ebb31ab35e)
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/conn.c7
-rw-r--r--src/ngircd/conn.h4
-rw-r--r--src/ngircd/irc-login.c3
-rw-r--r--src/ngircd/proc.c1
-rw-r--r--src/ngircd/resolve.c6
5 files changed, 12 insertions, 9 deletions
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
index 407da1a3..aa754eb4 100644
--- a/src/ngircd/conn.c
+++ b/src/ngircd/conn.c
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2010 Alexander Barton <alex@barton.de>
+ * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -435,12 +435,13 @@ Conn_Exit( void )
  * they don't hold connections open that the main process wants to close.
  */
 GLOBAL void
-Conn_CloseAllSockets(void)
+Conn_CloseAllSockets(int ExceptOf)
 {
 	CONN_ID idx;
 
 	for(idx = 0; idx < Pool_Size; idx++) {
-		if(My_Connections[idx].sock > NONE)
+		if(My_Connections[idx].sock > NONE &&
+		   My_Connections[idx].sock != ExceptOf)
 			close(My_Connections[idx].sock);
 	}
 }
diff --git a/src/ngircd/conn.h b/src/ngircd/conn.h
index c813729f..251da2a0 100644
--- a/src/ngircd/conn.h
+++ b/src/ngircd/conn.h
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2010 Alexander Barton <alex@barton.de>
+ * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -106,7 +106,7 @@ GLOBAL long WCounter;
 GLOBAL void Conn_Init PARAMS((void ));
 GLOBAL void Conn_Exit PARAMS(( void ));
 
-GLOBAL void Conn_CloseAllSockets PARAMS((void));
+GLOBAL void Conn_CloseAllSockets PARAMS((int ExceptOf));
 
 GLOBAL unsigned int Conn_InitListeners PARAMS(( void ));
 GLOBAL void Conn_ExitListeners PARAMS(( void ));
diff --git a/src/ngircd/irc-login.c b/src/ngircd/irc-login.c
index 0577cd9c..884a06be 100644
--- a/src/ngircd/irc-login.c
+++ b/src/ngircd/irc-login.c
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -959,6 +959,7 @@ Hello_User(CLIENT * Client)
 	} else {
 		/* Sub process */
 		Log_Init_Subprocess("Auth");
+		Conn_CloseAllSockets(NONE);
 		result = PAM_Authenticate(Client);
 		if (write(pipefd[1], &result, sizeof(result)) != sizeof(result))
 			Log_Subprocess(LOG_ERR,
diff --git a/src/ngircd/proc.c b/src/ngircd/proc.c
index fd2df1d9..7addb47e 100644
--- a/src/ngircd/proc.c
+++ b/src/ngircd/proc.c
@@ -79,7 +79,6 @@ Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout
 		signal(SIGALRM, Proc_GenericSignalHandler);
 		close(pipefds[0]);
 		alarm(timeout);
-		Conn_CloseAllSockets();
 		return 0;
 	}
 
diff --git a/src/ngircd/resolve.c b/src/ngircd/resolve.c
index 9b17af9c..c7e60038 100644
--- a/src/ngircd/resolve.c
+++ b/src/ngircd/resolve.c
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2009 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -75,7 +75,8 @@ Resolve_Addr(PROC_STAT * s, const ng_ipaddr_t *Addr, int identsock,
 	} else if( pid == 0 ) {
 		/* Sub process */
 		Log_Init_Subprocess("Resolver");
-		Do_ResolveAddr( Addr, identsock, pipefd[1]);
+		Conn_CloseAllSockets(identsock);
+		Do_ResolveAddr(Addr, identsock, pipefd[1]);
 		Log_Exit_Subprocess("Resolver");
 		exit(0);
 	}
@@ -104,6 +105,7 @@ Resolve_Name( PROC_STAT *s, const char *Host, void (*cbfunc)(int, short))
 	} else if( pid == 0 ) {
 		/* Sub process */
 		Log_Init_Subprocess("Resolver");
+		Conn_CloseAllSockets(NONE);
 		Do_ResolveName(Host, pipefd[1]);
 		Log_Exit_Subprocess("Resolver");
 		exit(0);