miniroon

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

commit 86d745b0c8ea71cf157a46a7ac46af6c95f403a5
parent 3a1f7b08f9ad5f79fd7b8430028ed1ffe60d31c9
Author: Jan Pobrislo <ccx@te2000.cz>
Date:   Tue, 30 Jul 2024 13:09:44 +0000

Handle EAGAIN in sendmsg/recvmsg

Diffstat:
Msrc/fdrecv.c | 13++++++++-----
Msrc/fdrecvto.c | 12+++++++-----
Msrc/fdsend.c | 5++++-
3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/fdrecv.c b/src/fdrecv.c @@ -29,15 +29,18 @@ void wait_readable(int fd) { int main (int argc, char const *const *argv) { unsigned int socket_fd; - int fd; + int fd = -1; if ((argc < 4)) strerr_dieusage(100, USAGE) ; if (!uint0_scan(argv[1], &socket_fd)) strerr_dieusage(100, USAGE) ; - wait_readable(socket_fd); - fd = ancil_recv_fd(socket_fd, 42); - if(fd < 0) { - strerr_dief1sys(111, "recvmsg()"); + while(fd < 0) { + wait_readable(socket_fd); + fd = ancil_recv_fd(socket_fd, 42); + if(fd < 0 && errno != EAGAIN) { + strerr_dief1sys(111, "recvmsg()"); + } } + /* disable close-on-exec flag if present on fd */ if(fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, NULL) & ~FD_CLOEXEC) == -1) { strerr_dief1sys(111, "fcntl() disabling FD_CLOEXEC"); diff --git a/src/fdrecvto.c b/src/fdrecvto.c @@ -29,15 +29,17 @@ void wait_readable(int fd) { int main (int argc, char const *const *argv) { unsigned int socket_fd, target_fd; - int fd; + int fd = -1; if ((argc < 4)) strerr_dieusage(100, USAGE) ; if (!uint0_scan(argv[1], &socket_fd)) strerr_dieusage(100, USAGE) ; if (!uint0_scan(argv[2], &target_fd)) strerr_dieusage(100, USAGE) ; - wait_readable(socket_fd); - fd = ancil_recv_fd(socket_fd, 42); - if(fd < 0) { - strerr_dief1sys(111, "recvmsg()"); + while(fd < 0) { + wait_readable(socket_fd); + fd = ancil_recv_fd(socket_fd, 42); + if(fd < 0 && errno != EAGAIN) { + strerr_dief1sys(111, "recvmsg()"); + } } if(fd == target_fd) { int tmp_fd = dup(fd); diff --git a/src/fdsend.c b/src/fdsend.c @@ -34,8 +34,11 @@ int main (int argc, char const *const *argv) if (!uint0_scan(argv[2], &fd_to_send)) strerr_dieusage(100, USAGE) ; wait_writable(socket_fd); - if(!ancil_send_fd(socket_fd, fd_to_send, 42)) { + while(!ancil_send_fd(socket_fd, fd_to_send, 42)) { + if(errno != EAGAIN) { strerr_dief1sys(111, "sendmsg()"); + } + wait_writable(socket_fd); } xexec(argv+3) ;