From 0db83386f2effba1be59ed301d9b400b57207b0a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 15 Mar 2016 15:40:02 +0100 Subject: add built in config for fallback --- dyndhcpd.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'dyndhcpd.c') 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;) { -- cgit v1.2.3-54-g00ecf