This is the mail archive of the cygwin@sourceware.cygnus.com
mailing list for the Cygwin project. See the Cygwin
home page for more information.
[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]
Re: Problem with socketpair/fork/dup2/fdopen b20
- To: Francois Felix Ingrand <felix@dial.oleane.com>
- Subject: Re: Problem with socketpair/fork/dup2/fdopen b20
- From: Mumit Khan <khan@xraylith.wisc.EDU>
- Date: Sat, 06 Feb 1999 16:19:37 -0600
- cc: gnu-win32@cygnus.com
- Delivered-To: listarch-cygwin@sourceware.cygnus.com
- Delivered-To: mailing list cygwin@sourceware.cygnus.com
- In-reply-to: Your message of "06 Feb 1999 13:56:28 +0100." <8690ebsnb7.fsf@dial.oleane.com>
- Mailing-List: contact cygwin-help@sourceware.cygnus.com; run by ezmlm
Francois Felix Ingrand <felix@dial.oleane.com> writes:
>
> I cannot get this to work.
>
> fdopen returns NULL and perror a bad file descriptor... which would suggest
> that dup2 did not duplicate stdout in sp[1]...
[ .. snippet of example code ... ]
Hi Francois,
I have code that does similar thing and it works on Cygwin as it does on
every POSIX-type system I've run it on.
Unless someone can spot something weird, you'll need to supply standalone
code that we can compile and run. I'm not sure I understand your
logic behind dup'ing stdin/stdout and then fdopen for read/write in the
child, but that's probably because I don't know what your code really
does.
I suggest you chop it down to the smallest size possible and repost as a
bug report.
Regards,
Mumit
>
> It work under Solaris and other Unices...
>
> void call_propice_cat(char *log_file)
> {
> int pid, sp[2];
>
> if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) < 0) {
> perror("call_propice: socketpair");
> exit(1);
> }
> fcntl(sp[1], F_SETFD, 1); /* this is to avoid that the ns will be d
> up when we fork */
>
> if ((pid = fork()) < 0) {
> perror("fork");
> exit(1);
> }
>
> if (pid) { /* The father */
> close(sp[0]); /* Close one side */
> fcntl(sp[1], F_SETFL, FNDELAY); /* I am not sure this is required...
> */
> if (dup2(sp[1],1) < 0)
> perror("call_propice_cat:dup2"); /* Get stdout plug on sp[1] */
> /* dup2(sp[1],2); Get stderr plug on sp[1] */
>
> propicefp = (FILE *)fdopen(sp[1], "r+");
> if (! propicefp)
> perror("call_propice_cat:fdopen"); /* Get stdout plug on
> sp[1] */
> setbuf(propicefp, NULL);
>
> propiceInputId = XtAppAddInput(app_context, sp[1], (XtPointer)XtInput
> ReadMask, read_propice, NULL);
> } else { /* The child */
>
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> "J'en ai cauchemarde... Microsoft l'a fait."
> Professional: http://www.laas.fr/~felix mailto:felix@laas.fr
> Personal: http://worldserver.oleane.com/felix mailto:felix@dial.oleane.com
>
>
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe@sourceware.cygnus.com
>
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com