зеркало из https://github.com/mozilla/gecko-dev.git
Fixed Bugzilla bug #45181.
Modified files: _beos.h, _macos.h, _os2.h, _unixos.h, _win95.h, _winnt.h, primpl.h, prfile.c, prio.c, prsocket.c, bfile.c, macsockotpt.c, os2io.c, unix.c, ntio.c, w95io.c, prinit.c, ptio.c
This commit is contained in:
Родитель
cd1abc962e
Коммит
dacf1ff7d8
|
@ -303,6 +303,8 @@ struct protoent* getprotobynumber(int number);
|
|||
#define _MD_READ_DIR _MD_read_dir
|
||||
#define _MD_CLOSE_DIR _MD_close_dir
|
||||
#define _MD_MAKE_NONBLOCK _MD_make_nonblock
|
||||
#define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable
|
||||
#define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable
|
||||
#define _MD_OPEN _MD_open
|
||||
#define _MD_OPEN_FILE _MD_open
|
||||
#define _MD_CLOSE_FILE _MD_close_file
|
||||
|
@ -500,6 +502,8 @@ NSPR_API(PRStatus) _MD_open_dir(struct _MDDir *md,const char *name);
|
|||
NSPR_API(char *) _MD_read_dir(struct _MDDir *md, PRIntn flags);
|
||||
NSPR_API(PRInt32) _MD_close_dir(struct _MDDir *md);
|
||||
NSPR_API(void) _MD_make_nonblock(PRFileDesc *fd);
|
||||
NSPR_API(void) _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported);
|
||||
NSPR_API(void) _MD_query_fd_inheritable(PRFileDesc *fd);
|
||||
NSPR_API(PRInt32) _MD_open(const char *name, PRIntn osflags, PRIntn mode);
|
||||
NSPR_API(PRInt32) _MD_close_file(PRInt32 osfd);
|
||||
NSPR_API(PRInt32) _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount);
|
||||
|
|
|
@ -438,6 +438,8 @@ extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level, PRInt32 optname, c
|
|||
#define _MD_INIT_FILEDESC _MD_initfiledesc
|
||||
#define _MD_FREE_FILEDESC _MD_freefiledesc
|
||||
#define _MD_MAKE_NONBLOCK _MD_makenonblock
|
||||
#define _MD_INIT_FD_INHERITABLE _MD_initfdinheritable
|
||||
#define _MD_QUERY_FD_INHERITABLE _MD_queryfdinheritable
|
||||
|
||||
#define _MD_GET_SOCKET_ERROR() _PR_MD_CURRENT_THREAD()->md.osErrCode
|
||||
|
||||
|
|
|
@ -256,6 +256,8 @@ extern PRInt32 _MD_CloseFile(PRInt32 osfd);
|
|||
#define _MD_INIT_FILEDESC(fd)
|
||||
extern void _MD_MakeNonblock(PRFileDesc *f);
|
||||
#define _MD_MAKE_NONBLOCK _MD_MakeNonblock
|
||||
#define _MD_INIT_FD_INHERITABLE (_PR_MD_INIT_FD_INHERITABLE)
|
||||
#define _MD_QUERY_FD_INHERITABLE (_PR_MD_QUERY_FD_INHERITABLE)
|
||||
#define _MD_SHUTDOWN (_PR_MD_SHUTDOWN)
|
||||
#define _MD_LISTEN(s, backlog) listen(s->secret->md.osfd,backlog)
|
||||
extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
|
||||
|
|
|
@ -287,8 +287,7 @@ extern void _MD_Wakeup_CPUs(void);
|
|||
|
||||
/************************************************************************/
|
||||
|
||||
extern void _MD_InitFileDesc(PRFileDesc *fd);
|
||||
#define _MD_INIT_FILEDESC _MD_InitFileDesc
|
||||
#define _MD_INIT_FILEDESC(fd)
|
||||
|
||||
extern void _MD_MakeNonblock(PRFileDesc *fd);
|
||||
#define _MD_MAKE_NONBLOCK _MD_MakeNonblock
|
||||
|
@ -459,6 +458,12 @@ extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
|
|||
extern PRStatus _MD_set_fd_inheritable(PRFileDesc *fd, PRBool inheritable);
|
||||
#define _MD_SET_FD_INHERITABLE _MD_set_fd_inheritable
|
||||
|
||||
extern void _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported);
|
||||
#define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable
|
||||
|
||||
extern void _MD_query_fd_inheritable(PRFileDesc *fd);
|
||||
#define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable
|
||||
|
||||
extern PRStatus _MD_gethostname(char *name, PRUint32 namelen);
|
||||
#define _MD_GETHOSTNAME _MD_gethostname
|
||||
|
||||
|
|
|
@ -240,6 +240,8 @@ extern PRInt32 _MD_CloseFile(PRInt32 osfd);
|
|||
#define _MD_INIT_FILEDESC(fd)
|
||||
extern void _MD_MakeNonblock(PRFileDesc *f);
|
||||
#define _MD_MAKE_NONBLOCK _MD_MakeNonblock
|
||||
#define _MD_INIT_FD_INHERITABLE _PR_MD_INIT_FD_INHERITABLE
|
||||
#define _MD_QUERY_FD_INHERITABLE _PR_MD_QUERY_FD_INHERITABLE
|
||||
#define _MD_SHUTDOWN _PR_MD_SHUTDOWN
|
||||
#define _MD_LISTEN(s, backlog) listen(s->secret->md.osfd,backlog)
|
||||
extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
|
||||
|
|
|
@ -267,6 +267,8 @@ extern PRInt32 _PR_MD_CLOSE(PRInt32 osfd, PRBool socket);
|
|||
|
||||
#define _MD_INIT_FILEDESC(fd)
|
||||
#define _MD_MAKE_NONBLOCK _PR_MD_MAKE_NONBLOCK
|
||||
#define _MD_INIT_FD_INHERITABLE _PR_MD_INIT_FD_INHERITABLE
|
||||
#define _MD_QUERY_FD_INHERITABLE _PR_MD_QUERY_FD_INHERITABLE
|
||||
#define _MD_SHUTDOWN _PR_MD_SHUTDOWN
|
||||
#define _MD_LISTEN _PR_MD_LISTEN
|
||||
#define _MD_CLOSE_SOCKET(s) _PR_MD_CLOSE(s, PR_TRUE)
|
||||
|
|
|
@ -1234,6 +1234,21 @@ extern PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds,
|
|||
PRIntervalTime timeout);
|
||||
#define _PR_MD_PR_POLL _MD_PR_POLL
|
||||
|
||||
/*
|
||||
* Initialize fd->secret->inheritable for a newly created fd.
|
||||
* If 'imported' is false, the osfd (i.e., fd->secret->md.osfd)
|
||||
* was created by NSPR and hence has the OS-dependent default
|
||||
* inheritable attribute. If 'imported' is true, the osfd was
|
||||
* not created by NSPR and hence a system call is required to
|
||||
* query its inheritable attribute. Since we may never need to
|
||||
* know the inheritable attribute of a fd, a platform may choose
|
||||
* to initialize fd->secret->inheritable of an imported fd to
|
||||
* _PR_TRI_UNKNOWN and only pay the cost of the system call
|
||||
* (in _PR_MD_QUERY_FD_INHERITABLE) when necessary.
|
||||
*/
|
||||
extern void _PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported);
|
||||
#define _PR_MD_INIT_FD_INHERITABLE _MD_INIT_FD_INHERITABLE
|
||||
|
||||
extern PRStatus _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable);
|
||||
#define _PR_MD_SET_FD_INHERITABLE _MD_SET_FD_INHERITABLE
|
||||
|
||||
|
@ -1658,10 +1673,20 @@ struct PRFileMap {
|
|||
#define _PR_FILEDESC_CLOSED 0x55555555 /* 0101010... */
|
||||
#define _PR_FILEDESC_FREED 0x11111111
|
||||
|
||||
/*
|
||||
** A boolean type with an additional "unknown" state
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
_PR_TRI_TRUE = 1,
|
||||
_PR_TRI_FALSE = 0,
|
||||
_PR_TRI_UNKNOWN = -1
|
||||
} _PRTriStateBool;
|
||||
|
||||
struct PRFilePrivate {
|
||||
PRInt32 state;
|
||||
PRBool nonblocking;
|
||||
PRBool inheritable;
|
||||
_PRTriStateBool inheritable;
|
||||
PRFileDesc *next;
|
||||
PRIntn lockCount;
|
||||
#ifdef _PR_HAVE_PEEK_BUFFER
|
||||
|
@ -1977,6 +2002,16 @@ extern PRStatus _PR_MD_GETHOSTNAME(char *name, PRUint32 namelen);
|
|||
extern PRStatus _PR_MD_GETSYSINFO(PRSysInfo cmd, char *name, PRUint32 namelen);
|
||||
#define _PR_MD_GETSYSINFO _MD_GETSYSINFO
|
||||
|
||||
/* File descriptor inheritance */
|
||||
|
||||
/*
|
||||
* If fd->secret->inheritable is _PR_TRI_UNKNOWN and we need to
|
||||
* know the inheritable attribute of the fd, call this function
|
||||
* to find that out. This typically requires a system call.
|
||||
*/
|
||||
extern void _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd);
|
||||
#define _PR_MD_QUERY_FD_INHERITABLE _MD_QUERY_FD_INHERITABLE
|
||||
|
||||
/* --- PR_GetRandomNoise() related things --- */
|
||||
|
||||
extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size );
|
||||
|
|
|
@ -359,6 +359,8 @@ PR_IMPLEMENT(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode)
|
|||
fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
|
||||
if (!fd) {
|
||||
(void) _PR_MD_CLOSE_FILE(osfd);
|
||||
} else {
|
||||
_PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
|
@ -379,6 +381,8 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
|
|||
fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
|
||||
if (!fd) {
|
||||
(void) _PR_MD_CLOSE_FILE(osfd);
|
||||
} else {
|
||||
_PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
|
@ -525,6 +529,8 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PRInt32 osfd)
|
|||
fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
|
||||
if( !fd ) {
|
||||
(void) _PR_MD_CLOSE_FILE(osfd);
|
||||
} else {
|
||||
_PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
|
||||
}
|
||||
|
||||
return fd;
|
||||
|
@ -542,6 +548,8 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PRInt32 osfd)
|
|||
fd = PR_AllocFileDesc(osfd, &_pr_pipeMethods);
|
||||
if( !fd ) {
|
||||
(void) _PR_MD_CLOSE_FILE(osfd);
|
||||
} else {
|
||||
_PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
|
||||
}
|
||||
|
||||
return fd;
|
||||
|
@ -695,8 +703,8 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
|
|||
(*readPipe)->secret->md.sync_file_io = PR_TRUE;
|
||||
(*writePipe)->secret->md.sync_file_io = PR_TRUE;
|
||||
#endif
|
||||
(*readPipe)->secret->inheritable = PR_TRUE;
|
||||
(*writePipe)->secret->inheritable = PR_TRUE;
|
||||
(*readPipe)->secret->inheritable = _PR_TRI_TRUE;
|
||||
(*writePipe)->secret->inheritable = _PR_TRI_TRUE;
|
||||
return PR_SUCCESS;
|
||||
#elif defined(XP_UNIX) || defined(XP_OS2)
|
||||
#ifdef XP_OS2
|
||||
|
@ -729,7 +737,9 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
|
|||
return PR_FAILURE;
|
||||
}
|
||||
_MD_MakeNonblock(*readPipe);
|
||||
_PR_MD_INIT_FD_INHERITABLE(*readPipe, PR_FALSE);
|
||||
_MD_MakeNonblock(*writePipe);
|
||||
_PR_MD_INIT_FD_INHERITABLE(*writePipe, PR_FALSE);
|
||||
return PR_SUCCESS;
|
||||
#else
|
||||
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
|
||||
|
|
|
@ -66,6 +66,9 @@ void _PR_InitIO(void)
|
|||
_pr_stdout = PR_AllocFileDesc(1, methods);
|
||||
_pr_stderr = PR_AllocFileDesc(2, methods);
|
||||
#endif
|
||||
_PR_MD_INIT_FD_INHERITABLE(_pr_stdin, PR_TRUE);
|
||||
_PR_MD_INIT_FD_INHERITABLE(_pr_stdout, PR_TRUE);
|
||||
_PR_MD_INIT_FD_INHERITABLE(_pr_stderr, PR_TRUE);
|
||||
|
||||
_PR_MD_INIT_IO();
|
||||
}
|
||||
|
|
|
@ -183,9 +183,10 @@ PRFileDesc *fd;
|
|||
|
||||
if (!_pr_initialized) _PR_ImplicitInitialization();
|
||||
fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
|
||||
if (fd != NULL)
|
||||
if (fd != NULL) {
|
||||
_PR_MD_MAKE_NONBLOCK(fd);
|
||||
else
|
||||
_PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
|
||||
} else
|
||||
_PR_MD_CLOSE_SOCKET(osfd);
|
||||
return(fd);
|
||||
}
|
||||
|
@ -196,9 +197,10 @@ PRFileDesc *fd;
|
|||
|
||||
if (!_pr_initialized) _PR_ImplicitInitialization();
|
||||
fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
|
||||
if (fd != NULL)
|
||||
if (fd != NULL) {
|
||||
_PR_MD_MAKE_NONBLOCK(fd);
|
||||
else
|
||||
_PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
|
||||
} else
|
||||
_PR_MD_CLOSE_SOCKET(osfd);
|
||||
return(fd);
|
||||
}
|
||||
|
@ -218,7 +220,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_CreateSocketPollFd(PRInt32 osfd)
|
|||
else
|
||||
{
|
||||
fd->secret->md.osfd = osfd;
|
||||
fd->secret->inheritable = PR_FALSE;
|
||||
fd->secret->inheritable = _PR_TRI_FALSE;
|
||||
fd->secret->state = _PR_FILEDESC_OPEN;
|
||||
fd->methods = PR_GetSocketPollFdMethods();
|
||||
}
|
||||
|
@ -420,6 +422,7 @@ PRIntervalTime timeout)
|
|||
fd2->secret->nonblocking = fd->secret->nonblocking;
|
||||
fd2->secret->inheritable = fd->secret->inheritable;
|
||||
#ifdef WINNT
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd2->secret->inheritable);
|
||||
if (!fd2->secret->nonblocking && !fd2->secret->inheritable) {
|
||||
/*
|
||||
* The new socket has been associated with an I/O
|
||||
|
@ -1297,6 +1300,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
|
|||
*/
|
||||
if (fd != NULL) {
|
||||
_PR_MD_MAKE_NONBLOCK(fd);
|
||||
_PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
|
||||
#if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)
|
||||
/*
|
||||
* For platforms with no support for IPv6
|
||||
|
@ -1366,7 +1370,9 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[])
|
|||
return PR_FAILURE;
|
||||
}
|
||||
_PR_MD_MAKE_NONBLOCK(f[0]);
|
||||
_PR_MD_INIT_FD_INHERITABLE(f[0], PR_FALSE);
|
||||
_PR_MD_MAKE_NONBLOCK(f[1]);
|
||||
_PR_MD_INIT_FD_INHERITABLE(f[1], PR_FALSE);
|
||||
return PR_SUCCESS;
|
||||
#elif defined(WINNT)
|
||||
/*
|
||||
|
@ -1445,6 +1451,8 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[])
|
|||
/* PR_AllocFileDesc() has invoked PR_SetError(). */
|
||||
return PR_FAILURE;
|
||||
}
|
||||
_PR_MD_INIT_FD_INHERITABLE(f[0], PR_FALSE);
|
||||
_PR_MD_INIT_FD_INHERITABLE(f[1], PR_FALSE);
|
||||
return PR_SUCCESS;
|
||||
|
||||
failed:
|
||||
|
|
|
@ -118,6 +118,20 @@ _MD_make_nonblock (PRFileDesc *fd)
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
_MD_init_fd_inheritable (PRFileDesc *fd, PRBool imported)
|
||||
{
|
||||
/* XXX this function needs to be implemented */
|
||||
fd->secret->inheritable = _PR_TRI_UNKNOWN;
|
||||
}
|
||||
|
||||
void
|
||||
_MD_query_fd_inheritable (PRFileDesc *fd)
|
||||
{
|
||||
/* XXX this function needs to be implemented */
|
||||
PR_ASSERT(0);
|
||||
}
|
||||
|
||||
PRInt32
|
||||
_MD_open (const char *name, PRIntn flags, PRIntn mode)
|
||||
{
|
||||
|
|
|
@ -1816,6 +1816,20 @@ void _MD_makenonblock(PRFileDesc *fd)
|
|||
}
|
||||
|
||||
|
||||
void _MD_initfdinheritable(PRFileDesc *fd, PRBool imported)
|
||||
{
|
||||
/* XXX this function needs to be implemented */
|
||||
fd->secret->inheritable = _PR_TRI_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
void _MD_queryfdinheritable(PRFileDesc *fd)
|
||||
{
|
||||
/* XXX this function needs to be implemented */
|
||||
PR_ASSERT(0);
|
||||
}
|
||||
|
||||
|
||||
PR_IMPLEMENT(PRInt32) _MD_shutdown(PRFileDesc *fd, PRIntn how)
|
||||
{
|
||||
#pragma unused (fd, how)
|
||||
|
|
|
@ -774,3 +774,25 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
|
|||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
|
||||
{
|
||||
/* XXX this function needs to be implemented */
|
||||
fd->secret->inheritable = _PR_TRI_UNKNOWN;
|
||||
}
|
||||
|
||||
void
|
||||
_PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd)
|
||||
{
|
||||
/* XXX this function needs to be reviewed */
|
||||
ULONG flags;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);
|
||||
if (DosQueryFHState((HFILE)fd->secret->md.osfd, &flags) == 0) {
|
||||
if (flags & OPEN_FLAGS_NOINHERIT) {
|
||||
fd->secret->inheritable = _PR_TRI_FALSE;
|
||||
} else {
|
||||
fd->secret->inheritable = _PR_TRI_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1314,6 +1314,22 @@ PRStatus _MD_set_fd_inheritable(PRFileDesc *fd, PRBool inheritable)
|
|||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
void _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported)
|
||||
{
|
||||
if (imported) {
|
||||
fd->secret->inheritable = _PR_TRI_UNKNOWN;
|
||||
} else {
|
||||
/* By default, a Unix fd is not closed on exec. */
|
||||
#ifdef DEBUG
|
||||
{
|
||||
int flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
|
||||
PR_ASSERT(0 == flags);
|
||||
}
|
||||
#endif
|
||||
fd->secret->inheritable = _PR_TRI_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
#if !defined(_PR_USE_POLL)
|
||||
|
||||
|
@ -2157,26 +2173,6 @@ void _MD_UnblockClockInterrupts()
|
|||
sigprocmask(SIG_UNBLOCK, &timer_set, 0);
|
||||
}
|
||||
|
||||
void _MD_InitFileDesc(PRFileDesc *fd)
|
||||
{
|
||||
/* By default, a Unix fd is not closed on exec. */
|
||||
#ifdef DEBUG
|
||||
{
|
||||
int flags;
|
||||
|
||||
/*
|
||||
* Ignore EBADF error on fd's 0, 1, 2 because they are
|
||||
* not open in all processes.
|
||||
*/
|
||||
flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
|
||||
PR_ASSERT((0 == flags) || (-1 == flags
|
||||
&& (0 <= fd->secret->md.osfd && fd->secret->md.osfd <= 2)
|
||||
&& errno == EBADF));
|
||||
}
|
||||
#endif
|
||||
fd->secret->inheritable = PR_TRUE;
|
||||
}
|
||||
|
||||
void _MD_MakeNonblock(PRFileDesc *fd)
|
||||
{
|
||||
PRInt32 osfd = fd->secret->md.osfd;
|
||||
|
@ -2277,6 +2273,17 @@ static void sigbushandler() {
|
|||
|
||||
#endif /* !defined(_PR_PTHREADS) */
|
||||
|
||||
void _MD_query_fd_inheritable(PRFileDesc *fd)
|
||||
{
|
||||
int flags;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);
|
||||
flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
|
||||
PR_ASSERT(-1 != flags);
|
||||
fd->secret->inheritable = (flags & FD_CLOEXEC) ?
|
||||
_PR_TRI_FALSE : _PR_TRI_TRUE;
|
||||
}
|
||||
|
||||
PROffset32 _MD_lseek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence)
|
||||
{
|
||||
PROffset32 rv, where;
|
||||
|
|
|
@ -1260,6 +1260,7 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
|
|||
PRUint32 llen, err;
|
||||
int rv;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
|
||||
if (fd->secret->nonblocking || fd->secret->inheritable) {
|
||||
if (!fd->secret->md.io_model_committed) {
|
||||
rv = _md_MakeNonblock((HANDLE)osfd);
|
||||
|
@ -1677,6 +1678,7 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
|
|||
int bytes;
|
||||
int rv, err;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
|
||||
if (fd->secret->nonblocking || fd->secret->inheritable) {
|
||||
if (!fd->secret->md.io_model_committed) {
|
||||
rv = _md_MakeNonblock((HANDLE)osfd);
|
||||
|
@ -1776,6 +1778,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
|
|||
int bytes;
|
||||
int rv, err;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
|
||||
if (fd->secret->nonblocking || fd->secret->inheritable) {
|
||||
if (!fd->secret->md.io_model_committed) {
|
||||
rv = _md_MakeNonblock((HANDLE)osfd);
|
||||
|
@ -1874,6 +1877,7 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
|
|||
PR_ASSERT(0 != rv);
|
||||
fd->secret->md.io_model_committed = PR_TRUE;
|
||||
}
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
|
||||
if (!fd->secret->nonblocking && !fd->secret->inheritable)
|
||||
return pt_SendTo(osfd, buf, amount, flags, addr, addrlen, timeout);
|
||||
else
|
||||
|
@ -1892,6 +1896,7 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
|
|||
PR_ASSERT(0 != rv);
|
||||
fd->secret->md.io_model_committed = PR_TRUE;
|
||||
}
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
|
||||
if (!fd->secret->nonblocking && !fd->secret->inheritable)
|
||||
return pt_RecvFrom(osfd, buf, amount, flags, addr, addrlen, timeout);
|
||||
else
|
||||
|
@ -1907,6 +1912,7 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
|
|||
int sent = 0;
|
||||
int rv;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
|
||||
if (fd->secret->nonblocking || fd->secret->inheritable) {
|
||||
if (!fd->secret->md.io_model_committed) {
|
||||
rv = _md_MakeNonblock((HANDLE)osfd);
|
||||
|
@ -2164,6 +2170,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
|
|||
LONG hiOffset = 0;
|
||||
LONG loOffset;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
|
||||
if (!fd->secret->md.sync_file_io) {
|
||||
PRThread *me = _PR_MD_CURRENT_THREAD();
|
||||
|
||||
|
@ -2315,6 +2322,7 @@ _PR_MD_WRITE(PRFileDesc *fd, void *buf, PRInt32 len)
|
|||
LONG hiOffset = 0;
|
||||
LONG loOffset;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
|
||||
if (!fd->secret->md.sync_file_io) {
|
||||
PRThread *me = _PR_MD_CURRENT_THREAD();
|
||||
|
||||
|
@ -2637,6 +2645,40 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
|
|||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
|
||||
{
|
||||
DWORD flags;
|
||||
|
||||
/*
|
||||
* On NT, fd->secret->inheritable is used to decide whether
|
||||
* we can associate the file handle with the I/O completion
|
||||
* port, so we must not set it to _PR_TRI_UNKNOWN.
|
||||
*/
|
||||
fd->secret->inheritable = _PR_TRI_FALSE;
|
||||
if (imported) {
|
||||
if (GetHandleInformation((HANDLE)fd->secret->md.osfd, &flags)) {
|
||||
if (flags & HANDLE_FLAG_INHERIT) {
|
||||
fd->secret->inheritable = _PR_TRI_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd)
|
||||
{
|
||||
DWORD flags;
|
||||
|
||||
if (GetHandleInformation((HANDLE)fd->secret->md.osfd, &flags)) {
|
||||
if (flags & HANDLE_FLAG_INHERIT) {
|
||||
fd->secret->inheritable = _PR_TRI_TRUE;
|
||||
} else {
|
||||
fd->secret->inheritable = _PR_TRI_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* --- DIR IO ------------------------------------------------------------ */
|
||||
#define GetFileFromDIR(d) (d)->d_entry.cFileName
|
||||
|
|
|
@ -921,6 +921,31 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
|
|||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
|
||||
{
|
||||
if (imported) {
|
||||
fd->secret->inheritable = _PR_TRI_UNKNOWN;
|
||||
} else {
|
||||
fd->secret->inheritable = _PR_TRI_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd)
|
||||
{
|
||||
DWORD flags;
|
||||
|
||||
PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);
|
||||
if (GetHandleInformation((HANDLE)fd->secret->md.osfd, &flags)) {
|
||||
if (flags & HANDLE_FLAG_INHERIT) {
|
||||
fd->secret->inheritable = _PR_TRI_TRUE;
|
||||
} else {
|
||||
fd->secret->inheritable = _PR_TRI_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32
|
||||
_PR_MD_RENAME(const char *from, const char *to)
|
||||
{
|
||||
|
|
|
@ -595,7 +595,10 @@ PR_ProcessAttrSetInheritableFD(
|
|||
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
if (!fd->secret->inheritable) {
|
||||
if (fd->secret->inheritable == _PR_TRI_UNKNOWN) {
|
||||
_PR_MD_QUERY_FD_INHERITABLE(fd);
|
||||
}
|
||||
if (fd->secret->inheritable != _PR_TRI_TRUE) {
|
||||
PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, 0);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
@ -692,7 +695,7 @@ PR_IMPLEMENT(PRFileDesc *) PR_GetInheritedFD(
|
|||
* The child process needs to call PR_SetFDInheritable
|
||||
* to make it non-inheritable if so desired.
|
||||
*/
|
||||
fd->secret->inheritable = PR_TRUE;
|
||||
fd->secret->inheritable = _PR_TRI_TRUE;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ static ssize_t (*pt_aix_sendfile_fptr)() = NULL;
|
|||
#endif
|
||||
|
||||
static PRFileDesc *pt_SetMethods(
|
||||
PRIntn osfd, PRDescType type, PRBool isAcceptedSocket);
|
||||
PRIntn osfd, PRDescType type, PRBool isAcceptedSocket, PRBool imported);
|
||||
|
||||
static PRLock *_pr_flock_lock; /* For PR_LockFile() etc. */
|
||||
static PRLock *_pr_rename_lock; /* For PR_Rename() */
|
||||
|
@ -967,9 +967,9 @@ void _PR_InitIO()
|
|||
|
||||
_PR_InitFdCache(); /* do that */
|
||||
|
||||
_pr_stdin = pt_SetMethods(0, PR_DESC_FILE, PR_FALSE);
|
||||
_pr_stdout = pt_SetMethods(1, PR_DESC_FILE, PR_FALSE);
|
||||
_pr_stderr = pt_SetMethods(2, PR_DESC_FILE, PR_FALSE);
|
||||
_pr_stdin = pt_SetMethods(0, PR_DESC_FILE, PR_FALSE, PR_TRUE);
|
||||
_pr_stdout = pt_SetMethods(1, PR_DESC_FILE, PR_FALSE, PR_TRUE);
|
||||
_pr_stderr = pt_SetMethods(2, PR_DESC_FILE, PR_FALSE, PR_TRUE);
|
||||
PR_ASSERT(_pr_stdin && _pr_stdout && _pr_stderr);
|
||||
|
||||
} /* _PR_InitIO */
|
||||
|
@ -1452,7 +1452,7 @@ static PRFileDesc* pt_Accept(
|
|||
if (addr && (AF_INET6 == addr->raw.family))
|
||||
addr->raw.family = PR_AF_INET6;
|
||||
#endif
|
||||
newfd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_TRUE);
|
||||
newfd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_TRUE, PR_FALSE);
|
||||
if (newfd == NULL) close(osfd); /* $$$ whoops! this doesn't work $$$ */
|
||||
else
|
||||
{
|
||||
|
@ -2690,22 +2690,8 @@ static void pt_MakeSocketNonblock(PRIntn osfd)
|
|||
#define pt_MakeSocketNonblock pt_MakeFdNonblock
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
static void pt_AssertCloseOnExecIsCleared(PRIntn osfd)
|
||||
{
|
||||
/*
|
||||
* Ignore EBADF error on fd's 0, 1, 2 because they are
|
||||
* not open in all processes.
|
||||
*/
|
||||
PRIntn flags;
|
||||
flags = fcntl(osfd, F_GETFD, 0);
|
||||
PR_ASSERT((0 == flags) || (-1 == flags
|
||||
&& (0 <= osfd && osfd <= 2) && errno == EBADF));
|
||||
}
|
||||
#endif
|
||||
|
||||
static PRFileDesc *pt_SetMethods(
|
||||
PRIntn osfd, PRDescType type, PRBool isAcceptedSocket)
|
||||
PRIntn osfd, PRDescType type, PRBool isAcceptedSocket, PRBool imported)
|
||||
{
|
||||
PRFileDesc *fd = _PR_Getfd();
|
||||
|
||||
|
@ -2714,11 +2700,17 @@ static PRFileDesc *pt_SetMethods(
|
|||
{
|
||||
fd->secret->md.osfd = osfd;
|
||||
fd->secret->state = _PR_FILEDESC_OPEN;
|
||||
/* By default, a Unix fd is not closed on exec. */
|
||||
if (imported) fd->secret->inheritable = _PR_TRI_UNKNOWN;
|
||||
else
|
||||
{
|
||||
/* By default, a Unix fd is not closed on exec. */
|
||||
#ifdef DEBUG
|
||||
pt_AssertCloseOnExecIsCleared(osfd);
|
||||
PRIntn flags;
|
||||
flags = fcntl(osfd, F_GETFD, 0);
|
||||
PR_ASSERT(0 == flags);
|
||||
#endif
|
||||
fd->secret->inheritable = PR_TRUE;
|
||||
fd->secret->inheritable = _PR_TRI_TRUE;
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case PR_DESC_FILE:
|
||||
|
@ -2794,11 +2786,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDesc(
|
|||
else pt_MakeFdNonblock(osfd);
|
||||
}
|
||||
fd->secret->state = _PR_FILEDESC_OPEN;
|
||||
/* By default, a Unix fd is not closed on exec. */
|
||||
#ifdef DEBUG
|
||||
pt_AssertCloseOnExecIsCleared(osfd);
|
||||
#endif
|
||||
fd->secret->inheritable = PR_TRUE;
|
||||
fd->secret->inheritable = _PR_TRI_UNKNOWN;
|
||||
return fd;
|
||||
|
||||
failed:
|
||||
|
@ -2868,7 +2856,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
|
|||
if (osfd == -1) pt_MapError(_PR_MD_MAP_SOCKET_ERROR, errno);
|
||||
else
|
||||
{
|
||||
fd = pt_SetMethods(osfd, ftype, PR_FALSE);
|
||||
fd = pt_SetMethods(osfd, ftype, PR_FALSE, PR_FALSE);
|
||||
if (fd == NULL) close(osfd);
|
||||
}
|
||||
#if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)
|
||||
|
@ -2941,7 +2929,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
|
|||
pt_MapError(_PR_MD_MAP_OPEN_ERROR, syserrno);
|
||||
else
|
||||
{
|
||||
fd = pt_SetMethods(osfd, PR_DESC_FILE, PR_FALSE);
|
||||
fd = pt_SetMethods(osfd, PR_DESC_FILE, PR_FALSE, PR_FALSE);
|
||||
if (fd == NULL) close(osfd); /* $$$ whoops! this is bad $$$ */
|
||||
}
|
||||
return fd;
|
||||
|
@ -3717,13 +3705,13 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2])
|
|||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
fds[0] = pt_SetMethods(osfd[0], PR_DESC_SOCKET_TCP, PR_FALSE);
|
||||
fds[0] = pt_SetMethods(osfd[0], PR_DESC_SOCKET_TCP, PR_FALSE, PR_FALSE);
|
||||
if (fds[0] == NULL) {
|
||||
close(osfd[0]);
|
||||
close(osfd[1]);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
fds[1] = pt_SetMethods(osfd[1], PR_DESC_SOCKET_TCP, PR_FALSE);
|
||||
fds[1] = pt_SetMethods(osfd[1], PR_DESC_SOCKET_TCP, PR_FALSE, PR_FALSE);
|
||||
if (fds[1] == NULL) {
|
||||
PR_Close(fds[0]);
|
||||
close(osfd[1]);
|
||||
|
@ -3747,14 +3735,14 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
|
|||
PR_SetError(PR_UNKNOWN_ERROR, errno);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
*readPipe = pt_SetMethods(pipefd[0], PR_DESC_PIPE, PR_FALSE);
|
||||
*readPipe = pt_SetMethods(pipefd[0], PR_DESC_PIPE, PR_FALSE, PR_FALSE);
|
||||
if (NULL == *readPipe)
|
||||
{
|
||||
close(pipefd[0]);
|
||||
close(pipefd[1]);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
*writePipe = pt_SetMethods(pipefd[1], PR_DESC_PIPE, PR_FALSE);
|
||||
*writePipe = pt_SetMethods(pipefd[1], PR_DESC_PIPE, PR_FALSE, PR_FALSE);
|
||||
if (NULL == *writePipe)
|
||||
{
|
||||
PR_Close(*readPipe);
|
||||
|
@ -3801,7 +3789,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PRInt32 osfd)
|
|||
PRFileDesc *fd;
|
||||
|
||||
if (!_pr_initialized) _PR_ImplicitInitialization();
|
||||
fd = pt_SetMethods(osfd, PR_DESC_FILE, PR_FALSE);
|
||||
fd = pt_SetMethods(osfd, PR_DESC_FILE, PR_FALSE, PR_TRUE);
|
||||
if (NULL == fd) close(osfd);
|
||||
return fd;
|
||||
} /* PR_ImportFile */
|
||||
|
@ -3811,7 +3799,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PRInt32 osfd)
|
|||
PRFileDesc *fd;
|
||||
|
||||
if (!_pr_initialized) _PR_ImplicitInitialization();
|
||||
fd = pt_SetMethods(osfd, PR_DESC_PIPE, PR_FALSE);
|
||||
fd = pt_SetMethods(osfd, PR_DESC_PIPE, PR_FALSE, PR_TRUE);
|
||||
if (NULL == fd) close(osfd);
|
||||
return fd;
|
||||
} /* PR_ImportPipe */
|
||||
|
@ -3821,7 +3809,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd)
|
|||
PRFileDesc *fd;
|
||||
|
||||
if (!_pr_initialized) _PR_ImplicitInitialization();
|
||||
fd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_FALSE);
|
||||
fd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_FALSE, PR_TRUE);
|
||||
if (NULL == fd) close(osfd);
|
||||
return fd;
|
||||
} /* PR_ImportTCPSocket */
|
||||
|
@ -3831,7 +3819,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportUDPSocket(PRInt32 osfd)
|
|||
PRFileDesc *fd;
|
||||
|
||||
if (!_pr_initialized) _PR_ImplicitInitialization();
|
||||
fd = pt_SetMethods(osfd, PR_DESC_SOCKET_UDP, PR_FALSE);
|
||||
fd = pt_SetMethods(osfd, PR_DESC_SOCKET_UDP, PR_FALSE, PR_TRUE);
|
||||
if (NULL != fd) close(osfd);
|
||||
return fd;
|
||||
} /* PR_ImportUDPSocket */
|
||||
|
@ -3848,7 +3836,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_CreateSocketPollFd(PRInt32 osfd)
|
|||
else
|
||||
{
|
||||
fd->secret->md.osfd = osfd;
|
||||
fd->secret->inheritable = PR_FALSE;
|
||||
fd->secret->inheritable = _PR_TRI_FALSE;
|
||||
fd->secret->state = _PR_FILEDESC_OPEN;
|
||||
fd->methods = PR_GetSocketPollFdMethods();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче