From 6fea20e2972e8858a7bd246905bbe23708023be7 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Mon, 17 Oct 2011 09:54:07 +0000 Subject: [PATCH] When path to the configuration file is relative, obtain full path, so we can always find the file, even after daemonizing and changing working directory to /. MFC after: 1 week --- sbin/hastd/hastd.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sbin/hastd/hastd.c b/sbin/hastd/hastd.c index d21f7f69f3fe..e4cd52022ec1 100644 --- a/sbin/hastd/hastd.c +++ b/sbin/hastd/hastd.c @@ -1168,6 +1168,22 @@ main(int argc, char *argv[]) pjdlog_errno(LOG_WARNING, "Unable to open or create pidfile"); } + /* + * When path to the configuration file is relative, obtain full path, + * so we can always find the file, even after daemonizing and changing + * working directory to /. + */ + if (cfgpath[0] != '/') { + const char *newcfgpath; + + newcfgpath = realpath(cfgpath, NULL); + if (newcfgpath == NULL) { + pjdlog_exit(EX_CONFIG, + "Unable to obtain full path of %s", cfgpath); + } + cfgpath = newcfgpath; + } + cfg = yy_config_parse(cfgpath, true); PJDLOG_ASSERT(cfg != NULL);