summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2014-10-03 16:09:38 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-10-20 21:43:47 +0200
commit3fd66df4813d1410c1a6187c80e3a23395b14aed (patch)
tree46e7fcf6ed71941ec6deae618f81427eee4110a5 /src/util
parent4546e283498ffe2511cb566b9159714c671e326b (diff)
downloadsssd-3fd66df4813d1410c1a6187c80e3a23395b14aed.tar.gz
sssd-3fd66df4813d1410c1a6187c80e3a23395b14aed.tar.xz
sssd-3fd66df4813d1410c1a6187c80e3a23395b14aed.zip
UTIL: Use a custom PID_PATH and DB_PATH when unit testing server.c
server.c used hardcoded PID_PATH and DB_PATH from config.h. Normally, this path resides in a system directory (like /var/) and should not be written to by tests. In order to specify a different one for tests, we need to conditionalize normal builds and unit test builds. Reviewed-by: Pavel Reichl <preichl@redhat.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/server.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/util/server.c b/src/util/server.c
index a908470cd..03f4b9588 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -411,6 +411,32 @@ errno_t server_common_rotate_logs(struct confdb_ctx *confdb,
return EOK;
}
+static const char *get_db_path(void)
+{
+#ifdef UNIT_TESTING
+#ifdef TEST_DB_PATH
+ return TEST_DB_PATH;
+#else
+ #error "TEST_DB_PATH must be defined when unit testing server.c!"
+#endif /* TEST_DB_PATH */
+#else
+ return DB_PATH;
+#endif /* UNIT_TESTING */
+}
+
+static const char *get_pid_path(void)
+{
+#ifdef UNIT_TESTING
+#ifdef TEST_PID_PATH
+ return TEST_PID_PATH;
+#else
+ #error "TEST_PID_PATH must be defined when unit testing server.c!"
+#endif /* TEST_PID_PATH */
+#else
+ return PID_PATH;
+#endif
+}
+
int server_setup(const char *name, int flags,
uid_t uid, gid_t gid,
const char *conf_entry,
@@ -468,10 +494,10 @@ int server_setup(const char *name, int flags,
}
if (flags & FLAGS_PID_FILE) {
- ret = pidfile(PID_PATH, name);
+ ret = pidfile(get_pid_path(), name);
if (ret != EOK) {
- DEBUG(SSSDBG_FATAL_FAILURE, "Error creating pidfile: %s/%s! "
- "(%d [%s])\n", PID_PATH, name, ret, strerror(ret));
+ DEBUG(SSSDBG_FATAL_FAILURE, "Error creating pidfile: %s/%s.pid! "
+ "(%d [%s])\n", get_pid_path(), name, ret, strerror(ret));
return ret;
}
}
@@ -513,7 +539,8 @@ int server_setup(const char *name, int flags,
ctx->parent_pid = getppid();
ctx->event_ctx = event_ctx;
- conf_db = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
+ conf_db = talloc_asprintf(ctx, "%s/%s",
+ get_db_path(), CONFDB_FILE);
if (conf_db == NULL) {
DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory, aborting!\n");
return ENOMEM;