Currently, if the -c parameter is used multiple times only the last clock will be synchronized and no error will be returned.
This patch implements proper support for multiple -c parameter and will synchronize all clocks to the selected source. v2: Fixed check for hard_pps and updated man Signed-off-by: Maciek Machnikowski <mac...@machnikowski.net> --- phc2sys.8 | 2 +- phc2sys.c | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/phc2sys.8 b/phc2sys.8 index 99fc937..9277e01 100644 --- a/phc2sys.8 +++ b/phc2sys.8 @@ -120,7 +120,7 @@ Specify the time sink by device (e.g. /dev/ptp1) or interface (e.g. eth1) or by name. The default is CLOCK_REALTIME (the system clock). Not compatible with the .B \-a -option. +option. This option may be given multiple times. .TP .BI \-E " servo" Specify which clock servo should be used. Valid values are pi for a PI diff --git a/phc2sys.c b/phc2sys.c index 599f9bd..8b03689 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -967,11 +967,10 @@ static bool hardpps_configured(int fd) return fd >= 0; } -static int phc2sys_static_configuration(struct phc2sys_private *priv, - const char *src_name, - const char *dst_name) +static int phc2sys_static_src_configuration(struct phc2sys_private *priv, + const char *src_name) { - struct clock *src, *dst; + struct clock *src; src = clock_add(priv, src_name, -1); if (!src) { @@ -981,6 +980,14 @@ static int phc2sys_static_configuration(struct phc2sys_private *priv, src->state = PS_SLAVE; priv->master = src; + return 0; +} + +static int phc2sys_static_dst_configuration(struct phc2sys_private *priv, + const char *dst_name) +{ + struct clock *dst; + dst = clock_add(priv, dst_name, -1); if (!dst) { fprintf(stderr, "valid destination clock must be selected.\n"); @@ -1047,11 +1054,11 @@ static void usage(char *progname) int main(int argc, char *argv[]) { - char *config = NULL, *dst_name = NULL, *progname, *src_name = NULL; + char *config = NULL, *last_dst_name = NULL, *progname, *src_name = NULL; char uds_local[MAX_IFNAME_SIZE + 1]; int autocfg = 0, c, domain_number = 0, index, ntpshm_segment, offset; int pps_fd = -1, print_level = LOG_INFO, r = -1, rt = 0; - int wait_sync = 0; + int wait_sync = 0, dst_cnt = 0; struct config *cfg; struct option *opts; double phc_rate, tmp; @@ -1095,7 +1102,13 @@ int main(int argc, char *argv[]) rt++; break; case 'c': - dst_name = optarg; + last_dst_name = optarg; + r = phc2sys_static_dst_configuration(&priv, + last_dst_name); + if (r) { + goto end; + } + dst_cnt++; break; case 'd': pps_fd = open(optarg, O_RDONLY); @@ -1246,7 +1259,7 @@ int main(int argc, char *argv[]) return c; } - if (autocfg && (src_name || dst_name || hardpps_configured(pps_fd) || + if (autocfg && (src_name || last_dst_name || hardpps_configured(pps_fd) || wait_sync || priv.forced_sync_offset)) { fprintf(stderr, "autoconfiguration cannot be mixed with manual config options.\n"); @@ -1264,10 +1277,15 @@ int main(int argc, char *argv[]) goto bad_usage; } - if (!dst_name) { - dst_name = "CLOCK_REALTIME"; + if (!last_dst_name) { + last_dst_name = "CLOCK_REALTIME"; + r = phc2sys_static_dst_configuration(&priv, last_dst_name); + if (r) { + goto end; + } } - if (hardpps_configured(pps_fd) && strcmp(dst_name, "CLOCK_REALTIME")) { + if (hardpps_configured(pps_fd) && (dst_cnt > 1 || + strcmp(last_dst_name, "CLOCK_REALTIME"))) { fprintf(stderr, "cannot use a pps device unless destination is CLOCK_REALTIME\n"); goto bad_usage; @@ -1300,7 +1318,7 @@ int main(int argc, char *argv[]) goto end; } - r = phc2sys_static_configuration(&priv, src_name, dst_name); + r = phc2sys_static_src_configuration(&priv, src_name); if (r) { goto end; } -- 2.36.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel