|
From: <wow...@us...> - 2015-10-16 19:49:25
|
Revision: 595
http://sourceforge.net/p/ptpd/code/595
Author: wowczarek
Date: 2015-10-16 19:49:23 +0000 (Fri, 16 Oct 2015)
Log Message:
-----------
- added descriptions to built-in templates
- support for (multiple) template files
global:template_files + default file
$datadir/ptpd/templates.conf for user's templates
- fixed ptpd not printing startup messages until
config is fully parsed, broken since 2.3.0
(explicitly set nondaemon for -C and -V)
- TODO file added to keep track of what's left
until each release is complete
Modified Paths:
--------------
trunk/src/dep/configdefaults.c
trunk/src/dep/configdefaults.h
trunk/src/dep/daemonconfig.c
trunk/src/dep/iniparser/dictionary.c
trunk/src/dep/iniparser/dictionary.h
trunk/src/dep/iniparser/iniparser.c
trunk/src/dep/iniparser/iniparser.h
trunk/src/dep/startup.c
trunk/src/dep/sys.c
Added Paths:
-----------
trunk/TODO
Added: trunk/TODO
===================================================================
--- trunk/TODO (rev 0)
+++ trunk/TODO 2015-10-16 19:49:23 UTC (rev 595)
@@ -0,0 +1,9 @@
+# not part of distribution - TODO notes to implement before next release
+
+2.3.1.1 / 2.3.2:
+
+- man page updates for template files
+- clock ID printed in reverse in L2 mode
+ with (grandmasterID present?)
+- complete built-in templates
+- add dummy or populated default template file
Modified: trunk/src/dep/configdefaults.c
===================================================================
--- trunk/src/dep/configdefaults.c 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/configdefaults.c 2015-10-16 19:49:23 UTC (rev 595)
@@ -1,5 +1,4 @@
-/*-
- * Copyright (c) 2013-2015 Wojciech Owczarek,
+/* Copyright (c) 2013-2015 Wojciech Owczarek,
*
* All Rights Reserved
*
@@ -38,6 +37,9 @@
#define CONFIG_ISTRUE(key) \
(iniparser_getboolean(dict,key,FALSE)==TRUE)
+#define CONFIG_ISSET(key) \
+ (strcmp(iniparser_getstring(dict, key, ""),"") != 0)
+
#define IS_QUIET()\
( CONFIG_ISTRUE("%quiet%:%quiet%") )
@@ -50,7 +52,7 @@
static const ConfigTemplate configTemplates[] = {
- { "g8265-e2e-master", {
+ { "g8265-e2e-master", "ITU-T G.8265.1 (Telecom profile) unicast master", {
{"ptpengine:preset", "masteronly"},
{"ptpengine:ip_mode", "unicast"},
{"ptpengine:unicast_negotiation", "y"},
@@ -65,7 +67,7 @@
{NULL}}
},
- { "g8265-e2e-slave", {
+ { "g8265-e2e-slave", "ITU-T G.8265.1 (Telecom profile) unicast slave", {
{"ptpengine:preset", "slaveonly"},
{"ptpengine:ip_mode", "unicast"},
{"ptpengine:unicast_negotiation", "y"},
@@ -75,7 +77,7 @@
{NULL}}
},
- { "layer2-p2p-master", {
+ { "layer2-p2p-master", "Layer 2 master using Peer to Peer", {
{"ptpengine:transport","ethernet"},
{"ptpengine:delay_mechanism","P2P"},
{"ptpengine:preset","masteronly"},
@@ -83,7 +85,7 @@
{NULL}}
},
- { "layer2-p2p-slave", {
+ { "layer2-p2p-slave", "Layer 2 slave running End to End", {
{"ptpengine:transport","ethernet"},
{"ptpengine:delay_mechanism","E2E"},
{"ptpengine:preset","slaveonly"},
@@ -91,7 +93,7 @@
{NULL}}
},
- { "valid-utc-properties", {
+ { "valid-utc-properties", "Basic property set to announce valid UTC, UTC offset and leap seconds", {
{"ptpengine:ptp_timescale","PTP"},
{"ptpengine:time_traceable","y"},
{"ptpengine:frequency_traceable","y"},
@@ -99,7 +101,7 @@
{NULL}}
},
- { "full-logging", {
+ { "full-logging", "Enable logging for all facilities (statistics, status, log file)", {
{"global:log_status", "y"},
{"global:status_file", "/var/run/ptpd2.status"},
{"global:statistics_log_interval", "1"},
@@ -112,7 +114,7 @@
{NULL}}
},
- { "full-logging-instance", {
+ { "full-logging-instance", "Logging for all facilities using 'instance' variable which user should provide", {
{"global:log_status", "y"},
{"global:status_file", "@rundir@/ptpd2.@instance@.status"},
{"global:statistics_log_interval", "1"},
@@ -133,13 +135,13 @@
/* template of a template looks like this... */
/*
- { "template-name", {
+ { "template-name", "template description", {
{"section:key","value"},
{"",""},
{NULL}}
},
- { "", {
+ { "", "", {
{"",""},
{"",""},
{NULL}}
@@ -488,53 +490,139 @@
return ret;
}
+/* Apply template search from dictionary src to dictionary dst */
+static int
+applyTemplateFromDictionary(dictionary *dict, dictionary *src, char *search, int overwrite) {
+ char *key, *value, *pos;
+ int i = 0;
+ int found;
+
+ /* -1 on not found, 0+ on actual applies */
+ found = -1;
+
+ for(i=0; i<src->n; i++) {
+ key = src->key[i];
+ value = src->val[i];
+ pos = strstr(key, ":");
+ if(value != NULL && pos != NULL) {
+ *pos = '\0';
+ pos++;
+ if(!strcmp(search, key) && (strstr(pos,":") != NULL)) {
+ if(found < 0) found = 0;
+ if( overwrite || !CONFIG_ISSET(pos)) {
+ DBG("template %s setting %s to %s\n", search, pos, value);
+ dictionary_set(dict, pos, value);
+ found++;
+ }
+ }
+ /* reverse the damage - no need for strdup() */
+ pos--;
+ *pos = ':';
+ }
+ }
+
+ return found;
+
+}
+
+static void loadFileList(dictionary *dict, char *list) {
+
+ char* stash;
+ char* text_;
+ char* text__;
+ char *filename;
+
+ if(dict == NULL) return;
+ if(!strlen(list)) return;
+
+ text_=strdup(list);
+
+ for(text__=text_;; text__=NULL) {
+ filename=strtok_r(text__,", ;\t",&stash);
+ if(filename==NULL) break;
+ if(!iniparser_merge_file(dict, filename,1)) {
+ ERROR("Could not load template file %s\n", filename);
+ } else {
+ INFO("Loaded template file %s\n",filename);
+ }
+ }
+
+ if(text_ != NULL) {
+ free(text_);
+ }
+
+}
+
/* split list to tokens, look for each template and apply it if found */
int
-applyConfigTemplates(char *templateNames, dictionary *dict) {
+applyConfigTemplates(dictionary *target, char *templateNames, char *files) {
ConfigTemplate *template = NULL;
TemplateOption *option = NULL;
char *templateName = NULL;
- Boolean found = 0;
+ int iFound = -1;
+ int fFound = -1;
+ dictionary *fileDict;
+ dictionary *dict;
+
char* stash;
char* text_;
char* text__;
- if(dict == NULL) {
+ if(target == NULL) {
return 0;
}
- if(strlen(templateNames)==0) return 0;
+ if(!strlen(templateNames)) return 0;
+ fileDict = dictionary_new(0);
+ dict = dictionary_new(0);
+//INFO("tf: %s",DEFAULT_TEMPLATE_FILE);
+ loadFileList(fileDict, DEFAULT_TEMPLATE_FILE);
+ loadFileList(fileDict, files);
+
text_=strdup(templateNames);
for(text__=text_;; text__=NULL) {
+ iFound = -1;
+ fFound = -1;
+
+ /* apply from built-in templates */
templateName=strtok_r(text__,", ;\t",&stash);
if(templateName==NULL) break;
- found = 0;
template = (ConfigTemplate*)configTemplates;
while(template->name != NULL) {
if(!strcmp(template->name, templateName)) {
- DBG("Loading config template %s\n", template->name);
+ if(iFound < 0) iFound = 0;
+ DBG("Loading built-in config template %s\n", template->name);
option = (TemplateOption*)template->options;
while(option->name != NULL) {
dictionary_set(dict, option->name, option->value);
DBG("----> %s = %s",option->name, option->value);
option++;
+ iFound++;
}
- found = 1;
- if (!IS_QUIET()) NOTICE("Applied configuration template \"%s\"\n", templateName);
break;
}
template++;
}
- if(!found) {
- if (!IS_QUIET()) WARNING("Configuration template \"%s\" not found\n", templateName);
+ /* apply from previously loaded files */
+ fFound = applyTemplateFromDictionary(dict, fileDict, templateName, 1);
+
+ if (!IS_QUIET()) {
+ if((iFound < 0) && (fFound < 0)) {
+ WARNING("Configuration template \"%s\" not found\n", templateName);
+ } else {
+ if(iFound < 0) iFound = 0;
+ if(fFound < 0) fFound = 0;
+ NOTICE("Applied configuration template \"%s\" (%d matches)\n", templateName,
+ iFound + fFound);
+ }
}
}
@@ -543,6 +631,10 @@
free(text_);
}
+ /* preserve existing settings */
+ dictionary_merge(dict, target, 0 , !IS_QUIET(), NULL);
+ dictionary_del(&fileDict);
+ dictionary_del(&dict);
return 0;
}
@@ -553,17 +645,18 @@
ConfigTemplate *template = NULL;
TemplateOption *option = NULL;
-
+ printf("\n");
template = (ConfigTemplate*)configTemplates;
while(template->name != NULL) {
- printf("Template: %s\n\n", template->name);
+ printf(" Template: %s\n", template->name);
+ printf("Description: %s\n\n", template->description);
option = (TemplateOption*)template->options;
while(option->name != NULL) {
printf("\t\t%s=\"%s\"\n", option->name, option->value);
option++;
}
template++;
- printf("\n");
+ printf("\n-\n\n");
}
}
Modified: trunk/src/dep/configdefaults.h
===================================================================
--- trunk/src/dep/configdefaults.h 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/configdefaults.h 2015-10-16 19:49:23 UTC (rev 595)
@@ -12,6 +12,8 @@
#include <stddef.h>
#include "iniparser/iniparser.h"
+#define DEFAULT_TEMPLATE_FILE DATADIR"/"PACKAGE_NAME"/templates.conf"
+
typedef struct {
char * name;
char * value;
@@ -19,6 +21,7 @@
typedef struct {
char * name;
+ char * description;
TemplateOption options[100];
} ConfigTemplate;
@@ -42,7 +45,7 @@
};
void loadDefaultSettings( RunTimeOpts* rtOpts );
-int applyConfigTemplates(char *templateNames, dictionary *dict);
+int applyConfigTemplates(dictionary *dict, char *templateNames, char *files);
PtpEnginePreset getPtpPreset(int presetNumber, RunTimeOpts* rtOpts);
void dumpConfigTemplates();
Modified: trunk/src/dep/daemonconfig.c
===================================================================
--- trunk/src/dep/daemonconfig.c 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/daemonconfig.c 2015-10-16 19:49:23 UTC (rev 595)
@@ -830,6 +830,7 @@
}
+
/**
* Iterate through dictionary dict (template) and check for keys in source
* that are not present in the template - display only.
@@ -870,6 +871,7 @@
* Therefore loadDefaultSettings should normally be used before parseConfig
*/
+
/*-
* WARNING: for ease of use, a limited number of keys is set
* via getopt in loadCommanLineOptions(). When renaming settings, make sure
@@ -900,13 +902,19 @@
/*
* apply the configuration template(s) as statically defined in configdefaults.c
- * The list of templates is a comma, space or tab separated names. Any templates
- * are applied before anything else: so any settings after this can override
+ * and in template files. The list of templates and files is comma, space or tab separated.
+ * names. Any templates are applied before anything else: so any settings after this can override
*/
if (CONFIG_ISPRESENT("global:config_templates")) {
- applyConfigTemplates(dictionary_get(dict, "global:config_templates", ""), dict);
+ applyConfigTemplates(
+ dict,
+ dictionary_get(dict, "global:config_templates", ""),
+ dictionary_get(dict, "global:template_files", "")
+ );
+
/* also set the template names in the target dictionary */
dictionary_set(target, "global:config_templates", dictionary_get(dict, "global:config_templates", ""));
+ dictionary_set(target, "global:template_files", dictionary_get(dict, "global:template_files", ""));
}
parseUserVariables(dict, target);
@@ -2304,7 +2312,7 @@
/* make sure the %x% special keys are unset */
HELP_END();
- dictionary_merge( dict, *target, 0, NULL);
+ dictionary_merge( dict, *target, 0, 0, NULL);
dictionary_del(&dict);
return TRUE;
@@ -2663,10 +2671,12 @@
return FALSE;
/* run in foreground */
case 'C':
+ rtOpts->nonDaemon=1;
dictionary_set(dict,"global:foreground", "Y");
break;
/* verbose mode */
case 'V':
+ rtOpts->nonDaemon=1;
dictionary_set(dict,"global:foreground", "Y");
dictionary_set(dict,"global:verbose_foreground", "Y");
break;
Modified: trunk/src/dep/iniparser/dictionary.c
===================================================================
--- trunk/src/dep/iniparser/dictionary.c 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/iniparser/dictionary.c 2015-10-16 19:49:23 UTC (rev 595)
@@ -435,13 +435,15 @@
return ;
}
-int dictionary_merge(dictionary* source, dictionary* dest, int warn, const char* warnStr)
+int dictionary_merge(dictionary* source, dictionary* dest, int overwrite, int warn, const char* warnStr)
{
int i = 0;
+ int clobber = 1;
if( source == NULL || dest == NULL) return -1;
+ if(warnStr == NULL) warnStr = "";
for(i = 0; i < source->n; i++) {
if(source->key[i] == NULL)
@@ -450,20 +452,28 @@
if((source->val[i] == NULL) || (strlen(source->val[i])==0))
continue;
/* no need to warn for settings whose value will not change */
- if(warn && (strcmp(dictionary_get(dest,source->key[i],""),"") != 0) &&
+ if((strcmp(dictionary_get(dest,source->key[i],""),"") != 0) &&
(strcmp(dictionary_get(dest,source->key[i],""),source->val[i]) != 0)) {
- WARNING("Warning: %s=\"%s\" : setting will be overwritten with value \"%s\" %s\n",
- source->key[i], dictionary_get(dest,source->key[i],""),
- source->val[i], warnStr);
+ if(!overwrite && warn) {
+ WARNING("Warning: %s=\"%s\" : value \"%s\" takes priority %s\n",
+ source->key[i], source->val[i],
+ dictionary_get(dest,source->key[i],""), warnStr);
+ }
+ clobber = 1;
+ if(!overwrite) {
+ clobber = 0;
+ }
}
- if ( dictionary_set( dest, source->key[i], source->val[i]) != 0)
- return -1;
+ if (clobber) {
+ if(dictionary_set( dest, source->key[i], source->val[i]) != 0) {
+ return -1;
+ }
+ }
}
return 0;
}
-
/* Test code */
#ifdef TESTDIC
#define NVALS 20000
Modified: trunk/src/dep/iniparser/dictionary.h
===================================================================
--- trunk/src/dep/iniparser/dictionary.h 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/iniparser/dictionary.h 2015-10-16 19:49:23 UTC (rev 595)
@@ -184,6 +184,6 @@
/*--------------------------------------------------------------------------*/
void dictionary_dump(dictionary * d, FILE * out);
-int dictionary_merge(dictionary * source, dictionary * dest, int warn, const char* warnStr);
+int dictionary_merge(dictionary * source, dictionary * dest, int overwrite, int warn, const char* warnStr);
#endif
Modified: trunk/src/dep/iniparser/iniparser.c
===================================================================
--- trunk/src/dep/iniparser/iniparser.c 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/iniparser/iniparser.c 2015-10-16 19:49:23 UTC (rev 595)
@@ -735,6 +735,23 @@
return dict ;
}
+
+int iniparser_merge_file(dictionary *dict, const char *filename, int overwrite) {
+
+ dictionary *src;
+
+ if ((src = iniparser_load(filename)) == NULL) {
+ return 0;
+ }
+
+ dictionary_merge(src, dict, overwrite, 0, NULL);
+
+ dictionary_del(&src);
+
+ return 1;
+
+}
+
/*-------------------------------------------------------------------------*/
/**
@brief Free all memory associated to an ini dictionary
Modified: trunk/src/dep/iniparser/iniparser.h
===================================================================
--- trunk/src/dep/iniparser/iniparser.h 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/iniparser/iniparser.h 2015-10-16 19:49:23 UTC (rev 595)
@@ -291,6 +291,10 @@
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame);
+int iniparser_merge_file(dictionary *dict, const char * filename, int overwrite);
+
+dictionary * iniparser_load_list(const char* list);
+
/*-------------------------------------------------------------------------*/
/**
@brief Free all memory associated to an ini dictionary
Modified: trunk/src/dep/startup.c
===================================================================
--- trunk/src/dep/startup.c 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/startup.c 2015-10-16 19:49:23 UTC (rev 595)
@@ -170,7 +170,7 @@
dictionary_del(&tmpConfig);
goto end;
}
- dictionary_merge(rtOpts->cliConfig, tmpConfig, 1, "from command line");
+ dictionary_merge(rtOpts->cliConfig, tmpConfig, 0, 1, "from command line");
/* Load default config to fill in the blanks in the config file */
RunTimeOpts tmpOpts;
loadDefaultSettings(&tmpOpts);
@@ -716,14 +716,14 @@
/* config file settings overwrite all others, except for empty strings */
INFO("Loading configuration file: %s\n",rtOpts->configFile);
if(loadConfigFile(&rtOpts->candidateConfig, rtOpts)) {
- dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, "from command line");
+ dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 0, 1, "from command line");
} else {
*ret = 1;
- dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, "from command line");
+ dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 0, 1, "from command line");
goto configcheck;
}
} else {
- dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, "from command line");
+ dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 0, 1, "from command line");
}
/**
* This is where the final checking of the candidate settings container happens.
Modified: trunk/src/dep/sys.c
===================================================================
--- trunk/src/dep/sys.c 2015-10-15 04:11:00 UTC (rev 594)
+++ trunk/src/dep/sys.c 2015-10-16 19:49:23 UTC (rev 595)
@@ -440,7 +440,10 @@
{
extern RunTimeOpts rtOpts;
extern Boolean startupInProgress;
- va_list ap;
+ va_list ap , ap1;
+
+ va_copy(ap1, ap);
+ va_start(ap1, format);
va_start(ap, format);
#ifdef RUNTIME_DEBUG
@@ -450,17 +453,19 @@
#endif
/* log level filter */
- if(priority > rtOpts.logLevel)
+ if(priority > rtOpts.logLevel) {
goto end;
-
+ }
/* If we're using a log file and the message has been written OK, we're done*/
if(rtOpts.eventLog.logEnabled && rtOpts.eventLog.logFP != NULL) {
if(writeMessage(rtOpts.eventLog.logFP, &rtOpts.eventLog.lastHash, priority, format, ap) > 0) {
maintainLogSize(&rtOpts.eventLog);
if(!startupInProgress)
goto end;
- else
+ else {
+ rtOpts.eventLog.lastHash = 0;
goto std_err;
+ }
}
}
@@ -487,17 +492,21 @@
syslogOpened = TRUE;
}
vsyslog(priority, format, ap);
- if (!startupInProgress)
+ if (!startupInProgress) {
goto end;
- else
+ }
+ else {
+ rtOpts.eventLog.lastHash = 0;
goto std_err;
+ }
}
std_err:
- va_start(ap, format);
+
/* Either all else failed or we're running in foreground - or we also log to stderr */
- writeMessage(stderr, &rtOpts.eventLog.lastHash, priority, format, ap);
+ writeMessage(stderr, &rtOpts.eventLog.lastHash, priority, format, ap1);
end:
+ va_end(ap1);
va_end(ap);
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|