* cygwin.din (ptsname_r): Export.

* fhandler.cc (fhandler_base::ptsname_r): Define.
* fhandler.h (fhandler_base::ptsname): Delete.
(fhandler_base::ptsname_r): Declare.
(fhandler_pty_master::ptsname_r): Declare.
* fhandler_tty.cc (fhandler_pty_master::ptsname): Delete.
(fhandler_pty_master::ptsname_r): New reentrant function derived from previous
ptsname.
* syscalls.cc (ptsname_r): Implement new function with functionality similar to
Linux.
(ptsname): Use ptsname_r () to fill out buf.
* include/cygwin/stdlib.h (ptsname_r): Declare.
* include/cygwin/version.h: Bump CYGWIN_VERSION_API_MINOR to 255 to reflect
export of ptsname_r.
* pinfo.cc (pinfo::wait): Return bool rather than int.
* pinfo.h (info::wait): Ditto.
(pinfo::reattach): Define !defined(_SIGPROC_H) case for consistency.
* sigproc.cc (child_info_spawn::reattach_children): Use correct dwProcessId
rather than pid when duplicating handle.
This commit is contained in:
Christopher Faylor 2011-11-07 20:05:49 +00:00
parent 78942629ac
commit 65a6152f18
11 changed files with 69 additions and 16 deletions

View File

@ -1,3 +1,26 @@
2011-11-07 Christopher Faylor <me.cygwin2011@cgf.cx>
* cygwin.din (ptsname_r): Export.
* fhandler.cc (fhandler_base::ptsname_r): Define.
* fhandler.h (fhandler_base::ptsname): Delete.
(fhandler_base::ptsname_r): Declare.
(fhandler_pty_master::ptsname_r): Declare.
* fhandler_tty.cc (fhandler_pty_master::ptsname): Delete.
(fhandler_pty_master::ptsname_r): New reentrant function derived from
previous ptsname.
* syscalls.cc (ptsname_r): Implement new function with functionality
similar to Linux.
(ptsname): Use ptsname_r () to fill out buf.
* include/cygwin/stdlib.h (ptsname_r): Declare.
* include/cygwin/version.h: Bump CYGWIN_VERSION_API_MINOR to 255 to
reflect export of ptsname_r.
* pinfo.cc (pinfo::wait): Return bool rather than int.
* pinfo.h (info::wait): Ditto.
(pinfo::reattach): Define !defined(_SIGPROC_H) case for consistency.
* sigproc.cc (child_info_spawn::reattach_children): Use correct
dwProcessId rather than pid when duplicating handle.
2011-11-07 Corinna Vinschen <corinna@vinschen.de> 2011-11-07 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (CHUNK_SIZE): Drop NO_COPY. * fhandler.cc (CHUNK_SIZE): Drop NO_COPY.

View File

@ -1277,6 +1277,7 @@ pthread_spin_unlock SIGFE
pthread_testcancel SIGFE pthread_testcancel SIGFE
pthread_yield = sched_yield SIGFE pthread_yield = sched_yield SIGFE
ptsname SIGFE ptsname SIGFE
ptsname_r SIGFE
putc SIGFE putc SIGFE
_putc = putc SIGFE _putc = putc SIGFE
putc_unlocked SIGFE putc_unlocked SIGFE

View File

@ -1407,6 +1407,13 @@ fhandler_base::tcgetsid ()
return -1; return -1;
} }
int
fhandler_base::ptsname_r (char *, size_t)
{
set_errno (ENOTTY);
return ENOTTY;
}
void void
fhandler_base::operator delete (void *p) fhandler_base::operator delete (void *p)
{ {

View File

@ -381,7 +381,7 @@ public:
virtual pid_t get_popen_pid () const {return 0;} virtual pid_t get_popen_pid () const {return 0;}
virtual bool isdevice () const { return true; } virtual bool isdevice () const { return true; }
virtual bool isfifo () const { return false; } virtual bool isfifo () const { return false; }
virtual char *ptsname () { return NULL;} virtual int ptsname_r (char *, size_t);
virtual class fhandler_socket *is_socket () { return NULL; } virtual class fhandler_socket *is_socket () { return NULL; }
virtual class fhandler_console *is_console () { return 0; } virtual class fhandler_console *is_console () { return 0; }
virtual int is_windows () {return 0; } virtual int is_windows () {return 0; }
@ -1486,7 +1486,7 @@ public:
int tcflush (int); int tcflush (int);
int ioctl (unsigned int cmd, void *); int ioctl (unsigned int cmd, void *);
char *ptsname (); int ptsname_r (char *, size_t);
bool hit_eof (); bool hit_eof ();
bool setup (); bool setup ();

View File

@ -1419,13 +1419,19 @@ fhandler_pty_master::ioctl (unsigned int cmd, void *arg)
return 0; return 0;
} }
char * int
fhandler_pty_master::ptsname () fhandler_pty_master::ptsname_r (char *buf, size_t buflen)
{ {
static char buf[TTY_NAME_MAX]; char tmpbuf[TTY_NAME_MAX];
__small_sprintf (buf, "/dev/pty%d", get_unit ()); __small_sprintf (tmpbuf, "/dev/pty%d", get_unit ());
return buf; if (buflen <= strlen (tmpbuf))
{
set_errno (ERANGE);
return ERANGE;
}
strcpy (buf, tmpbuf);
return 0;
} }
void void

