]> jfr.im git - irc/freenode/solanum.git/commitdiff
librb: add rb_{set,clear}_cloexec
authorDoug Freed <redacted>
Sun, 13 Dec 2020 08:38:25 +0000 (08:38 +0000)
committerDoug Freed <redacted>
Tue, 26 Jan 2021 05:03:48 +0000 (00:03 -0500)
librb/include/rb_commio.h
librb/src/commio.c
librb/src/export-syms.txt

index b7a37db8d174c79956f9e34e7c5ddd1e7cc5ee42..0462442dd4b6214ff687b41d55dec09c361b35e6 100644 (file)
@@ -118,6 +118,8 @@ void rb_note(rb_fde_t *, const char *);
 #define RB_SSL_CERTFP_LEN_SHA512       64
 
 int rb_set_nb(rb_fde_t *);
+int rb_set_cloexec(rb_fde_t *);
+int rb_clear_cloexec(rb_fde_t *);
 int rb_set_buffers(rb_fde_t *, int);
 
 int rb_get_sockerr(rb_fde_t *);
index c3f4d122162d64e976bb955ed034908340fc32ac..9d9bfaee5dc2806b2ec4612e28a4fc2cfa9c789c 100644 (file)
@@ -260,6 +260,50 @@ rb_set_nb(rb_fde_t *F)
        return 1;
 }
 
+int
+rb_set_cloexec(rb_fde_t *F)
+{
+#ifdef _WIN32
+       SetHandleInformation((HANDLE) F->fd, HANDLE_FLAG_INHERIT, 0);
+#else
+       int res;
+       rb_platform_fd_t fd;
+       if(F == NULL)
+               return 0;
+       fd = F->fd;
+
+       res = fcntl(fd, F_GETFD, NULL);
+       if(res == -1)
+               return 0;
+       if(fcntl(fd, F_SETFD, res | FD_CLOEXEC) == -1)
+               return 0;
+
+       return 1;
+#endif
+}
+
+int
+rb_clear_cloexec(rb_fde_t *F)
+{
+#ifdef _WIN32
+       SetHandleInformation((HANDLE) F->fd, HANDLE_FLAG_INHERIT, 1);
+#else
+       int res;
+       rb_platform_fd_t fd;
+       if(F == NULL)
+               return 0;
+       fd = F->fd;
+
+       res = fcntl(fd, F_GETFD, NULL);
+       if(res == -1)
+               return 0;
+       if(fcntl(fd, F_SETFD, res & ~FD_CLOEXEC) == -1)
+               return 0;
+
+       return 1;
+#endif
+}
+
 /*
  * rb_settimeout() - set the socket timeout
  *
index 0c479b6dbb0d896588a66ec7b35de864c4ee23c4..f63869b8d7652ae884440933084c8f865ba84fac 100644 (file)
@@ -13,6 +13,7 @@ rb_bh_usage
 rb_bh_usage_all
 rb_bind
 rb_checktimeouts
+rb_clear_cloexec
 rb_clear_patricia
 rb_close
 rb_connect_sockaddr
@@ -153,6 +154,7 @@ rb_sctp_bindx
 rb_select
 rb_send_fd_buf
 rb_set_buffers
+rb_set_cloexec
 rb_set_nb
 rb_set_time
 rb_set_type