mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: "Zou, Nanhai" <nanhai.zou@intel.com>
Cc: linux-kernel@vger.kernel.org, hongjiu.lu@intel.com
Subject: Re: [Patch] Fix a race condition in pty.c
Date: Fri, 17 Dec 2004 00:35:49 -0800	[thread overview]
Message-ID: <20041217003549.6bd66810.akpm@osdl.org> (raw)
In-Reply-To: <894E37DECA393E4D9374E0ACBBE7427013CA24@pdsmsx402.ccr.corp.intel.com>

"Zou, Nanhai" <nanhai.zou@intel.com> wrote:
>
>  <<pty_close-race-fix.patch>> There is a race condition int pty.c 
>  when pty_close wakes up waiter on its pair device before set
>  TTY_OTHER_CLOSED flag.
> 
>  It is possible on SMP or preempt kernel, waiter wakes up too early that
>  it will not get TTY_OTHER_CLOSED flag then fall into sleep again.
> 
>  Lu hong jiu report this bug will hang some expect scripts on SMP
>  machines.

The patch looks good (apart from the application/octet-stream encoding.  grr.)

But on my test box it still doesn't fix the testcase which hj attached to
bug 3894:

select (3) returns: 1
Read -1 characters.
errno: Input/output error
334
select (3) returns: 1
Read -1 characters.
errno: Input/output error
335

In fact the same happens on a non-preempt uniprocessor kernel, so I must be
seeing something different.

#include <sys/types.h> 
#include <sys/select.h>
#include <stdio.h>
#include <unistd.h>
#include <pty.h>

int
main ()
{
  pid_t pid;
  int fd;
  char slave_name [20];
  char buffer [1000];
  int count;
  fd_set readfds;
  int ret;

  pid = forkpty (&fd, slave_name, NULL, NULL);
  switch (pid)
    {
    case 0: /* Child process. */     
      if (execlp ("true", "true", NULL))
	perror ("execlp");
      return 1;
      break;

    default: /* Parent process. */
      break;
    } 

  FD_ZERO (&readfds);
  FD_SET (fd, &readfds);
  ret = select (1024, &readfds, NULL, NULL, NULL);
  printf ("select (%d) returns: %d\n", fd, ret);
  if (ret < 0)
    perror ("select");
  else if (FD_ISSET (fd, &readfds))
    {
      count = read (fd, buffer, 999);
      printf ("Read %d characters.\n", count);
      perror("errno");
    }
  return 0;
}


  reply	other threads:[~2004-12-17  8:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-17  3:07 Zou, Nanhai
2004-12-17  8:35 ` Andrew Morton [this message]
2004-12-17 17:09 Lu, Hongjiu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041217003549.6bd66810.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=hongjiu.lu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nanhai.zou@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®