summaryrefslogtreecommitdiffstats
path: root/dyndhcpd.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2016-03-15 15:40:02 +0100
committerGravatar Christian Hesse <mail@eworm.de>2016-03-15 15:40:02 +0100
commit0db83386f2effba1be59ed301d9b400b57207b0a (patch)
tree9932d18d83ff72b2319c60fcb1a76c45d318378f /dyndhcpd.c
parentfcd79f550b23182705d86ca3520db5ea60e37453 (diff)
downloaddyndhcpd-0db83386f2effba1be59ed301d9b400b57207b0a.tar.gz
dyndhcpd-0db83386f2effba1be59ed301d9b400b57207b0a.tar.zst
add built in config for fallback
Diffstat (limited to 'dyndhcpd.c')
-rw-r--r--dyndhcpd.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/dyndhcpd.c b/dyndhcpd.c
index 5cbfb79..134e845 100644
--- a/dyndhcpd.c
+++ b/dyndhcpd.c
@@ -47,7 +47,7 @@ int main(int argc, char ** argv) {
char * template = NULL;
FILE * templatefile;
- const char * templatefilename = NULL;
+ const char * templatefilename = CONFIG_TEMPLATE;
char * config = NULL;
FILE * configfile;
char * configfilename = NULL;
@@ -209,26 +209,25 @@ int main(int argc, char ** argv) {
}
/* open the template for reading */
- if (templatefilename == NULL)
- templatefilename = CONFIG_TEMPLATE;
- if ((templatefile = fopen(templatefilename, "r")) == NULL) {
- fprintf(stderr, "Failed opening config template for reading.\n");
- goto out;
- }
-
- /* seek to the and so we know the file size */
- fseek(templatefile, 0, SEEK_END);
- fsize = ftell(templatefile);
- fseek(templatefile, 0, SEEK_SET);
-
- /* allocate memory and read file */
- template = malloc(fsize + 1);
- if ((fread(template, fsize, 1, templatefile)) != 1) {
- fprintf(stderr, "Failed reading config template.\n");
- goto out;
+ if ((templatefile = fopen(templatefilename, "r")) != NULL) {
+ /* seek to the and so we know the file size */
+ fseek(templatefile, 0, SEEK_END);
+ fsize = ftell(templatefile);
+ fseek(templatefile, 0, SEEK_SET);
+
+ /* allocate memory and read file */
+ template = malloc(fsize + 1);
+ if ((fread(template, fsize, 1, templatefile)) != 1) {
+ fprintf(stderr, "Failed reading config template.\n");
+ goto out;
+ }
+ fclose(templatefile);
+ template[fsize] = 0;
+ } else {
+ fprintf(stderr, "Failed opening config template for reading.\n"
+ "Using fallback to built in defaults, functionality is limited.\n");
+ template = strdup(FALLBACKCONFIG);
}
- fclose(templatefile);
- template[fsize] = 0;
/* replace strings with real values */
for (tmp = template; *tmp;) {