device_parser: Fall back to read /etc/cdba

After attempting to read .cdba, fall back to read /etc/cdba - to make it
possible to provide system wide configuration for a multiple users.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson
2020-06-29 00:02:16 -07:00
parent d094208e7c
commit a2a11706df
3 changed files with 16 additions and 5 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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