Replace the shm_segment number with a more general refclock_id and shift
by first_shm_index only in the SHM-specific context to allow other types
of refclocks to be used.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 timemaster.c | 48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/timemaster.c b/timemaster.c
index cafd3a3..9fea011 100644
--- a/timemaster.c
+++ b/timemaster.c
@@ -658,8 +658,9 @@ static char **get_ptp4l_command(struct program_config 
*config,
        return command;
 }
 
-static char **get_phc2sys_command(struct program_config *config, int domain,
-                                 int poll, int shm_segment, char *uds_path,
+static char **get_phc2sys_command(struct program_config *config,
+                                 struct timemaster_config *tconfig, int domain,
+                                 int poll, int refclock_id, char *uds_path,
                                  char *message_tag)
 {
        char **command = (char **)parray_new();
@@ -674,7 +675,9 @@ static char **get_phc2sys_command(struct program_config 
*config, int domain,
                      xstrdup("-t"), xstrdup(message_tag),
                      xstrdup("-n"), string_newf("%d", domain),
                      xstrdup("-E"), xstrdup("ntpshm"),
-                     xstrdup("-M"), string_newf("%d", shm_segment), NULL);
+                     xstrdup("-M"), string_newf("%d", refclock_id +
+                                                tconfig->first_shm_segment),
+                     NULL);
 
        return command;
 }
@@ -702,11 +705,13 @@ static void add_command(char **command, int command_group,
        parray_append((void ***)&script->command_groups, group);
 }
 
-static void add_shm_source(int shm_segment, int poll, int dpoll, double delay,
-                          char *ntp_options, char *prefix,
-                          struct timemaster_config *config, char **ntp_config)
+static void add_refclock_source(int refclock_id, int poll, int dpoll,
+                               double delay, char *ntp_options, char *prefix,
+                               struct timemaster_config *config,
+                               char **ntp_config)
 {
-       char *refid = get_refid(prefix, shm_segment);
+       int shm_segment = refclock_id + config->first_shm_segment;
+       char *refid = get_refid(prefix, refclock_id);
 
        switch (config->ntp_program) {
        case CHRONYD:
@@ -758,7 +763,7 @@ static int add_vclock(struct script *script, int 
pclock_index)
 }
 
 static int add_ptp_source(struct ptp_domain *source,
-                         struct timemaster_config *config, int *shm_segment,
+                         struct timemaster_config *config, int *refclock_id,
                          int *command_group, int ***allocated_phcs,
                          char **ntp_config, struct script *script)
 {
@@ -867,9 +872,9 @@ static int add_ptp_source(struct ptp_domain *source,
                }
 
                uds_path = string_newf("%s/ptp4l.%d.socket",
-                                      config->rundir, *shm_segment);
+                                      config->rundir, *refclock_id);
                uds_path2 = string_newf("%s/ptp4lro.%d.socket",
-                                       config->rundir, *shm_segment);
+                                       config->rundir, *refclock_id);
 
                message_tag = string_newf("[%d", source->domain);
                for (j = 0; interfaces[j]; j++)
@@ -879,7 +884,7 @@ static int add_ptp_source(struct ptp_domain *source,
 
                config_file = xmalloc(sizeof(*config_file));
                config_file->path = string_newf("%s/ptp4l.%d.conf",
-                                               config->rundir, *shm_segment);
+                                               config->rundir, *refclock_id);
 
                config_file->content = xstrdup("[global]\n");
                if (*config->ptp4l.settings) {
@@ -905,10 +910,10 @@ static int add_ptp_source(struct ptp_domain *source,
                                                    vclock_index, 1);
                        add_command(command, *command_group, script);
 
-                       command = get_phc2sys_command(&config->phc2sys,
+                       command = get_phc2sys_command(&config->phc2sys, config,
                                                      source->domain,
                                                      source->phc2sys_poll,
-                                                     *shm_segment, uds_path,
+                                                     *refclock_id, uds_path,
                                                      message_tag);
                        add_command(command, (*command_group)++, script);
                } else {
@@ -919,16 +924,18 @@ static int add_ptp_source(struct ptp_domain *source,
 
                        string_appendf(&config_file->content,
                                       "clock_servo ntpshm\n"
-                                      "ntpshm_segment %d\n", *shm_segment);
+                                      "ntpshm_segment %d\n",
+                                      *refclock_id + 
config->first_shm_segment);
                }
 
                parray_append((void ***)&script->configs, config_file);
 
-               add_shm_source(*shm_segment, source->ntp_poll,
-                              source->phc2sys_poll, source->delay,
-                              source->ntp_options, "PTP", config, ntp_config);
+               add_refclock_source(*refclock_id, source->ntp_poll,
+                                   source->phc2sys_poll, source->delay,
+                                   source->ntp_options, "PTP", config,
+                                   ntp_config);
 
-               (*shm_segment)++;
+               (*refclock_id)++;
 
                free(message_tag);
                free(uds_path);
@@ -1037,7 +1044,7 @@ static struct script *script_create(struct 
timemaster_config *config)
        struct source *source, **sources;
        struct config_file *ntp_config = NULL;
        int **allocated_phcs = (int **)parray_new();
-       int ret = 0, shm_segment, command_group = 0;
+       int ret = 0, refclock_id = 0, command_group = 0;
 
        script->vclocks = (struct phc_vclocks **)parray_new();
        script->configs = (struct config_file **)parray_new();
@@ -1047,7 +1054,6 @@ static struct script *script_create(struct 
timemaster_config *config)
        script->restart_groups = config->restart_processes;
 
        ntp_config = add_ntp_program(config, script, command_group++);
-       shm_segment = config->first_shm_segment;
 
        for (sources = config->sources; (source = *sources); sources++) {
                switch (source->type) {
@@ -1056,7 +1062,7 @@ static struct script *script_create(struct 
timemaster_config *config)
                                ret = 1;
                        break;
                case PTP_DOMAIN:
-                       if (add_ptp_source(&source->ptp, config, &shm_segment,
+                       if (add_ptp_source(&source->ptp, config, &refclock_id,
                                           &command_group, &allocated_phcs,
                                           &ntp_config->content, script))
                                ret = 1;
-- 
2.37.3



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

Reply via email to