miniroon

Simplistic macaroon-based authorization for Unix systems
git clone https://ccx.te2000.cz/git/miniroon
Log | Files | Refs

commit f29bb200c1fb86697c4bbda34fbd96c21c169767
parent 86d745b0c8ea71cf157a46a7ac46af6c95f403a5
Author: Jan Pobrislo <ccx@te2000.cz>
Date:   Tue, 30 Jul 2024 18:13:01 +0000

Set fds nonblocking correctly.

Diffstat:
Msrc/pidns_run.c | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/pidns_run.c b/src/pidns_run.c @@ -13,16 +13,31 @@ #define PROG "pidns_run" -void nonblock_cloexec(int fd) { +void fd_cloexec(int fd) { int flags = fcntl(fd, F_GETFD); if(flags == -1) { strerr_dief1sys(111, "fcntl() getfd"); } - if(fcntl(fd, F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0) { + if(fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { strerr_dief1sys(111, "fcntl() setfd"); } } +void fd_nonblock(int fd) { + int flags = fcntl(fd, F_GETFL); + if(flags == -1) { + strerr_dief1sys(111, "fcntl() getfd"); + } + if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) { + strerr_dief1sys(111, "fcntl() setfd"); + } +} + +void nonblock_cloexec(int fd) { + fd_cloexec(fd); + fd_nonblock(fd); +} + int main(const int argc, const char **argv) { int piperw[2]; #define parent_rfd piperw[0]