socat: Exit when the file associated with an FD is destroyed
cover socat: Exit when the file associated with an FD is destroyed
The following changes since commit 93ad1ab49be03dd082a98f80464cfee9d98a3a33:
diffoscope: Ensure rpm is configured correctly (2021-02-24 12:42:45 +0000)
are available in the Git repository at:
git://git.openembedded.org/openembedded-core-contrib rbt/socat
http://cgit.openembedded.org/openembedded-core-contrib/log/?h=rbt/socat
Robert Yang (1):
socat: Exit when the file associated with an FD is destroyed
...le-associated-with-an-FD-is-destroye.patch | 62 +++++++++++++++++++ .../socat/socat_1.7.4.1.bb | 1 + 2 files changed, 63 insertions(+) create mode 100644 meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch
Signature · 1 line
2.17.1
PATCH 1/1 socat: Exit when the file associated with an FD is destroyed
In many scenarios the receipt of an EOF will coincide with the teardown of the file which the FD is associated with by the application on the other side of the file pipe. If a timeout (-t) is used socat continues to poll for new data (read) and send any new data (write) until the timeout. This can lead to input/output errors as the FD exists still but the file it was openned on is gone, and no check is done on writes.
To get around this a check is added after the EOF is received that the file still exists, and if not we proceed to exit immediately. This will avoid i/o errors and will also cause a quicker return as we don't have to wait for the timeout.
The original author is Mark Asselstine <[email protected]>.
--- ...le-associated-with-an-FD-is-destroye.patch | 62 +++++++++++++++++++ .../socat/socat_1.7.4.1.bb | 1 + 2 files changed, 63 insertions(+) create mode 100644 meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch
meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch new file +62 -0
@@ -0,0 +1,62 @@ +From 956d4b00a101f61b4cfaafa0856b646646536492 Mon Sep 17 00:00:00 2001 +From: Mark Asselstine <[email protected]> +Date: Mon, 7 Dec 2015 21:27:35 -0500 +Subject: [PATCH] Exit when the file associated with an FD is destroyed + +In many scenarios the receipt of an EOF will coincide with the +teardown of the file which the FD is associated with by the +application on the other side of the file pipe. If a timeout (-t) is +used socat continues to poll for new data (read) and send any new data +(write) until the timeout. This can lead to input/output errors as the +FD exists still but the file it was openned on is gone, and no check +is done on writes. + +To get around this a check is added after the EOF is received that the +file still exists, and if not we proceed to exit immediately. This +will avoid i/o errors and will also cause a quicker return as we don't +have to wait for the timeout. + +Signed-off-by: Mark Asselstine <[email protected]> + +Upstream-Status: Submitted [[email protected]] + +Signed-off-by: Robert Yang <[email protected]> + +--- + socat.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/socat.c b/socat.c +index b619a3d..de4a14b 100644 +--- a/socat.c ++++ b/socat.c +@@ -773,6 +773,7 @@ int _socat(void) { + int polling = 0; /* handling ignoreeof */ + int wasaction = 1; /* last poll was active, do NOT sleep before next */ + struct timeval total_timeout; /* the actual total timeout timer */ ++ struct stat file_stat; + + #if WITH_FILAN + if (socat_opts.debug) { +@@ -1123,6 +1124,10 @@ int _socat(void) { + xioshutdown(sock2, SHUT_WR); + XIO_RDSTREAM(sock1)->eof = 3; + XIO_RDSTREAM(sock1)->ignoreeof = false; ++ if (fstat(XIO_GETRDFD(sock1), &file_stat) == -1 || file_stat.st_nlink == 0) { ++ Notice1("socket 1 (fd %d) is gone", XIO_GETRDFD(sock1)); ++ break; ++ } + } + } else if (polling && XIO_RDSTREAM(sock1)->ignoreeof) { + polling = 0; +@@ -1146,6 +1151,10 @@ int _socat(void) { + xioshutdown(sock1, SHUT_WR); + XIO_RDSTREAM(sock2)->eof = 3; + XIO_RDSTREAM(sock2)->ignoreeof = false; ++ if (fstat(XIO_GETRDFD(sock2), &file_stat) == -1 || file_stat.st_nlink == 0) { ++ Notice1("socket 2 (fd %d) is gone", XIO_GETRDFD(sock2)); ++ break; ++ } + } + } else if (polling && XIO_RDSTREAM(sock2)->ignoreeof) { + polling = 0;
meta/recipes-connectivity/socat/socat_1.7.4.1.bb +1 -0
@@ -10,6 +10,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \ file://README;beginline=257;endline=287;md5=82520b052f322ac2b5b3dfdc7c7eea86" SRC_URI = "http://www.dest-unreach.org/socat/download/socat-${PV}.tar.bz2 \ + file://Exit-when-the-file-associated-with-an-FD-is-destroye.patch \ " SRC_URI[md5sum] = "36cad050ecf4981ab044c3fbd75c643f"
Signature · 1 line
2.17.1
Quoted 41 lines · Robert Yang
In many scenarios the receipt of an EOF will coincide with the teardown of the file which the FD is associated with by the application on the other side of the file pipe. If a timeout (-t) is used socat continues to poll for new data (read) and send any new data (write) until the timeout. This can lead to input/output errors as the FD exists still but the file it was openned on is gone, and no check is done on writes.
To get around this a check is added after the EOF is received that the file still exists, and if not we proceed to exit immediately. This will avoid i/o errors and will also cause a quicker return as we don't have to wait for the timeout.
The original author is Mark Asselstine <[email protected]>.
Signed-off-by Robert Yang <[email protected]>---
...le-associated-with-an-FD-is-destroye.patch | 62 +++++++++++++++++++
.../socat/socat_1.7.4.1.bb | 1 +2 files changed, 63 insertions(+)create mode 100644
meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patchmeta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch new file +13
-0@@ -0,0 +1,62 @@ +From 956d4b00a101f61b4cfaafa0856b646646536492 Mon Sep 17 00:00:00 2001 +From: Mark Asselstine <[email protected]> +Date: Mon, 7 Dec 2015 21:27:35 -0500 +Subject: [PATCH] Exit when the file associated with an FD is destroyed + +In many scenarios the receipt of an EOF will coincide with the +teardown of the file which the FD is associated with by the +application on the other side of the file pipe. If a timeout (-t) is +used socat continues to poll for new data (read) and send any new data +(write) until the timeout. This can lead to input/output errors as the +FD exists still but the file it was openned on is gone, and no check +is done on writes. +
meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch line 23
Quoted 10 lines
meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch new file +10
-0+To get around this a check is added after the EOF is received that the +file still exists, and if not we proceed to exit immediately. This +will avoid i/o errors and will also cause a quicker return as we don't +have to wait for the timeout. + +Signed-off-by: Mark Asselstine <[email protected]> + +Upstream-Status: Submitted [[email protected]] + +Signed-off-by: Robert Yang <[email protected]>
This was written in 2015, when was it submitted? What was the response? An idea of the current status would be good for a patch of this age.
Cheers,
Richard
Hi RP,
Quoted 47 lines · Richard Purdie
Quoted 46 lines · Robert Yang
In many scenarios the receipt of an EOF will coincide with the teardown of the file which the FD is associated with by the application on the other side of the file pipe. If a timeout (-t) is used socat continues to poll for new data (read) and send any new data (write) until the timeout. This can lead to input/output errors as the FD exists still but the file it was openned on is gone, and no check is done on writes.
To get around this a check is added after the EOF is received that the file still exists, and if not we proceed to exit immediately. This will avoid i/o errors and will also cause a quicker return as we don't have to wait for the timeout.
The original author is Mark Asselstine <[email protected]>.
Signed-off-by Robert Yang <[email protected]>--- ...le-associated-with-an-FD-is-destroye.patch | 62 +++++++++++++++++++ .../socat/socat_1.7.4.1.bb | 1 + 2 files changed, 63 insertions(+)create mode 100644
meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patchmeta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch new file +18
-0@@ -0,0 +1,62 @@ +From 956d4b00a101f61b4cfaafa0856b646646536492 Mon Sep 17 00:00:00 2001 +From: Mark Asselstine <[email protected]> +Date: Mon, 7 Dec 2015 21:27:35 -0500 +Subject: [PATCH] Exit when the file associated with an FD is destroyed + +In many scenarios the receipt of an EOF will coincide with the +teardown of the file which the FD is associated with by the +application on the other side of the file pipe. If a timeout (-t) is +used socat continues to poll for new data (read) and send any new data +(write) until the timeout. This can lead to input/output errors as the +FD exists still but the file it was openned on is gone, and no check +is done on writes. + +To get around this a check is added after the EOF is received that the +file still exists, and if not we proceed to exit immediately. This +will avoid i/o errors and will also cause a quicker return as we don't +have to wait for the timeout. +
Quoted 8 lines
meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch line 23
Quoted 5 lines
meta/recipes-connectivity/socat/files/Exit-when-the-file-associated-with-an-FD-is-destroye.patch new file +5
-0+Signed-off-by: Mark Asselstine <[email protected]> + +Upstream-Status: Submitted [[email protected]] + +Signed-off-by: Robert Yang <[email protected]>This was written in 2015, when was it submitted? What was the response? An idea of the current status would be good for a patch of this age.
I sent it to upstream yesterday, I got a reply from upstream today which asked for a testcase, let's hold on this patch and wait for upstream to merge it.
// Robert
Quoted 6 lines
Cheers,
Richard