Reintegrate socket duplication via WSADuplicateSocket/WSASocket.

* autoload.cc (WSADuplicateSocketW): Define.
	(WSASocketW): Define.
	* dtable.cc (dtable::release): Call dec_need_fixup_before if necessary.
	(dtable::fixup_before_fork): New function.
	(dtable::fixup_before_exec): New function.
	* dtable.h (class dtable): Add member cnt_need_fixup_before.  Add
	declarations for above new functions.
	(dtable::dec_need_fixup_before): New inline method.
	(dtable::inc_need_fixup_before): New inline method.
	(dtable::need_fixup_before): New inline method.
	* fhandler.h (fhandler_base::fixup_before_fork_exec): New virtual
	method.
	(fhandler_base::need_fixup_before): New virtual method.
	(class fhandler_socket): Add member prot_info_ptr.
	(fhandler_socket::init_fixup_before): Declare.
	(fhandler_socket::need_fixup_before): New inline method.
	(fhandler_socket::fixup_before_fork_exec): Declare.
	(fhandler_socket::fixup_after_exec): Declare.
	* fhandler_socket.cc (fhandler_socket::fhandler_socket): Initialize
	prot_info_ptr to NULL.
	(fhandler_socket::~fhandler_socket): Free prot_info_ptr conditionally.
	(fhandler_socket::init_fixup_before): New method.
	(fhandler_socket::fixup_before_fork_exec): Ditto.
	(fhandler_socket::fixup_after_fork): Use WSASocketW to duplicate
	socket if necessary.
	(fhandler_socket::fixup_after_exec): New method.
	(fhandler_socket::dup): Use fixup_before_fork_exec/fixup_after_fork
	to duplicate socket if necessary.
	* fork.cc (frok::parent): Start child suspended if some fhandler
	needs fixup before fork.  If so, call dtable::fixup_before_fork after
	CreateProcess and resume child.
	* net.cc (fdsock): Try to find out if socket needs fixup before and
	initialize socket accordingly.  Add HUGE comment to explain what happens
	and why.
	* spawn.cc (spawn_guts): Start child suspended if some fhandler needs
	fixup before exec.  If so, call dtable::fixup_before_exec after
	CreateProcess.
This commit is contained in:
Corinna Vinschen
2009-11-17 10:43:01 +00:00
parent 88242190ec
commit b14f53a8ec
9 changed files with 221 additions and 8 deletions

View File

@ -226,6 +226,7 @@ class fhandler_base
return close_on_exec () ? &sec_none_nih : &sec_none;
}
virtual int fixup_before_fork_exec (DWORD) { return 0; }
virtual void fixup_after_fork (HANDLE);
virtual void fixup_after_exec ();
void create_read_state (LONG n)
@ -270,6 +271,7 @@ class fhandler_base
/* fixup fd possibly non-inherited handles after fork */
bool fork_fixup (HANDLE, HANDLE &, const char *);
virtual bool need_fixup_before () const {return false;}
virtual int open (int, mode_t = 0);
int open_fs (int, mode_t = 0);
@ -463,6 +465,12 @@ class fhandler_socket: public fhandler_base
void rmem (int nrmem) { _rmem = nrmem; }
void wmem (int nwmem) { _wmem = nwmem; }
private:
struct _WSAPROTOCOL_INFOW *prot_info_ptr;
public:
void init_fixup_before ();
bool need_fixup_before () const {return prot_info_ptr != NULL;}
private:
char *sun_path;
char *peer_sun_path;
@ -524,7 +532,9 @@ class fhandler_socket: public fhandler_base
int dup (fhandler_base *child);
void set_close_on_exec (bool val);
int fixup_before_fork_exec (DWORD);
void fixup_after_fork (HANDLE);
void fixup_after_exec ();
char *get_proc_fd_name (char *buf);
select_record *select_read (select_stuff *);