From 2fe44bbd7885dcaa72e85df9bc2881cef78feb78 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Sat, 30 Oct 2021 18:10:27 +0200 Subject: [PATCH] Fixed -r, -R to named pipe "No such device or address" error --- CHANGES | 5 +++++ socat.c | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 8866ccf..7c10ed4 100644 --- a/CHANGES +++ b/CHANGES @@ -40,6 +40,11 @@ Corrections: Test: SNIFF_RIGHT_TO_LEFT Thanks to 1314 gsf for reporting this bug and sending a patch. + Options -r and -R, when opening a named pipe that has no actual reader, + failed with "No such device or address". To solve this problem, Socat + now opens the pipe in rw-Mode. + Thanks to Cody J.Soultz for sending a patch. + Testing: Prevent the TIMESTAMP tests from sporadically failing due do seconds overflow diff --git a/socat.c b/socat.c index 8c9b841..b7a9b61 100644 --- a/socat.c +++ b/socat.c @@ -191,8 +191,17 @@ int main(int argc, const char *argv[]) { #ifdef O_LARGEFILE O_LARGEFILE| #endif - O_NONBLOCK, 0664)) < 0) + O_NONBLOCK, 0664)) < 0) { + if (errno == ENXIO) { + if ((socat_opts.sniffleft = Open(a, O_CREAT|O_RDWR|O_APPEND| +#ifdef O_LARGEFILE + O_LARGEFILE| +#endif + O_NONBLOCK, 0664)) > 0) + break; /* try to open pipe rdwr */ + } Error2("option -r \"%s\": %s", a, strerror(errno)); + } break; case 'R': if (arg1[0][2]) { a = *arg1+2; @@ -207,8 +216,17 @@ int main(int argc, const char *argv[]) { #ifdef O_LARGEFILE O_LARGEFILE| #endif - O_NONBLOCK, 0664)) < 0) + O_NONBLOCK, 0664)) < 0) { + if (errno == ENXIO) { + if ((socat_opts.sniffright = Open(a, O_CREAT|O_RDWR|O_APPEND| +#ifdef O_LARGEFILE + O_LARGEFILE| +#endif + O_NONBLOCK, 0664)) > 0) + break; /* try to open pipe rdwr */ + } Error2("option -R \"%s\": %s", a, strerror(errno)); + } break; case 'b': if (arg1[0][2]) { a = *arg1+2;