1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

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
This commit is contained in:
Andrew Tridgell 2011-11-30 15:17:47 +11:00 committed by Andrew Bartlett
parent 9782501f0b
commit 3b56f64923
2 changed files with 23 additions and 0 deletions

View File

@ -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;
}

View File

@ -667,6 +667,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.
**/