On 11/29/2020 7:50 PM, Richard Cochran wrote:
> The main program determines whether a PPS device is the time source
> with an open-coded test for a valid file descriptor.  Replace it with
> a helper routine whose name properly signifies the meaning of the
> test.
> 
> Signed-off-by: Richard Cochran <richardcoch...@gmail.com>

Makes sense.

Reviewed-by: Jacob Keller <jacob.e.kel...@intel.com>

> ---
>  phc2sys.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/phc2sys.c b/phc2sys.c
> index e17909f..f28e9be 100644
> --- a/phc2sys.c
> +++ b/phc2sys.c
> @@ -979,6 +979,11 @@ static int clock_handle_leap(struct phc2sys_private 
> *priv, struct clock *clock,
>       return 0;
>  }
>  
> +static bool hardpps_configured(int fd)
> +{
> +     return fd >= 0;
> +}
> +
>  static void usage(char *progname)
>  {
>       fprintf(stderr,
> @@ -1222,12 +1227,13 @@ int main(int argc, char *argv[])
>               return c;
>       }
>  
> -     if (autocfg && (src_name || dst_name || pps_fd >= 0 || wait_sync || 
> priv.forced_sync_offset)) {
> +     if (autocfg && (src_name || dst_name || hardpps_configured(pps_fd) ||
> +                     wait_sync || priv.forced_sync_offset)) {
>               fprintf(stderr,
>                       "autoconfiguration cannot be mixed with manual config 
> options.\n");
>               goto bad_usage;
>       }
> -     if (!autocfg && pps_fd < 0 && !src_name) {
> +     if (!autocfg && !hardpps_configured(pps_fd) && !src_name) {
>               fprintf(stderr,
>                       "autoconfiguration or valid source clock must be 
> selected.\n");
>               goto bad_usage;
> @@ -1282,7 +1288,7 @@ int main(int argc, char *argv[])
>       dst->state = PS_MASTER;
>       LIST_INSERT_HEAD(&priv.dst_clocks, dst, dst_list);
>  
> -     if (pps_fd >= 0 && dst->clkid != CLOCK_REALTIME) {
> +     if (hardpps_configured(pps_fd) && dst->clkid != CLOCK_REALTIME) {
>               fprintf(stderr,
>                       "cannot use a pps device unless destination is 
> CLOCK_REALTIME\n");
>               goto bad_usage;
> @@ -1320,7 +1326,7 @@ int main(int argc, char *argv[])
>               }
>       }
>  
> -     if (pps_fd >= 0) {
> +     if (hardpps_configured(pps_fd)) {
>               /* only one destination clock allowed with PPS until we
>                * implement a mean to specify PTP port to PPS mapping */
>               dst->servo = servo_add(&priv, dst);
> 


_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to