Respect sysconfdir for configuration file location

The sysconfdir is used if it exists, otherwise it fallbacks
to the previous default /etc.
This commit is contained in:
James Sanderson 2016-11-06 19:30:01 +00:00 • committed by Andrea Mazzoleni
parent 8f625f2be4
commit ee1aa840f1
5 changed files with 40 additions and 16 deletions

View file

@ -241,7 +241,13 @@ void config(char* conf, size_t conf_size, const char* argv0)
#else
(void)argv0;
pathcpy(conf, conf_size, "/etc/" PACKAGE ".conf");
#ifdef SYSCONFDIR
/* if it exists, give precedence at sysconfdir, usually /usr/local/etc */
if (access(SYSCONFDIR "/" PACKAGE ".conf", F_OK) == 0)
pathcpy(conf, conf_size, SYSCONFDIR "/" PACKAGE ".conf");
else /* otherwise fallback to plain /etc */
#endif
pathcpy(conf, conf_size, "/etc/" PACKAGE ".conf");
#endif
}