diff options
author | Christopher Faylor <me@cgf.cx> | 2003-01-05 03:01:29 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-01-05 03:01:29 +0000 |
commit | 426ad1bd00e18fb2dcb6d1c1b9126e7e7bf21215 (patch) | |
tree | 0e4156cd0cc97e8b4c02dbb32cc4abfa0f10b330 | |
parent | dbb84327d92f085c07759ba39b79f0242510e1d5 (diff) | |
download | newlib-github/unlabeled-1.44.4.zip newlib-github/unlabeled-1.44.4.tar.gz newlib-github/unlabeled-1.44.4.tar.bz2 |
Replace is_fs_device with is_fs_special throughout.github/unlabeled-1.44.4unlabeled-1.44.4
* Makefile.in (DLL_OFILES): Add fhandler_fifo.o.
* devices.h (fh_devices): Renumber some minor numbers to fit in 8 bits.
* dtable.cc (dtable::build_fhandler): Handle FH_FIFO. Set errno to ENODEV if
device not found.
* dtable::find_fifo: Define new function.
* dtable.h (dtable::find_fifo): Declare new function.
* fhandler.cc (fhandler_base::device_access_denied): Fix O_RDONLY test.
(fhandler_base::write): Use output file handle for writing.
(fhandler_base::fstat): Use is_fs_special rather than is_fs_device.
* fhandler.h (fhandler_base::is_fs_special): Rename from is_fs_device.
(fhandler_pipe): Make private elements protected so that fhandler_fifo can use
them too.
(fhandler_pipe::create): New function derived from make_pipe.
(fhandler_fifo): Add more needed elements.
(fhandler_pty_master::slave): Add to track slave device.
(fhandler_pty_master::get_unit): Define.
* fhandler_tty.cc (fhandler_tty_master::init): Register slave device.
(fhandler_pty_master::open): Ditto.
(symlink_info::parse_device): Handle fifo specially.
* pinfo.cc (_pinfo::commune_recv): Initial fifo implementation.
(_pinfo::commune_send): Ditto.
* pinfo.h (picom): Add PICOM_FIFO.
* pipe.cc (fhandler_pipe::close): Close input handle here specifically.
(fhandler_pipe::create): Rename from make_pipe. Create fhandlers rather than
fds.
(pipe): Use fhandler_pipe::create to create pipe.
(_pipe): Ditto.
* syscalls.cc (mknod): Accommodate fifos.
-rw-r--r-- | winsup/cygwin/pipe.cc | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index 0749a66..9d42753 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -83,16 +83,21 @@ fhandler_pipe::read (void *in_ptr, size_t& in_len) return; } -int fhandler_pipe::close () +int +fhandler_pipe::close () { - int res = this->fhandler_base::close (); if (guard) CloseHandle (guard); if (writepipe_exists) CloseHandle (writepipe_exists); if (read_state && !cygheap->fdtab.in_vfork_cleanup ()) CloseHandle (read_state); - return res; + if (get_handle ()) + { + CloseHandle (get_handle ()); + set_io_handle (NULL); + } + return 0; } bool @@ -174,55 +179,45 @@ fhandler_pipe::dup (fhandler_base *child) } int -make_pipe (int fildes[2], unsigned int psize, int mode) +fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode, bool fifo) { HANDLE r, w; SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none; int res = -1; - cygheap_fdnew fdr; - if (fdr >= 0) + if (!CreatePipe (&r, &w, sa, psize)) + __seterrno (); + else { - cygheap_fdnew fdw (fdr, false); - if (fdw < 0) - /* out of fds? */; - else if (!CreatePipe (&r, &w, sa, psize)) - __seterrno (); - else + fhs[0] = (fhandler_pipe *) cygheap->fdtab.build_fhandler (-1, *piper_dev, "/dev/piper"); + fhs[1] = (fhandler_pipe *) cygheap->fdtab.build_fhandler (-1, *pipew_dev, "/dev/pipew"); + + int binmode = mode & O_TEXT ?: O_BINARY; + fhs[0]->init (r, GENERIC_READ, binmode); + fhs[1]->init (w, GENERIC_WRITE, binmode); + if (mode & O_NOINHERIT) + { + fhs[0]->set_close_on_exec_flag (1); + fhs[1]->set_close_on_exec_flag (1); + } + + fhs[0]->read_state = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); + fhs[0]->set_need_fork_fixup (); + + res = 0; + fhs[0]->create_guard (sa); + if (wincap.has_unreliable_pipes ()) { - fhandler_pipe *fhr = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdr, *piper_dev, "/dev/piper"); - fhandler_pipe *fhw = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdw, *pipew_dev, "/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; - fhr->read_state = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); - fhr->set_need_fork_fixup (); - - 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; - } + char buf[80]; + int count = pipecount++; /* FIXME: Should this be InterlockedIncrement? */ + __small_sprintf (buf, pipeid_fmt, myself->pid, count); + fhs[1]->writepipe_exists = CreateEvent (sa, TRUE, FALSE, buf); + fhs[0]->orig_pid = myself->pid; + fhs[0]->id = count; } } - syscall_printf ("%d = make_pipe ([%d, %d], %d, %p)", res, fildes[0], - fildes[1], psize, mode); + syscall_printf ("%d = ([%p, %p], %d, %p)", res, fhs[0], fhs[1], psize, mode); return res; } @@ -257,15 +252,38 @@ extern "C" int pipe (int filedes[2]) { extern DWORD binmode; - return make_pipe (filedes, 16384, (!binmode || binmode == O_BINARY) ? O_BINARY : O_TEXT); + fhandler_pipe *fhs[2]; + int res = fhandler_pipe::create (fhs, 16384, (!binmode || binmode == O_BINARY) + ? O_BINARY : O_TEXT); + if (res == 0) + { + cygheap_fdnew fdin; + cygheap_fdnew fdout (fdin, false); + fdin = fhs[0]; + fdout = fhs[1]; + filedes[0] = fdin; + filedes[1] = fdout; + } + + return res; } extern "C" int _pipe (int filedes[2], unsigned int psize, int mode) { - int res = make_pipe (filedes, psize, mode); + fhandler_pipe *fhs[2]; + int res = fhandler_pipe::create (fhs, psize, mode); /* This type of pipe is not interruptible so set the appropriate flag. */ if (!res) - cygheap->fdtab[filedes[0]]->set_r_no_interrupt (1); + { + cygheap_fdnew fdin; + cygheap_fdnew fdout (fdin, false); + fhs[0]->set_r_no_interrupt (1); + fdin = fhs[0]; + fdout = fhs[1]; + filedes[0] = fdin; + filedes[1] = fdout; + } + return res; } |