diff options
author | seawood%netscape.com <devnull@localhost> | 2002-02-10 20:55:14 +0000 |
---|---|---|
committer | seawood%netscape.com <devnull@localhost> | 2002-02-10 20:55:14 +0000 |
commit | fcaeee14591603e2efd3fafb6de24773307ec541 (patch) | |
tree | 4c3bd3465cbaf1cf2f9ddda775e305cfa575a65d | |
parent | f9c8afe364cbb82573450a20da11258a351ec6b0 (diff) | |
download | nspr-hg-fcaeee14591603e2efd3fafb6de24773307ec541.tar.gz |
Add support for inheritable fds on BeOS.
Bug #96331 r=arougthopher@lizardland.net
-rw-r--r-- | pr/include/md/_beos.h | 1 | ||||
-rw-r--r-- | pr/src/io/prio.c | 2 | ||||
-rw-r--r-- | pr/src/md/beos/bfile.c | 35 |
3 files changed, 33 insertions, 5 deletions
diff --git a/pr/include/md/_beos.h b/pr/include/md/_beos.h index 391c9720..b746f75b 100644 --- a/pr/include/md/_beos.h +++ b/pr/include/md/_beos.h @@ -312,6 +312,7 @@ 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_SET_FD_INHERITABLE _MD_set_fd_inheritable #define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable #define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable #define _MD_OPEN _MD_open diff --git a/pr/src/io/prio.c b/pr/src/io/prio.c index ce5c021b..74336d1e 100644 --- a/pr/src/io/prio.c +++ b/pr/src/io/prio.c @@ -143,7 +143,7 @@ PR_IMPLEMENT(PRStatus) PR_SetFDInheritable( PRFileDesc *fd, PRBool inheritable) { -#if defined(XP_UNIX) || defined(WIN32) || defined(XP_OS2) +#if defined(XP_UNIX) || defined(WIN32) || defined(XP_OS2) || defined(XP_BEOS) /* * Only a non-layered, NSPR file descriptor can be inherited * by a child process. diff --git a/pr/src/md/beos/bfile.c b/pr/src/md/beos/bfile.c index e42c63db..2b03652f 100644 --- a/pr/src/md/beos/bfile.c +++ b/pr/src/md/beos/bfile.c @@ -118,18 +118,45 @@ _MD_make_nonblock (PRFileDesc *fd) } +PRStatus +_MD_set_fd_inheritable (PRFileDesc *fd, PRBool inheritable) +{ + int rv; + + rv = fcntl(fd->secret->md.osfd, F_SETFD, inheritable ? 0 : FD_CLOEXEC); + if (-1 == rv) { + PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO()); + return PR_FAILURE; + } + return PR_SUCCESS; +} + void _MD_init_fd_inheritable (PRFileDesc *fd, PRBool imported) { - /* XXX this function needs to be implemented */ - fd->secret->inheritable = _PR_TRI_UNKNOWN; + if (imported) { + fd->secret->inheritable = _PR_TRI_UNKNOWN; + } else { + int flags = fcntl(fd->secret->md.osfd, F_GETFD, 0); + if (flags == -1) { + PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO()); + return; + } + fd->secret->inheritable = (flags & FD_CLOEXEC) ? + _PR_TRI_TRUE : _PR_TRI_FALSE; + } } void _MD_query_fd_inheritable (PRFileDesc *fd) { - /* XXX this function needs to be implemented */ - PR_ASSERT(0); + 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; } PRInt32 |