!9 backport ppswatch: Fix quitting after signal
From: @liyy9 Reviewed-by: @Charlie_li Signed-off-by: @Charlie_li
This commit is contained in:
commit
62e6c0fc8e
79
0001-ppswatch-Fix-quitting-after-signal.patch
Normal file
79
0001-ppswatch-Fix-quitting-after-signal.patch
Normal file
@ -0,0 +1,79 @@
|
||||
From 6deb88a80529f76a1ff1bdc9f1d0eb15c46c87e4 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Konrad=20Gr=C3=A4fe?= <konradgraefe@aol.com>
|
||||
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 <konradgraefe@aol.com>
|
||||
---
|
||||
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 <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -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
|
||||
|
||||
@ -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 <liyuanyuan@xfusion.com> - 1.0.2-4
|
||||
- ppswatch: Fix quitting after signal
|
||||
|
||||
* Mon Dec 9 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.0.2-3
|
||||
- Package init
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user