This is the mail archive of the cygwin mailing list for the Cygwin project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
On Fri, Apr 13, 2007 at 03:25:01PM +0200, Corinna Vinschen wrote:
> On Apr 3 10:13, Bob Rossi wrote:
> > On Mon, Apr 02, 2007 at 08:37:53PM -0400, Christopher Faylor wrote:
> > > On Mon, Apr 02, 2007 at 08:07:23PM -0400, Bob Rossi wrote:
> > > >When ctrl-z is typed, CGDB receives a SIGTSTP on both linux and cygwin.
> > > >When CGDB is at the select loop and this happens on linux select returns
> > > >-1 and errno is set to EINTR. My code simple does a 'continue' when this
> > > >happens and the select loop is reentered. All works well. On cygwin,
> > > >select does not return with -1. (I didn't check the return value but I
> > > >can, I just compare to -1 in an if statement). In fact, select also
> > > >detects that input is ready on stdin. This causes CGDB to get to a read
> > > >system call (which is non blocking) and the read system call fails with
> > > >errno set to EAGAIN. This causes CGDB to exit.
> > > >
> > > >The main loop looks something like this,
> > > > if (select (max + 1, &rset, NULL, NULL, NULL) == -1)
> > > > {
> > > > if (errno == EINTR)
> > > > continue;
> > > > ..
> > > > }
> > > >
> > > > if (FD_ISSET (STDIN_FILENO, &rset)) {
> > > > handle_stdin
> > > > }
> > > >
> > > >So, my question is, is there a bug with select on cygwin? Is select
> > > >working properly and I should handle the read call differently? Why does
> > > >it act differently than linux?
> > >
> > > You say that something changed between different releases but you don't
> > > mention what those releases are. Is this releases of Cygwin? If so,
> > > what releases?
> > >
> > > If this is as easy to demonstrate as you say, then a simple test case
> > > is definitely called for.
> >
> > Hi Christopher,
> >
> > Attached is the test case. If I run it under linux, and then type ctrl-z, I
> > never get into the user_input_loop call. If I run it in cygwin, I do.
> >
> > Hopefully I'm doing something wrong here. Please advise!
>
> I'm a bit puzzled. I don't see any difference in behaviour on Linux and
> Cygwin related to your testcase. I have no problems to trigger the
> user_input_loop call on Linux and Cygwin. After I press ctrl-z, I don't
> get into it on both systems. After unsuspending the process, I get into
> user_input_loop on both systems again. Either your testcase is wrong,
> or you should exactly specify what has to be typed to trigger the
> problem. I tested this with Cygwin 1.5.24 and Linux 2.6.20.5, btw.
Hi Corinna,
Thanks for testing this! I definately do not get the same results as
you. On ubuntu linux,
$ uname -a
Linux black 2.6.17-11-386 #2 Thu Feb 1 19:50:13 UTC 2007 i686
GNU/Linux
I'm running cygwin version 1.5.24 and have attached cygcheck.out.
I've modified the main program slightly to better show the problem.
On both platforms I do,
gcc -g main.c -o main
On cygwin when I type './main' and then I type 'ctrl-z', I see this,
$ ./main.exe
Select return value:1
In user_input_loop
On linux when I type './main' and then I type 'ctrl-z', I see this,
$ ./main
[1]+ Stopped ./main
$ fg
./main
In fact, I never see the user_input_loop on linux.
What's interesting and annoying is that when I tested this last time on
linux, I was sure that after the SIGTSTP was sent, the select loop
returned. The value of val was -1 and errno was EINTR and I did a
continue to the loop again. However, with the example I just posted, it
appears that linux never breaks free of the select loop. I am still
seeing a difference between linux and cygwin as shown above.
I'm curious to know if this is a programming error on my part or if it
is a bug in the select call on cygwin.
Thanks!
Bob Rossi
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <termios.h>
static struct termios term_attributes;
int
tty_cbreak (int fd, struct termios *orig)
{
struct termios buf;
if (tcgetattr (fd, &buf) < 0)
return -1;
/* Save the original state, for resetting later */
*orig = buf;
buf.c_lflag &= ~(ECHO | ICANON);
buf.c_iflag &= ~(ICRNL | INLCR);
buf.c_cc[VMIN] = 1;
buf.c_cc[VTIME] = 0;
#if defined (VLNEXT) && defined (_POSIX_VDISABLE)
buf.c_cc[VLNEXT] = _POSIX_VDISABLE;
#endif
#if defined (VDSUSP) && defined (_POSIX_VDISABLE)
buf.c_cc[VDSUSP] = _POSIX_VDISABLE;
#endif
if (tcsetattr (fd, TCSAFLUSH, &buf) < 0)
return -1;
return 0;
}
int
tty_set_attributes (int fd, struct termios *buf)
{
if (tcsetattr (fd, TCSAFLUSH, buf) < 0)
return -1;
return 0;
}
int
user_input_loop ()
{
fprintf (stderr, "In user_input_loop\r\n");
return 0;
}
static int
main_loop (void)
{
fd_set rset;
int max = STDIN_FILENO;
int val;
for (;;)
{
/* Reset the fd_set, and watch for input from GDB or stdin */
FD_ZERO (&rset);
FD_SET (STDIN_FILENO, &rset);
/* Wait for input */
val =select (max + 1, &rset, NULL, NULL, NULL);
fprintf (stderr, "Select return value:%d\r\n", val);
if (val == -1)
{
if (errno == EINTR)
continue;
else
{
fprintf (stderr, __FILE__, __LINE__,
"select failed: %s", strerror (errno));
return -1;
}
}
/* Input received: Handle it */
if (FD_ISSET (STDIN_FILENO, &rset)) {
if (user_input_loop () == -1)
return -1;
return 0;
}
}
return 0;
}
int
main (int argc, char *argv[])
{
if (tty_cbreak (STDIN_FILENO, &term_attributes) == -1)
{
fprintf (stderr, __FILE__, __LINE__, "tty_cbreak error");
exit (-1);
}
/* Enter main loop */
main_loop ();
if (tty_set_attributes (STDIN_FILENO, &term_attributes) == -1)
fprintf (stderr, __FILE__, __LINE__, "tty_reset error");
return 0;
}
Attachment:
cygcheck.out
Description: Text document
-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |