Assume only the chronyd or ntpd process is essential for synchronization
of the system clock and ignore SIGCHLD from other processes. This should
provide resiliency against possible bugs in ptp4l or phc2sys that can
terminate the processes.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 timemaster.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/timemaster.c b/timemaster.c
index 7a22a8b..66ac521 100644
--- a/timemaster.c
+++ b/timemaster.c
@@ -1035,6 +1035,14 @@ static int script_run(struct script *script)
        pid_t pid, *pids;
        int i, num_commands, status, ret = 0;
 
+       for (num_commands = 0; script->commands[num_commands]; num_commands++)
+               ;
+
+       if (!num_commands) {
+               /* nothing to do */
+               return 0;
+       }
+
        if (create_config_files(script->configs))
                return 1;
 
@@ -1050,9 +1058,6 @@ static int script_run(struct script *script)
                return 1;
        }
 
-       for (num_commands = 0; script->commands[num_commands]; num_commands++)
-               ;
-
        pids = xcalloc(num_commands, sizeof(*pids));
 
        for (i = 0; i < num_commands; i++) {
@@ -1065,15 +1070,25 @@ static int script_run(struct script *script)
 
        /* wait for one of the blocked signals */
        while (1) {
-               if (sigwaitinfo(&mask, &info) > 0)
-                       break;
-               if (errno != EINTR) {
+               if (sigwaitinfo(&mask, &info) < 0) {
+                       if (errno == EINTR)
+                               continue;
                        pr_err("sigwaitinfo() failed: %m");
                        break;
                }
-       }
 
-       pr_info("received signal %d", info.si_signo);
+               /*
+                * assume only the first process (i.e. chronyd or ntpd) is
+                * essential and continue if other processes terminate
+                */
+               if (info.si_signo == SIGCHLD && info.si_pid != pids[0]) {
+                       pr_info("process %d terminated (ignored)", info.si_pid);
+                       continue;
+               }
+
+               pr_info("received signal %d", info.si_signo);
+               break;
+       }
 
        /* kill all started processes */
        for (i = 0; i < num_commands; i++) {
-- 
2.5.5


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to