integ/base/linuxptp/debian/patches/0046-Robustness-improvements-to-phc2sys-socket.patch
Andre Mauricio Zelak 600ad549b5 Use time traceable flag in HA clock selection
A new time traceable flag was added to pmc agent to store the current
time traceable status.

This flag replaces the utc_offset_traceable flag in the HA clock
selection algorithm and status command.

Test plan: HA clock selection algorithm
PASS: Verify the clock source which time isn't traceable is discarded
by the algorithm if ha_gm_timeTraceable is enabled.
PASS: Verify the clock source which time is traceable isn't discarded
by the algorithm if ha_gm_timeTraceable is enabled.

Regression: status command
PASS: Verify the response of status command shows the correct GM time
traceable.

The 'valid sources' command is used to get a list of interfaces which
the clock is matching the requirements. The response contains a space
separated list of interfaces, or "None" when not a single clock is
matching all the requirements.

Test plan: valid sources command
PASS: Verify that a space separated list of interface is returned when
one or more clocks match the requirements.
PASS: Verify that the string "None" is returned when not a single clock
match the requirements.

Now the GM time traceable check is enabled by default as it is an
important check for both T-GM and T-BC scenarios.

The GM time traceable check is controlled in configuration by using
the ha_gm_timeTraceable setting, and it can be disabled using the
value 0 (ha_gm_timeTraceable 0).

Test plan: default value
PASS Verify the check is performed by default.
PASS Verify the user can disable the check by configuration.

Bonus:

Fixed the behavior when none clock is matching the requirements and the
active clock source is disabled using the 'disable source <interface>'
command. The interface is must be disabled and a new clock source is
selected.

Test plan: none clock is matching the requirements
PASS: Verify that the active source can be disabled and a new one is
selected.
PASS: Verify that an attempt to disable the last active interface
fails and an appopriated message is given as response.
PASS: Verify that the interface with higher priority is selected after
re-enabling it.
PASS: Verify the active clock source doesn't change if another
interface is disabled.
PASS: Verify the active clock source doesn't change if another
interface is re-enabled.

Story: 2010723
Task: 48702

Change-Id: I64193575a995e520d36460c0ebb8dd452fa8c2b8
Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
2023-09-06 15:09:14 -03:00

79 lines
2.5 KiB
Diff

From f480fb54182da36baeb35bac90154abafcaf854a Mon Sep 17 00:00:00 2001
From: Andre Mauricio Zelak <andre.zelak@windriver.com>
Date: Tue, 8 Aug 2023 14:06:55 -0300
Subject: [PATCH 46/54] Robustness improvements to phc2sys socket
When phc2sys abnormally exits the socket file might remain created.
To avoid error when phc2sys is relaunched, the exixting file is
deleted before recriating the socket.
If the peer application closes the socket before sending the
response completely, it will cause a broken pipe error. The
send function generates a SIGPIPE on broken pipe errors,
killing the phc2sys process unless MSG_NOSIGNAL flag is set.
Test plan: socket file
PASS: Verify that phc2sys can restart normally after killing it.
Test plan: SIGPIPE
PASS: Verify the phc2sys application don't exit when client socket
is closed before the respose is sent.
Reviewed-by: Cole Walker <cole.walker@windriver.com>
Reviewed-by: Andre Fernando Zanella Kantek
<andrefernandozanella.kantek@windriver.com>
[commit 8b3765b3f104a90a487fbcb0f61074c7677c215e upstream]
[commit 50ad1c6f81a706b8be6689bea2ba2db215cf3dc3 upstream]
Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
---
phc2sys.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/phc2sys.c b/phc2sys.c
index 6965162..edc626f 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1218,7 +1218,9 @@ static int ha_com_socket_open(int *fd_out, struct config *cfg)
int fd, err;
struct sockaddr_un sa;
const int backlog = 50;
- const char *name = config_get_string(cfg, NULL, "ha_phc2sys_com_socket");
+ const char *path = config_get_string(cfg, NULL, "ha_phc2sys_com_socket");
+
+ unlink(path);
fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (fd < 0) {
@@ -1228,7 +1230,7 @@ static int ha_com_socket_open(int *fd_out, struct config *cfg)
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_LOCAL;
- strncpy(sa.sun_path, name, sizeof(sa.sun_path) - 1);
+ strncpy(sa.sun_path, path, sizeof(sa.sun_path) - 1);
err = bind(fd, (struct sockaddr *) &sa, sizeof(sa));
if (err < 0) {
@@ -1245,7 +1247,7 @@ static int ha_com_socket_open(int *fd_out, struct config *cfg)
}
*fd_out = fd;
- chmod(name, HA_SCK_FILEMODE);
+ chmod(path, HA_SCK_FILEMODE);
return 0;
}
@@ -1269,7 +1271,7 @@ static int ha_com_socket_send(int fd, void *buf, size_t buflen)
{
int cnt;
- cnt = send(fd, buf, buflen, 0);
+ cnt = send(fd, buf, buflen, MSG_NOSIGNAL);
if (cnt < 0) {
pr_err("ha_com_socket: send failed: %m");
return -errno;
--
2.25.1