Add support for inheritable fds on BeOS.
authorseawood%netscape.com
Sun, 10 Feb 2002 20:54:55 +0000
changeset 2242 85877fd6dba8da0a49b7cc904d162f271ffdfe45
parent 2240 c254c2b35a90035a38cd88921f807221c7144a41
child 2244 b06bc2369074710e0bb648ece4a2f02ea9cdfe76
push idunknown
push userunknown
push dateunknown
bugs96331
Add support for inheritable fds on BeOS. Bug #96331 r=arougthopher@lizardland.net
pr/include/md/_beos.h
pr/src/io/prio.c
pr/src/md/beos/bfile.c
--- a/pr/include/md/_beos.h
+++ b/pr/include/md/_beos.h
@@ -307,16 +307,17 @@ struct protoent* getprotobynumber(int nu
 /* don't need any I/O initializations */
 #define _MD_INIT_IO()
 #define _MD_INIT_FILEDESC(fd)
 
 #define _MD_OPEN_DIR _MD_open_dir
 #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
 #define _MD_OPEN_FILE _MD_open
 #define _MD_CLOSE_FILE _MD_close_file
 #define _MD_READ _MD_read
 #define _MD_WRITE _MD_write
 #define _MD_WRITEV _MD_writev
--- a/pr/src/io/prio.c
+++ b/pr/src/io/prio.c
@@ -159,17 +159,17 @@ PR_IMPLEMENT(PRInt32) PR_Poll(PRPollDesc
 
 /*
 ** Set the inheritance attribute of a file descriptor.
 */
 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.
      */
     if (fd->identity != PR_NSPR_IO_LAYER) {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return PR_FAILURE;
     }
--- a/pr/src/md/beos/bfile.c
+++ b/pr/src/md/beos/bfile.c
@@ -113,28 +113,55 @@ int rv = 0, err;
 void
 _MD_make_nonblock (PRFileDesc *fd)
 {
 	int blocking = 1;
 	setsockopt(fd->secret->md.osfd, SOL_SOCKET, SO_NONBLOCK, &blocking, sizeof(blocking));
 
 }
 
+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
 _MD_open (const char *name, PRIntn flags, PRIntn mode)
 {
 	PRInt32 osflags;
 	PRInt32 rv, err;