On Tue, Oct 18, 2022 at 05:08:29PM +0200, Maciek Machnikowski wrote:
> To enable handling lstab in the same way by different pps sources, move
> update_leapsecond_table function from the nmea_pps_source to the generic lstab
> file. This also required moving leapfile filename and its modification time to
> the struct lstab.
>
> Signed-off-by: Maciek Machnikowski <[email protected]>
> ---
> lstab.c | 55 ++++++++++++++++++++++++++++++++++++++++
> lstab.h | 8 ++++++
> ts2phc_nmea_pps_source.c | 51 +++----------------------------------
> 3 files changed, 67 insertions(+), 47 deletions(-)
>
> diff --git a/lstab.c b/lstab.c
> index a44aead..019e2d1 100644
> --- a/lstab.c
> +++ b/lstab.c
> @@ -3,6 +3,7 @@
> * @note Copyright (C) 2012 Richard Cochran <[email protected]>
> * @note SPDX-License-Identifier: GPL-2.0+
> */
> +#include <sys/stat.h>
> #include <inttypes.h>
> #include <stdio.h>
> #include <stdlib.h>
Preserve alphabetical order please.
> @@ -157,6 +160,8 @@ static int lstab_read(struct lstab *lstab, const char
> *name)
> struct lstab *lstab_create(const char *filename)
> {
> struct lstab *lstab = calloc(1, sizeof(*lstab));
> + struct stat statbuf;
> + int err;
>
> if (!lstab) {
> return NULL;
> @@ -166,12 +171,57 @@ struct lstab *lstab_create(const char *filename)
> free(lstab);
> return NULL;
> }
> + lstab->leapfile = filename;
> +
> + err = stat(lstab->leapfile, &statbuf);
> + if (err) {
> + fprintf(stderr, "file status failed on %s: %m",
> + lstab->leapfile);
Missing free(lstab);
> + return NULL;
> + }
> +
> + lstab->lsfile_mtime = statbuf.st_mtim.tv_sec;
> +
> } else {
> lstab_init(lstab);
> }
> return lstab;
> }
>
> +int update_leapsecond_table(struct lstab *lstab)
No need for global function. Add static keyword.
> +{
> + const char* leapfile;
> + struct stat statbuf;
> + int err;
> +
> + if (!lstab) {
> + return -1;
> + }
This test is unnecessary as caller provides valid lstab.
> + if (!lstab->leapfile) {
> + return 0;
> + }
> + err = stat(lstab->leapfile, &statbuf);
> + if (err) {
> + fprintf(stderr, "file status failed on %s: %m",
> + lstab->leapfile);
> + return -1;
> + }
> + if (lstab->lsfile_mtime == statbuf.st_mtim.tv_sec) {
> + return 0;
> + }
> + printf("updating leap seconds file\n");
> + leapfile = lstab->leapfile;
> + lstab_destroy(lstab);
> +
> + lstab = lstab_create(leapfile);
> + if (!lstab) {
> + return -1;
> + }
> +
> + return 0;
> +}
Thanks,
Richard
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel