diff options
-rw-r--r-- | lib/util/blocking.c | 18 | ||||
-rw-r--r-- | lib/util/samba_util.h | 5 |
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/util/blocking.c b/lib/util/blocking.c index f5933cc92b..9dede7aa0d 100644 --- a/lib/util/blocking.c +++ b/lib/util/blocking.c @@ -60,3 +60,21 @@ _PUBLIC_ int set_blocking(int fd, bool set) return fcntl( fd, F_SETFL, val); #undef FLAG_TO_SET } + + +_PUBLIC_ bool set_close_on_exec(int fd) +{ +#ifdef FD_CLOEXEC + int val; + + val = fcntl(fd, F_GETFD, 0); + if (val >= 0) { + val |= FD_CLOEXEC; + val = fcntl(fd, F_SETFD, val); + if (val != -1) { + return true; + } + } +#endif + return false; +} diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h index 9a76fa9f04..3b5169d744 100644 --- a/lib/util/samba_util.h +++ b/lib/util/samba_util.h @@ -668,6 +668,11 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid, _PUBLIC_ int set_blocking(int fd, bool set); /** + set close on exec on a file descriptor if available + **/ +_PUBLIC_ bool set_close_on_exec(int fd); + +/** Sleep for a specified number of milliseconds. **/ _PUBLIC_ void smb_msleep(unsigned int t); |