|
Packit |
06dd63 |
/* cloexec.c - set or clear the close-on-exec descriptor flag
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
Copyright (C) 2004, 2009-2019 Free Software Foundation, Inc.
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
This program is free software: you can redistribute it and/or modify
|
|
Packit |
06dd63 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
06dd63 |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
06dd63 |
(at your option) any later version.
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
06dd63 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
06dd63 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
06dd63 |
GNU General Public License for more details.
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
You should have received a copy of the GNU General Public License
|
|
Packit |
06dd63 |
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
*/
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
#include <stdbool.h>
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
|
|
Packit |
06dd63 |
or clear the flag if VALUE is false.
|
|
Packit |
06dd63 |
Return 0 on success, or -1 on error with 'errno' set.
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
Note that on MingW, this function does NOT protect DESC from being
|
|
Packit |
06dd63 |
inherited into spawned children. Instead, either use dup_cloexec
|
|
Packit |
06dd63 |
followed by closing the original DESC, or use interfaces such as
|
|
Packit |
06dd63 |
open or pipe2 that accept flags like O_CLOEXEC to create DESC
|
|
Packit |
06dd63 |
non-inheritable in the first place. */
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
int set_cloexec_flag (int desc, bool value);
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
/* Duplicates a file handle FD, while marking the copy to be closed
|
|
Packit |
06dd63 |
prior to exec or spawn. Returns -1 and sets errno if FD could not
|
|
Packit |
06dd63 |
be duplicated. */
|
|
Packit |
06dd63 |
|
|
Packit |
06dd63 |
int dup_cloexec (int fd);
|