View File

@ -30,6 +30,7 @@ long random (void);
char *setstate (const char *state); char *setstate (const char *state);
void srandom (unsigned); void srandom (unsigned);
char *ptsname (int); char *ptsname (int);
int ptsname_r(int, char *, size_t);
int grantpt (int); int grantpt (int);
int unlockpt (int); int unlockpt (int);
#endif /*__STRICT_ANSI__*/ #endif /*__STRICT_ANSI__*/

View File

@ -423,12 +423,13 @@ details. */
252: CW_CVT_ENV_TO_WINENV added. 252: CW_CVT_ENV_TO_WINENV added.
253: Export TIOCSCTTY, tcgetsid. 253: Export TIOCSCTTY, tcgetsid.
254: Export getgrouplist. 254: Export getgrouplist.
255: Export ptsname_r.
*/ */
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0 #define CYGWIN_VERSION_API_MAJOR 0
#define CYGWIN_VERSION_API_MINOR 254 #define CYGWIN_VERSION_API_MINOR 255
/* There is also a compatibity version number associated with the /* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible shared memory regions. It is incremented when incompatible

View File

@ -975,10 +975,10 @@ _pinfo::dup_proc_pipe (HANDLE hProcess)
} }
/* function to set up the process pipe and kick off proc_waiter */ /* function to set up the process pipe and kick off proc_waiter */
int bool
pinfo::wait () pinfo::wait ()
{ {
/* If rd_proc_pipe that means we're in an execed process which already has /* If rd_proc_pipe != NULL we're in an execed process which already has
grabbed the read end of the pipe from the previous cygwin process running grabbed the read end of the pipe from the previous cygwin process running
with this pid. */ with this pid. */
if (!rd_proc_pipe) if (!rd_proc_pipe)
@ -989,13 +989,13 @@ pinfo::wait ()
{ {
system_printf ("Couldn't create pipe tracker for pid %d, %E", system_printf ("Couldn't create pipe tracker for pid %d, %E",
(*this)->pid); (*this)->pid);
return 0; return false;
} }
if (!(*this)->dup_proc_pipe (hProcess)) if (!(*this)->dup_proc_pipe (hProcess))
{ {
system_printf ("Couldn't duplicate pipe topid %d(%p), %E", (*this)->pid, hProcess); system_printf ("Couldn't duplicate pipe topid %d(%p), %E", (*this)->pid, hProcess);
return 0; return false;
} }
} }
@ -1013,7 +1013,7 @@ pinfo::wait ()
(*this)->pid, (*this)->dwProcessId, rd_proc_pipe); (*this)->pid, (*this)->dwProcessId, rd_proc_pipe);
} }
return 1; return true;
} }
void void

View File

@ -153,7 +153,7 @@ public:
pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL), waiter_ready (0), wait_thread (NULL) {init (n, flag, NULL);} pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL), waiter_ready (0), wait_thread (NULL) {init (n, flag, NULL);}
void thisproc (HANDLE) __attribute__ ((regparm (2))); void thisproc (HANDLE) __attribute__ ((regparm (2)));
void release (); void release ();
int wait () __attribute__ ((regparm (1))); bool wait () __attribute__ ((regparm (1)));
~pinfo () ~pinfo ()
{ {
if (destroy && procinfo) if (destroy && procinfo)
@ -173,6 +173,7 @@ public:
operator _pinfo * () const {return procinfo;} operator _pinfo * () const {return procinfo;}
void preserve () { destroy = false; } void preserve () { destroy = false; }
#ifndef _SIGPROC_H #ifndef _SIGPROC_H
int reattach () {system_printf ("reattach is not here"); return 0;}
int remember () {system_printf ("remember is not here"); return 0;} int remember () {system_printf ("remember is not here"); return 0;}
#else #else
int reattach () int reattach ()

View File

@ -866,7 +866,7 @@ child_info_spawn::reattach_children ()
false, DUPLICATE_SAME_ACCESS)) false, DUPLICATE_SAME_ACCESS))
debug_printf ("couldn't duplicate parent %p handles for forked children after exec, %E", debug_printf ("couldn't duplicate parent %p handles for forked children after exec, %E",
children[i].rd_proc_pipe); children[i].rd_proc_pipe);
else if (!(p.hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, false, p->pid))) else if (!(p.hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, false, p->dwProcessId)))
CloseHandle (p.rd_proc_pipe); CloseHandle (p.rd_proc_pipe);
else if (!p.reattach ()) else if (!p.reattach ())
{ {

View File

@ -2906,10 +2906,23 @@ getpgrp (void)
extern "C" char * extern "C" char *
ptsname (int fd) ptsname (int fd)
{ {
static char buf[TTY_NAME_MAX];
return ptsname_r (fd, buf, sizeof (buf)) == 0 ? buf : NULL;
}
extern "C" int
ptsname_r (int fd, char *buf, size_t buflen)
{
if (!buf)
{
set_errno (EINVAL);
return EINVAL;
}
cygheap_fdget cfd (fd); cygheap_fdget cfd (fd);
if (cfd < 0) if (cfd < 0)
return 0; return 0;
return (char *) (cfd->ptsname ()); return cfd->ptsname_r (buf, buflen);
} }
static int __stdcall static int __stdcall