summaryrefslogtreecommitdiff
path: root/src/biruda.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-12-03 15:22:26 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-12-03 15:22:26 +0100
commit6d0a5d2c4e984fe08330865e2bc28402c7dc9775 (patch)
tree5105ae71ee275c77ab6c0f4ee98366b0dbed86de /src/biruda.c
parentf1e189bcfdedd95ad9b0a69adbc318f4e2edf740 (diff)
downloadbiruda-6d0a5d2c4e984fe08330865e2bc28402c7dc9775.tar.gz
biruda-6d0a5d2c4e984fe08330865e2bc28402c7dc9775.tar.bz2
added some worker and port config checks
Diffstat (limited to 'src/biruda.c')
-rw-r--r--src/biruda.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/biruda.c b/src/biruda.c
index 5f73aa5..ec48b26 100644
--- a/src/biruda.c
+++ b/src/biruda.c
@@ -63,7 +63,7 @@ static int test_config( const struct gengetopt_args_info *args_info )
return 0;
}
-static int conf_parse_worker_execution( cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result )
+static int conf_validate_worker_execution( cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result )
{
if( strcmp( value, "direct" ) == 0 ) {
*(worker_execution_mode_t *)result = WORKER_EXECUTION_DIRECT;
@@ -76,6 +76,28 @@ static int conf_parse_worker_execution( cfg_t *cfg, cfg_opt_t *opt, const char *
return 0;
}
+static int conf_validate_worker( cfg_t *cfg, cfg_opt_t *opt )
+{
+ cfg_t *worker = cfg_opt_getnsec( opt, cfg_opt_size( opt ) - 1 );
+
+ worker_execution_mode_t mode = (worker_execution_mode_t)cfg_getint( worker, "execution" );
+
+ switch( mode ) {
+ case WORKER_EXECUTION_DISABLED:
+ // skip, ok
+ break;
+
+ case WORKER_EXECUTION_DIRECT:
+ if( cfg_size( worker, "command" ) == 0 ) {
+ cfg_error( cfg, "missing required option 'command' for worker '%s'",
+ cfg_title( worker ) );
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
static int read_config( const char *filename, cfg_t **cfg )
{
cfg_opt_t opts_master[] = {
@@ -90,11 +112,11 @@ static int read_config( const char *filename, cfg_t **cfg )
cfg_opt_t opts_worker[] = {
CFG_STR( "control", 0, CFGF_NODEFAULT ),
- CFG_INT_CB( "execution", WORKER_EXECUTION_DIRECT, CFGF_NONE, conf_parse_worker_execution ),
- CFG_STR( "command", NULL, CFGF_NONE ),
+ CFG_INT_CB( "execution", WORKER_EXECUTION_DISABLED, CFGF_NONE, &conf_validate_worker_execution ),
+ CFG_STR( "command", NULL, CFGF_NODEFAULT ),
CFG_END( )
};
-
+
cfg_opt_t opts_webserver[] = {
CFG_STR( "host", (char *)DEFAULT_WEBSERVER_HOST, CFGF_NONE ),
CFG_INT( "port", DEFAULT_WEBSERVER_PORT, CFGF_NONE ),
@@ -111,6 +133,8 @@ static int read_config( const char *filename, cfg_t **cfg )
};
*cfg = cfg_init( opts, CFGF_NONE );
+
+ cfg_set_validate_func( *cfg, "worker", &conf_validate_worker );
switch( cfg_parse( *cfg, filename ) ) {
case CFG_FILE_ERROR: