summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-11-30 15:17:47 +1100
committerAndrew Bartlett <abartlet@samba.org>2011-12-15 23:36:22 +0100
commit3b56f64923a71a90734c5167d549e4eb14002d18 (patch)
tree9f0e674be0f784f05845380f7afa9abc1a57230c /lib
parent9782501f0b9fafa171c4ed830abd8433b0be1f1b (diff)
downloadsamba-3b56f64923a71a90734c5167d549e4eb14002d18.tar.gz
samba-3b56f64923a71a90734c5167d549e4eb14002d18.tar.bz2
samba-3b56f64923a71a90734c5167d549e4eb14002d18.zip
lib/util: added set_close_on_exec()
this was already in tevent_util.c, but library layering prevented us from using it in some other libraries
Diffstat (limited to 'lib')
-rw-r--r--lib/util/blocking.c18
-rw-r--r--lib/util/samba_util.h5
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);