From: Alain Magloire Message-Id: <199903020302.WAA09354@mccoy2.ECE.McGill.CA> Subject: Re: inetutils To: eliz AT is DOT elta DOT co DOT il (Eli Zaretskii) Date: Mon, 1 Mar 1999 22:02:58 -0500 (EST) Cc: djgpp-workers AT delorie DOT com In-Reply-To: from "Eli Zaretskii" at Mar 1, 99 11:23:32 am X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Bonjour > So you will need to do something like this: > > system ("start.exe /m redir -i input -o output -e error foo.exe"); > > ("redir" is a standard program that comes with DJGPP.) > > This still has some problems, like passing the environment variables > (we could change "redir" to read them from a file), and the > redirection will not work in certain cases, like when the parent and > the child try to write to the same file, because Windows generally > prevents two programs from writing to the same file. > But let me explain briefly, inetutils is a collection of servers and clients. The servers are all spawn by the superdaemon inetd. Inetd after accept()ing a connection set the stage to run the server : select(); fd = accept(); pid = fork() pid == 0 { dup2(fd, 0); dup2(fd, 1) dup2(fd, 2); exec("ftpd/telnetd/rlogind .."); } ... sigaction (SIGCHLD) ==> wait3("reaped child") The std{in,out,err} are sockets handles. And in fact the code is full of fgets()/putc() etc .. all servers take for granted that the std I/O are redirected. The problem with system() is that I don't have the pid for the wait but if I read your post right doing a waitpid() after a start /m is meaningless. Passing file descriptors to another processes is sometimes supported via ioctl(). But I don't think it exists on DJGPP. A cleaner solution would be to have the SVR4 interface of /dev/fd/n where n is the file descriptor. for example : /dev/fd/0 --> stdin /dev/fd/1 --> stdout etc .. so one could do : redir -i /dev/fd/123 -o /dev/fd/123 -e /dev/13 ftpd.exe Or maybe reserve the namespace "/dev/tcp" for the networking library. So /dev/tcp/xxx could be use to pass handle around. I don't know enough about DJGPP nor libsocket to see if this is feasible. -- au revoir, alain ---- Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!