diff --git a/cdba-server.c b/cdba-server.c index 91bb375..a5fd932 100644 --- a/cdba-server.c +++ b/cdba-server.c @@ -287,7 +287,14 @@ int main(int argc, char **argv) signal(SIGPIPE, sigpipe_handler); - device_parser(".cdba"); + ret = device_parser(".cdba"); + if (ret) { + ret = device_parser("/etc/cdba"); + if (ret) { + fprintf(stderr, "device parser: unable to open config file\n"); + exit(1); + } + } watch_add_readfd(STDIN_FILENO, handle_stdin, NULL); diff --git a/device_parser.c b/device_parser.c index 2cc56a0..e6ce67a 100644 --- a/device_parser.c +++ b/device_parser.c @@ -145,7 +145,7 @@ static void parse_board(struct device_parser *dp) device_add(dev); } -void device_parser(const char *path) +int device_parser(const char *path) { struct device_parser dp; char key[TOKEN_LENGTH]; @@ -154,11 +154,13 @@ void device_parser(const char *path) fh = fopen(path, "r"); if (!fh) { fprintf(stderr, "device parser: unable to open %s\n", path); - exit(1); + return -1; } - if(!yaml_parser_initialize(&dp.parser)) + if(!yaml_parser_initialize(&dp.parser)) { fprintf(stderr, "device parser: failed to initialize parser\n"); + return -1; + } yaml_parser_set_input_file(&dp.parser, fh); @@ -188,4 +190,6 @@ void device_parser(const char *path) yaml_parser_delete(&dp.parser); fclose(fh); + + return 0; } diff --git a/device_parser.h b/device_parser.h index 1bf0615..2fcd770 100644 --- a/device_parser.h +++ b/device_parser.h @@ -1,6 +1,6 @@ #ifndef __DEVICE_PARSER_H__ #define __DEVICE_PARSER_H__ -void device_parser(const char *path); +int device_parser(const char *path); #endif