Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/pipe.cc')
-rw-r--r--winsup/cygwin/pipe.cc98
1 files changed, 50 insertions, 48 deletions
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index 099aa37b3..b37a7751e 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -1,6 +1,6 @@
/* pipe.cc: pipe for Cygwin.
- Copyright 1996, 1998, 1999, 2000, 2001 Red Hat, Inc.
+ Copyright 1996, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
This file is part of Cygwin.
@@ -8,9 +8,10 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
+/* FIXME: Should this really be fhandler_pipe.cc? */
+
#include "winsup.h"
#include <unistd.h>
-#include <sys/fcntl.h>
#include <errno.h>
#include "cygerrno.h"
#include "security.h"
@@ -19,21 +20,19 @@ details. */
#include "dtable.h"
#include "cygheap.h"
#include "thread.h"
-#include "sigproc.h"
#include "pinfo.h"
static unsigned pipecount;
static const NO_COPY char pipeid_fmt[] = "stupid_pipe.%u.%u";
-fhandler_pipe::fhandler_pipe (const char *name, DWORD devtype) :
- fhandler_base (devtype, name),
- guard (0), writepipe_exists(0), orig_pid (0), id (0)
+fhandler_pipe::fhandler_pipe (DWORD devtype)
+ : fhandler_base (devtype), guard (NULL), broken_pipe (false), writepipe_exists(0),
+ orig_pid (0), id (0)
{
- set_cb (sizeof *this);
}
-off_t
-fhandler_pipe::lseek (off_t offset, int whence)
+__off64_t
+fhandler_pipe::lseek (__off64_t offset, int whence)
{
debug_printf ("(%d, %d)", offset, whence);
set_errno (ESPIPE);
@@ -50,11 +49,13 @@ fhandler_pipe::set_close_on_exec (int val)
set_inheritance (writepipe_exists, val);
}
-int
+int __stdcall
fhandler_pipe::read (void *in_ptr, size_t in_len)
{
+ if (broken_pipe)
+ return 0;
int res = this->fhandler_base::read (in_ptr, in_len);
- ReleaseMutex (guard);
+ (void) ReleaseMutex (guard);
return res;
}
@@ -73,6 +74,8 @@ fhandler_pipe::hit_eof ()
{
char buf[80];
HANDLE ev;
+ if (broken_pipe)
+ return 1;
if (!orig_pid)
return false;
__small_sprintf (buf, pipeid_fmt, orig_pid, id);
@@ -125,55 +128,54 @@ fhandler_pipe::dup (fhandler_base *child)
return 0;
}
-
int
make_pipe (int fildes[2], unsigned int psize, int mode)
{
- SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "make_pipe");
-
HANDLE r, w;
- int fdr = -1, fdw = -1;
SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none;
int res = -1;
- if ((fdr = cygheap->fdtab.find_unused_handle ()) < 0)
- set_errno (ENMFILE);
- else if ((fdw = cygheap->fdtab.find_unused_handle (fdr + 1)) < 0)
- set_errno (ENMFILE);
- else if (!CreatePipe (&r, &w, sa, psize))
- __seterrno ();
- else
+ cygheap_fdnew fdr;
+ if (fdr >= 0)
{
- fhandler_pipe *fhr = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper");
- fhandler_pipe *fhw = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
-
- int binmode = mode & O_TEXT ? 0 : 1;
- fhr->init (r, GENERIC_READ, binmode);
- fhw->init (w, GENERIC_WRITE, binmode);
- if (mode & O_NOINHERIT)
- {
- fhr->set_close_on_exec_flag (1);
- fhw->set_close_on_exec_flag (1);
- }
-
- fildes[0] = fdr;
- fildes[1] = fdw;
-
- res = 0;
- fhr->create_guard (sa);
- if (wincap.has_unreliable_pipes ())
+ cygheap_fdnew fdw (fdr, false);
+ if (fdw < 0)
+ /* out of fds? */;
+ else if (!CreatePipe (&r, &w, sa, psize))
+ __seterrno ();
+ else
{
- char buf[80];
- int count = pipecount++; /* FIXME: Should this be InterlockedIncrement? */
- __small_sprintf (buf, pipeid_fmt, myself->pid, count);
- fhw->writepipe_exists = CreateEvent (sa, TRUE, FALSE, buf);
- fhr->orig_pid = myself->pid;
- fhr->id = count;
+ fhandler_pipe *fhr = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper");
+ fhandler_pipe *fhw = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
+
+ int binmode = mode & O_TEXT ?: O_BINARY;
+ fhr->init (r, GENERIC_READ, binmode);
+ fhw->init (w, GENERIC_WRITE, binmode);
+ if (mode & O_NOINHERIT)
+ {
+ fhr->set_close_on_exec_flag (1);
+ fhw->set_close_on_exec_flag (1);
+ }
+
+ fildes[0] = fdr;
+ fildes[1] = fdw;
+
+ res = 0;
+ fhr->create_guard (sa);
+ if (wincap.has_unreliable_pipes ())
+ {
+ char buf[80];
+ int count = pipecount++; /* FIXME: Should this be InterlockedIncrement? */
+ __small_sprintf (buf, pipeid_fmt, myself->pid, count);
+ fhw->writepipe_exists = CreateEvent (sa, TRUE, FALSE, buf);
+ fhr->orig_pid = myself->pid;
+ fhr->id = count;
+ }
}
}
- syscall_printf ("%d = make_pipe ([%d, %d], %d, %p)", res, fdr, fdw, psize, mode);
- ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "make_pipe");
+ syscall_printf ("%d = make_pipe ([%d, %d], %d, %p)", res, fildes[0],
+ fildes[1], psize, mode);
return res;
}