Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 config.c  | 7 +------
 config.h  | 2 --
 ntpshm.c  | 9 +++------
 ntpshm.h  | 7 +------
 phc2sys.c | 3 +++
 ptp4l.c   | 2 --
 servo.c   | 2 +-
 7 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/config.c b/config.c
index 1ae564f..c1d5aeb 100644
--- a/config.c
+++ b/config.c
@@ -96,6 +96,7 @@ struct config_item config_tab[] = {
        GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
        GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, 
PRINT_LEVEL_MAX),
        GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
+       GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
        GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
        GLOB_ITEM_DBL("pi_integral_exponent", 0.4, -DBL_MAX, DBL_MAX),
        GLOB_ITEM_DBL("pi_integral_norm_max", 0.3, DBL_MIN, 2.0),
@@ -554,12 +555,6 @@ static enum parser_result parse_global_setting(const char 
*option,
                        return r;
                cfg->dds.sanity_freq_limit = val;
 
-       } else if (!strcmp(option, "ntpshm_segment")) {
-               r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
-               if (r != PARSED_OK)
-                       return r;
-               *cfg->ntpshm_segment = val;
-
        } else if (!strcmp(option, "ptp_dst_mac")) {
                if (MAC_LEN != sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
                                      &mac[0], &mac[1], &mac[2], &mac[3], 
&mac[4], &mac[5]))
diff --git a/config.h b/config.h
index bdfead7..c1ada46 100644
--- a/config.h
+++ b/config.h
@@ -69,8 +69,6 @@ struct config {
        struct port_defaults pod;
        enum servo_type clock_servo;
 
-       int *ntpshm_segment;
-
        unsigned char *ptp_dst_mac;
        unsigned char *p2p_dst_mac;
        unsigned char *udp6_scope;
diff --git a/ntpshm.c b/ntpshm.c
index 8b18e2d..3b62a3f 100644
--- a/ntpshm.c
+++ b/ntpshm.c
@@ -22,12 +22,11 @@
 #include <sys/types.h>
 #include <sys/shm.h>
 
+#include "config.h"
 #include "print.h"
 #include "ntpshm.h"
 #include "servo_private.h"
 
-#define NS_PER_SEC 1000000000
-
 /* NTP leap values */
 #define LEAP_NORMAL 0x0
 #define LEAP_INSERT 0x1
@@ -36,9 +35,6 @@
 /* Key of the first SHM segment */
 #define SHMKEY 0x4e545030
 
-/* Number of the SHM segment to be used */
-int ntpshm_segment = 0;
-
 /* Declaration of the SHM segment from ntp (ntpd/refclock_shm.c) */
 struct shmTime {
        int    mode; /* 0 - if valid set
@@ -134,9 +130,10 @@ static void ntpshm_leap(struct servo *servo, int leap)
        s->leap = leap;
 }
 
-struct servo *ntpshm_servo_create(void)
+struct servo *ntpshm_servo_create(struct config *cfg)
 {
        struct ntpshm_servo *s;
+       int ntpshm_segment = config_get_int(cfg, NULL, "ntpshm_segment");
        int shmid;
 
        s = calloc(1, sizeof(*s));
diff --git a/ntpshm.h b/ntpshm.h
index ea54a54..80934e0 100644
--- a/ntpshm.h
+++ b/ntpshm.h
@@ -21,11 +21,6 @@
 
 #include "servo.h"
 
-/**
- * The number of the SHM segment that will be used by newly created servo
- */
-extern int ntpshm_segment;
-
-struct servo *ntpshm_servo_create(void);
+struct servo *ntpshm_servo_create(struct config *cfg);
 
 #endif
diff --git a/phc2sys.c b/phc2sys.c
index c2c611b..4088a91 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1227,6 +1227,7 @@ int main(int argc, char *argv[])
        int c, domain_number = 0, pps_fd = -1;
        int r, wait_sync = 0;
        int print_level = LOG_INFO, use_syslog = 1, verbose = 0;
+       int ntpshm_segment;
        double phc_rate, tmp;
        struct node node = {
                .sanity_freq_limit = 200000000,
@@ -1334,6 +1335,8 @@ int main(int argc, char *argv[])
                case 'M':
                        if (get_arg_val_i(c, optarg, &ntpshm_segment, INT_MIN, 
INT_MAX))
                                return -1;
+                       if (config_set_int(cfg, "ntpshm_segment", 
ntpshm_segment))
+                               return -1;
                        break;
                case 'u':
                        if (get_arg_val_ui(c, optarg, &node.stats_max_count,
diff --git a/ptp4l.c b/ptp4l.c
index b74cda6..b9982c8 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,8 +103,6 @@ static struct config cfg_settings = {
        .transport = TRANS_UDP_IPV4,
        .clock_servo = CLOCK_SERVO_PI,
 
-       .ntpshm_segment = &ntpshm_segment,
-
        .ptp_dst_mac = ptp_dst_mac,
        .p2p_dst_mac = p2p_dst_mac,
        .udp6_scope = &udp6_scope,
diff --git a/servo.c b/servo.c
index 0449223..9aab7f2 100644
--- a/servo.c
+++ b/servo.c
@@ -43,7 +43,7 @@ struct servo *servo_create(struct config *cfg, enum 
servo_type type,
                servo = linreg_servo_create(fadj);
                break;
        case CLOCK_SERVO_NTPSHM:
-               servo = ntpshm_servo_create();
+               servo = ntpshm_servo_create(cfg);
                break;
        case CLOCK_SERVO_NULLF:
                servo = nullf_servo_create();
-- 
2.1.4


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

Reply via email to