From 43e8a98327c4572111134e3322bb524ab9644098 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 5 Jan 2023 15:13:53 +0100 Subject: [PATCH] handle EINTR when waiting for transmit timestamp (#2128786) Resolves: #2128786 --- linuxptp-eintr.patch | 30 ++++++++++++++++++++++++++++++ linuxptp.spec | 3 +++ 2 files changed, 33 insertions(+) create mode 100644 linuxptp-eintr.patch diff --git a/linuxptp-eintr.patch b/linuxptp-eintr.patch new file mode 100644 index 0000000..2ea76ad --- /dev/null +++ b/linuxptp-eintr.patch @@ -0,0 +1,30 @@ +commit c8de9f33e437fb15cff32c0028f651d7cb916a37 +Author: Miroslav Lichvar +Date: Tue Sep 13 13:44:10 2022 +0200 + + sk: Handle EINTR when waiting for transmit timestamp. + + If ptp4l received a signal in poll() waiting for a transmit timestamp, + multiple (possibly confusing) error messages are logged before exit. + + If poll() returns with EINTR, call it once again to get the timestamp + and avoid logging the errors. Don't call it in a loop to avoid getting + stuck in case the timestamp is lost and the signal is repeated before + the poll timeout can be reached. + + Signed-off-by: Miroslav Lichvar + +diff --git a/sk.c b/sk.c +index 80075be..d27abff 100644 +--- a/sk.c ++++ b/sk.c +@@ -354,6 +354,9 @@ int sk_receive(int fd, void *buf, int buflen, + if (flags == MSG_ERRQUEUE) { + struct pollfd pfd = { fd, sk_events, 0 }; + res = poll(&pfd, 1, sk_tx_timeout); ++ /* Retry once on EINTR to avoid logging errors before exit */ ++ if (res < 0 && errno == EINTR) ++ res = poll(&pfd, 1, sk_tx_timeout); + if (res < 1) { + pr_err(res ? "poll for tx timestamp failed: %m" : + "timed out while polling for tx timestamp"); diff --git a/linuxptp.spec b/linuxptp.spec index 9f1690e..b729cc9 100644 --- a/linuxptp.spec +++ b/linuxptp.spec @@ -47,6 +47,8 @@ Patch12: linuxptp-vclock.patch Patch13: linuxptp-phcerr.patch # add support for VLAN over bond Patch14: linuxptp-vlanbond.patch +# handle EINTR when waiting for transmit timestamp +Patch15: linuxptp-eintr.patch BuildRequires: gcc gcc-c++ make systemd @@ -74,6 +76,7 @@ Supporting legacy APIs and other platforms is not a goal. %patch12 -p1 -b .vclock %patch13 -p1 -b .phcerr %patch14 -p1 -b .vlanbond +%patch15 -p1 -b .eintr mv linuxptp-testsuite-%{testsuite_ver}* testsuite mv clknetsim-%{clknetsim_ver}* testsuite/clknetsim