From 78a720f2b38459f5be1089f01e4b396e6167948a Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 25 Sep 2018 18:16:20 +0200 Subject: [PATCH] timemaster: Allow ptp4l-specific sections in [ptp4l.conf]. Remove > from beginning of lines specified in the *.conf sections in order to allow a ptp4l-specific section (e.g. [unicast_master_table]) to be included there. After inserting the lines to the generated ptp4l.conf, switch back to the [global] section. Signed-off-by: Miroslav Lichvar --- timemaster.8 | 10 +++++++--- timemaster.c | 28 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/timemaster.8 b/timemaster.8 index 7288972..2f92976 100644 --- a/timemaster.8 +++ b/timemaster.8 @@ -253,9 +253,13 @@ Specify extra options that should be added to all \fBptp4l\fR command lines. By default, \fB\-l 5\fR is added to the command lines. .SS [ptp4l.conf] -Settings specified in this section are copied directly to the configuration -files generated for all \fBptp4l\fR instances. There is no default content of -this section. +Settings specified in this section are copied directly to the global section of +the configuration files generated for all \fBptp4l\fR instances. There is no +default content of this section. + +Other sections (e.g. \fB[unicast_master_table]\fR) may be specified here, but +lines beginning with the bracket need to be prefixed with the \fB>\fR character +to prevent \fBtimemaster\fR from parsing it as a beginning of another section. .SH NOTES For best accuracy, \fBchronyd\fR is usually preferred over \fBntpd\fR, it also diff --git a/timemaster.c b/timemaster.c index 4ba921e..058678f 100644 --- a/timemaster.c +++ b/timemaster.c @@ -405,6 +405,23 @@ static int parse_timemaster_settings(char **settings, return 0; } +static char **parse_raw_settings(char **settings) +{ + char **setting, *s, **parsed_settings; + + parsed_settings = (char **)parray_new(); + + for (setting = settings; *setting; setting++) { + s = *setting; + /* Unescape lines beginning with '>' */ + if (s[0] == '>') + s++; + parray_append((void ***)&parsed_settings, xstrdup(s)); + } + + return parsed_settings; +} + static int parse_section(char **settings, char *name, struct timemaster_config *config) { @@ -451,8 +468,7 @@ static int parse_section(char **settings, char *name, if (settings_dst) { free_parray((void **)*settings_dst); - *settings_dst = (char **)parray_new(); - extend_string_array(settings_dst, settings); + *settings_dst = parse_raw_settings(settings); } return 0; @@ -802,9 +818,13 @@ 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_file->content = xstrdup("[global]\n"); - extend_config_string(&config_file->content, - config->ptp4l.settings); + if (*config->ptp4l.settings) { + extend_config_string(&config_file->content, + config->ptp4l.settings); + string_appendf(&config_file->content, "\n[global]\n"); + } extend_config_string(&config_file->content, source->ptp4l_settings); string_appendf(&config_file->content,