All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <dan@debian.org>
To: linux-kernel@vger.kernel.org
Subject: Blocking behavior changed for pipes in 2.6.11-rc3
Date: Fri, 11 Feb 2005 22:19:04 -0500	[thread overview]
Message-ID: <20050212031904.GA18380@nevyn.them.org> (raw)

This program [cribbed loosely from tst-cancel17.c in glibc] has changed
behavior with the recent pipe changes.  It used to block; which makes sense.
It gets the maximum buffer size for the pipe (or a page if that's larger),
and writes that many bytes plus two to it.  It reads one back.  The write
"shouldn't" have room to finish.

Checking the POSIX language for _PC_PIPE_BUF I think this is OK - it doesn't
say that no more bytes than that can be written at once, just that this is
the maximum which are guaranteed to be written atomically.  So I'm guessing
this change is a feature, not a bug.  Right?

[snip]

#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void *
tf (void *fd)
{
  int *fds = fd;
  char mem[1];
  read (fds[0], mem, 1);
}

int
main (void)
{
  pthread_t th;
  int len;
  int fds[2];

  if (pipe (fds) != 0)
    {
      puts ("pipe failed");
      return 1;
    }

  size_t len2 = fpathconf (fds[1], _PC_PIPE_BUF);
  size_t page_size = sysconf (_SC_PAGESIZE);
  len2 = (len2 < page_size ? page_size : len2) + 1 + 1;
  char *mem2 = malloc (len2);

  pthread_create (&th, NULL, tf, fds);
  write (fds[1], mem2, len2);

  return 0;
}

[/snip]

-- 
Daniel Jacobowitz
CodeSourcery, LLC

                 reply	other threads:[~2005-02-12  3:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20050212031904.GA18380@nevyn.them.org \
    --to=dan@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.