Skip to content

Commit

Permalink
ts2phc: check is_running in ts2phc_pps_sink_poll()
Browse files Browse the repository at this point in the history
A recent bug in the ts2phc_pps_sink_poll() function caused the ts2phc
program to fail to exit in response to the SIGINT, SIGQUIT, SIGTERM, and
SIGHUP signals.

In normal behavior, these signals are caught by the handle_int_quit_term()
function, which sets the global running variable to 0. This causes the main
loop of the ts2phc main function to terminate and the program will clean up
and then quit.

However, if the ts2phc_pps_sink_poll() function does not exit -- as in the
buggy situation previously mentioned -- then the ts2phc application will
not exit.

Additional error checking was added to ts2phc_pps_sink_poll() to prevent it
from continuing when a clock device fails to poll. However, the
application may still take some time to finish polling while waiting for
events on all of the sink clocks.

If the user has issued a signal, there is no reason to continue polling,
and the application ought to stop immediately. In practice, if the signal
arrives while the poll() system call is running, it will exit and set errno
to EINTR. This normally causes the function to exit with a return of 0.
However, if the signal arrives at another point, the function will continue
polling until its normal exit condition. This could take some time,
preventing the program from exiting quickly.

Add a check against is_running() to the loop body, so that the ts2phc
program will exit efficiently upon being signaled.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
  • Loading branch information
jacob-keller authored and richardcochran committed Sep 6, 2024
1 parent f848316 commit e2dc1e1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ts2phc_pps_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ int ts2phc_pps_sink_poll(struct ts2phc_private *priv)
while (!all_sinks_have_events) {
struct ts2phc_pps_sink *sink;

if (!is_running())
return 0;

cnt = poll(polling_array->pfd, priv->n_sinks, 2000);
if (cnt < 0) {
if (errno == EINTR) {
Expand Down

0 comments on commit e2dc1e1

Please sign in to comment.