From ceea660bfa2b58612287d2c954d0410eba7511f1 Mon Sep 17 00:00:00 2001 From: liyuan Date: Sun, 8 Jan 2023 12:48:01 +0800 Subject: [PATCH] backport ppswatch: Fix quitting after signal --- 0001-ppswatch-Fix-quitting-after-signal.patch | 79 +++++++++++++++++++ pps-tools.spec | 7 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 0001-ppswatch-Fix-quitting-after-signal.patch diff --git a/0001-ppswatch-Fix-quitting-after-signal.patch b/0001-ppswatch-Fix-quitting-after-signal.patch new file mode 100644 index 0000000..321feb8 --- /dev/null +++ b/0001-ppswatch-Fix-quitting-after-signal.patch @@ -0,0 +1,79 @@ +From 6deb88a80529f76a1ff1bdc9f1d0eb15c46c87e4 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Konrad=20Gr=C3=A4fe?= +Date: Fri, 10 Aug 2018 09:47:33 +0200 +Subject: [PATCH] ppswatch: Fix quitting after signal +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The ppswatch quitting mechanism relies on time_pps_fetch() being +interrupted by a signal. Therefore when ppswatch receives a signal while +it's not within time_pps_fetch() it would print the stastics but not +quit the application. + +I can reliably reproduce the issue on my embedded machine (using the +pps-gpio driver) by running the following snippet: + ./ppswatch -a /dev/pps3 & + pid=$! + sleep 3 + kill $pid + +This patch fixes the issue. + +Signed-off-by: Konrad Gräfe +--- + ppswatch.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/ppswatch.c b/ppswatch.c +index eb0500c..5c6202b 100644 +--- a/ppswatch.c ++++ b/ppswatch.c +@@ -14,6 +14,7 @@ + * GNU General Public License for more details. + */ + ++#include + #include + #include + #include +@@ -39,6 +40,8 @@ static int max_divergence = 0; + static double mean = 0.0; + static double M2 = 0.0; + ++static volatile bool quit = false; ++ + int find_source(char *path, pps_handle_t *handle, int *avail_mode) + { + pps_params_t params; +@@ -112,8 +115,8 @@ int fetch_source(pps_handle_t handle, int avail_mode) + ret = time_pps_fetch(handle, PPS_TSFMT_TSPEC, &infobuf, + &timeout); + } +- if (ret < 0) { +- if (errno == EINTR) { ++ if (ret < 0 || quit) { ++ if (errno == EINTR || quit) { + return -1; + } + +@@ -244,6 +247,7 @@ void print_stats() + + static void sighandler_exit(int signum) { + print_stats(); ++ quit = true; + } + + int main(int argc, char *argv[]) +@@ -272,7 +276,7 @@ int main(int argc, char *argv[]) + /* loop, printing the most recent timestamp every second or so */ + while (1) { + ret = fetch_source(handle, avail_mode); +- if (ret < 0 && errno == EINTR) { ++ if ((ret < 0 && errno == EINTR) || quit) { + ret = 0; + break; + } +-- +2.33.0 + diff --git a/pps-tools.spec b/pps-tools.spec index 55d0526..f157df6 100644 --- a/pps-tools.spec +++ b/pps-tools.spec @@ -1,11 +1,13 @@ Name: pps-tools Version: 1.0.2 -Release: 3 +Release: 4 Summary: User-space tools for LinuxPPS License: GPLv2+ URL: https://github.com/redlab-i/pps-tools Source0: https://github.com/redlab-i/pps-tools/archive/v%{version}/%{name}-%{version}.tar.gz +Patch0001: 0001-ppswatch-Fix-quitting-after-signal.patch + BuildRequires: gcc %description @@ -43,6 +45,9 @@ install -p -m644 -t $RPM_BUILD_ROOT%{_includedir}/sys timepps.h %{_includedir}/sys/timepps.h %changelog +* Thu Oct 12 2023 liyuanyuan - 1.0.2-4 +- ppswatch: Fix quitting after signal + * Mon Dec 9 2019 openEuler Buildteam - 1.0.2-3 - Package init -- Gitee