🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
3 messages
3 total messages Started by Bruce M Ong Wed, 17 Oct 1990 20:46
Passing open file descriptor to the exec'ed process
#1045
Author: Bruce M Ong
Date: Wed, 17 Oct 1990 20:46
22 lines
1253 bytes
Hi -
	I have a question w/ regard to passing open file descriptors
from a parent to a child that's spawned with 'exec' not 'fork'. Basically,
how to do it right?

	I have a parent process that makes a socket connection with a remote
server. And depending on a server reply message type, I want the parent
process to exec another program (the parent process will go away, with
the new program replacing it). However, i dont want to close the connection
and open the connection again from the new program - I want the new program
to inherite the open socket descriptor and continue to talk to the server,
without the server knowing that the client has gone through a metamorphosis.

	Any hints or where can I find some source example, (does the BSD
inetd do something like this?) would be much appreciated.

	thanks -

	bruce
	deadhead@cup.portal.com
	
Re: Passing open file descriptor to the exec'ed process
#1055
Author: Thomas Olano
Date: Thu, 18 Oct 1990 17:04
21 lines
1613 bytes
In article <34954@cup.portal.com> DeadHead@cup.portal.com (Bruce M Ong) writes:
...
>	I have a parent process that makes a socket connection with a remote
>server. And depending on a server reply message type, I want the parent
>process to exec another program (the parent process will go away, with
>the new program replacing it). However, i dont want to close the connection
>and open the connection again from the new program - I want the new program
>to inherite the open socket descriptor and continue to talk to the server,


When I did something similar, I passed the open socket descriptor to the 
child using environment variables.  This may not be the "easiest" or "best"
way to do it, but hey, it worked!  Essentially the parent set an environment
variable with putenv() and the child read it with getenv().  Perhaps a more
elegant method would be to pass the descriptor as an argument in the exec
call.  The default is for files and sockets to remain open over and exec so
everything should be happy.

Marc Olano
olano@cs.unc.edu
no cute signature
Re: Passing open file descriptor to the exec'ed process
#1060
Author: Applied Magnetics
Date: Thu, 18 Oct 1990 21:02
17 lines
1211 bytes
In article <16903@thorin.cs.unc.edu> olano@currituck.cs.unc.edu (Thomas Olano) writes:

>In article <34954@cup.portal.com> DeadHead@cup.portal.com (Bruce M Ong) writes:
>...
>> [wants to open a socket and pass it through an exec()]
>
>When I did something similar, I passed the open socket descriptor to the 
>child using environment variables.  [...]

Sockets remain open across the exec.  If I understand the question
correctly, the problem is to tell the exec'd process which descriptor
carries the socket?  You should be able to open the socket, then use
dup2(2) to force it onto a pre-agreed descriptor.  This way, you don't
need to pass anything.

Disclaimer:  I haven't tried this.  Nor has my employer.
  --P. Asselin,  R&D, Applied Magnetics Corp.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads