From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19913 invoked by alias); 19 Apr 2007 12:20:18 -0000 Received: (qmail 19904 invoked by uid 22791); 19 Apr 2007 12:20:17 -0000 X-Spam-Check-By: sourceware.org Received: from province.act-europe.fr (HELO province.act-europe.fr) (212.157.227.214) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 19 Apr 2007 13:20:11 +0100 Received: by province.act-europe.fr (Postfix, from userid 560) id A6F7E164DD4; Thu, 19 Apr 2007 14:20:08 +0200 (CEST) Date: Thu, 19 Apr 2007 12:26:00 -0000 From: Jerome Guitton To: gdb-patches@sources.redhat.com Subject: [RFA/mingw32] stdin redirection Message-ID: <20070419122008.GA27914@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="E/DnYTRukya0zdZ1" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-04/txt/msg00291.txt.bz2 --E/DnYTRukya0zdZ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 455 Related to this discussion: http://sourceware.org/ml/gdb/2007-04/msg00063.html It appeared that we should not use WaitForMultipleObjects on a file handle. Here is a patch (inspired from the way GDB deals with pipes on mingw32) to fix this issue. OK to apply? 2007-04-19 Jerome Guitton * ser-mingw.c (fd_is_file): New function. (file_select_thread): New function. (ser_console_wait_handle): Add special handling for files. --E/DnYTRukya0zdZ1 Content-Type: video/dv Content-Disposition: attachment; filename="ser-mingw.c.dif" Content-Transfer-Encoding: quoted-printable Content-length: 3000 Index: ser-mingw.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/ser-mingw.c,v=0A= retrieving revision 1.8=0A= diff -u -p -r1.8 ser-mingw.c=0A= --- ser-mingw.c 8 Apr 2007 15:20:07 -0000 1.8=0A= +++ ser-mingw.c 19 Apr 2007 12:17:29 -0000=0A= @@ -453,6 +453,15 @@ fd_is_pipe (int fd)=0A= return 0;=0A= }=0A= =20=0A= +static int=0A= +fd_is_file (int fd)=0A= +{=0A= + if (GetFileType ((HANDLE) _get_osfhandle (fd)) =3D=3D FILE_TYPE_DISK)=0A= + return 1;=0A= + else=0A= + return 0;=0A= +}=0A= +=0A= static DWORD WINAPI=0A= pipe_select_thread (void *arg)=0A= {=0A= @@ -501,6 +510,51 @@ pipe_select_thread (void *arg)=0A= }=0A= }=0A= =20=0A= +static DWORD WINAPI=0A= +file_select_thread (void *arg)=0A= +{=0A= + struct serial *scb =3D arg;=0A= + struct ser_console_state *state;=0A= + int event_index;=0A= + HANDLE h;=0A= +=0A= + state =3D scb->state;=0A= + h =3D (HANDLE) _get_osfhandle (scb->fd);=0A= +=0A= + while (1)=0A= + {=0A= + HANDLE wait_events[2];=0A= + DWORD n_avail;=0A= +=0A= + SetEvent (state->have_stopped);=0A= +=0A= + wait_events[0] =3D state->start_select;=0A= + wait_events[1] =3D state->exit_select;=0A= +=0A= + if (WaitForMultipleObjects (2, wait_events, FALSE, INFINITE) !=3D WA= IT_OBJECT_0)=0A= + return 0;=0A= +=0A= + ResetEvent (state->have_stopped);=0A= +=0A= + retry:=0A= + if (SetFilePointer (h, 0, NULL, FILE_CURRENT) =3D=3D INVALID_SET_FIL= E_POINTER)=0A= + {=0A= + SetEvent (state->except_event);=0A= + continue;=0A= + }=0A= +=0A= + SetEvent (state->read_event);=0A= + continue;=0A= +=0A= + /* Delay 10ms before checking again, but allow the stop event=0A= + to wake us. */=0A= + if (WaitForSingleObject (state->stop_select, 10) =3D=3D WAIT_OBJECT_= 0)=0A= + continue;=0A= +=0A= + goto retry;=0A= + }=0A= +}=0A= +=0A= static void=0A= ser_console_wait_handle (struct serial *scb, HANDLE *read, HANDLE *except)= =0A= {=0A= @@ -512,7 +566,7 @@ ser_console_wait_handle (struct serial *=0A= int is_tty;=0A= =20=0A= is_tty =3D isatty (scb->fd);=0A= - if (!is_tty && !fd_is_pipe (scb->fd))=0A= + if (!is_tty && !fd_is_file (scb->fd) && !fd_is_pipe (scb->fd))=0A= {=0A= *read =3D NULL;=0A= *except =3D NULL;=0A= @@ -541,9 +595,12 @@ ser_console_wait_handle (struct serial *=0A= if (is_tty)=0A= state->thread =3D CreateThread (NULL, 0, console_select_thread, scb, 0,= =0A= &threadId);=0A= - else=0A= + else if (fd_is_pipe (scb->fd))=0A= state->thread =3D CreateThread (NULL, 0, pipe_select_thread, scb, 0,=0A= &threadId);=0A= + else=0A= + state->thread =3D CreateThread (NULL, 0, file_select_thread, scb, 0,=0A= + &threadId);=0A= }=0A= =20=0A= *read =3D state->read_event;=0A= --E/DnYTRukya0zdZ1--