79 lines
2.2 KiB
Diff
79 lines
2.2 KiB
Diff
# src: https://github.com/redlab-i/pps-tools/commit/6deb88a80529f76a1ff1bdc9f1d0eb15c46c87e4.patch
|
|
|
|
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
|
|
--- ppswatch.c
|
|
+++ 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;
|
|
}
|