ccx-utils

Miscellaneous utilities written in C
git clone https://ccx.te2000.cz/git/ccx-utils
Log | Files | Refs

commit 03a509da002f4be9c9d40e4b7c88ec3cca357e95
parent 42f9a2d5eed3755f3bd7d5b9b489641739fa356b
Author: Jan Pobrislo <ccx@te2000.cz>
Date:   Tue, 30 Jul 2024 12:46:21 +0000

Make fdrecv work too by disabling cloexec flag on the fd

Diffstat:
Msrc/fdrecv.c | 5+++++
Msrc/test-fdsend | 6+++++-
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/fdrecv.c b/src/fdrecv.c @@ -1,4 +1,5 @@ #include <errno.h> +#include <fcntl.h> #include <sys/select.h> #include <skalibs/types.h> @@ -37,6 +38,10 @@ int main (int argc, char const *const *argv) if(fd < 0) { 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"); + } size_t env_size = strlen(argv[2]) + uint_fmt(0, fd) + 2; char envstr[env_size]; diff --git a/src/test-fdsend b/src/test-fdsend @@ -6,4 +6,8 @@ background { redirfd -r 0 ./fdsend.c ./fdsend 3 0 true } fdclose 3 -./fdrecvto 4 0 cat +# ./fdrecvto 4 0 cat +./fdrecv 4 FD +importas -i FD FD +fdmove 0 $FD +cat