|
|
905b4d |
From a2fbe2b9de23e91835c10153d048c1b0c5ec7fee Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
905b4d |
Date: Fri, 3 Oct 2014 16:09:38 +0200
|
|
|
905b4d |
Subject: [PATCH 06/22] UTIL: Use a custom PID_PATH and DB_PATH when unit
|
|
|
905b4d |
testing server.c
|
|
|
905b4d |
|
|
|
905b4d |
server.c used hardcoded PID_PATH and DB_PATH from config.h. Normally,
|
|
|
905b4d |
this path resides in a system directory (like /var/) and should not be
|
|
|
905b4d |
written to by tests. In order to specify a different one for tests, we
|
|
|
905b4d |
need to conditionalize normal builds and unit test builds.
|
|
|
905b4d |
|
|
|
905b4d |
Reviewed-by: Pavel Reichl <preichl@redhat.com>
|
|
|
905b4d |
---
|
|
|
905b4d |
src/util/server.c | 35 +++++++++++++++++++++++++++++++----
|
|
|
905b4d |
1 file changed, 31 insertions(+), 4 deletions(-)
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/util/server.c b/src/util/server.c
|
|
|
905b4d |
index a908470cdcf2cb85a6742e44905ae12d136c83d5..03f4b9588e6c5322d9b68b8cac90128bcb5cfcb6 100644
|
|
|
905b4d |
--- a/src/util/server.c
|
|
|
905b4d |
+++ b/src/util/server.c
|
|
|
905b4d |
@@ -411,6 +411,32 @@ errno_t server_common_rotate_logs(struct confdb_ctx *confdb,
|
|
|
905b4d |
return EOK;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
+static const char *get_db_path(void)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+#ifdef UNIT_TESTING
|
|
|
905b4d |
+#ifdef TEST_DB_PATH
|
|
|
905b4d |
+ return TEST_DB_PATH;
|
|
|
905b4d |
+#else
|
|
|
905b4d |
+ #error "TEST_DB_PATH must be defined when unit testing server.c!"
|
|
|
905b4d |
+#endif /* TEST_DB_PATH */
|
|
|
905b4d |
+#else
|
|
|
905b4d |
+ return DB_PATH;
|
|
|
905b4d |
+#endif /* UNIT_TESTING */
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
+static const char *get_pid_path(void)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+#ifdef UNIT_TESTING
|
|
|
905b4d |
+#ifdef TEST_PID_PATH
|
|
|
905b4d |
+ return TEST_PID_PATH;
|
|
|
905b4d |
+#else
|
|
|
905b4d |
+ #error "TEST_PID_PATH must be defined when unit testing server.c!"
|
|
|
905b4d |
+#endif /* TEST_PID_PATH */
|
|
|
905b4d |
+#else
|
|
|
905b4d |
+ return PID_PATH;
|
|
|
905b4d |
+#endif
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
int server_setup(const char *name, int flags,
|
|
|
905b4d |
uid_t uid, gid_t gid,
|
|
|
905b4d |
const char *conf_entry,
|
|
|
905b4d |
@@ -468,10 +494,10 @@ int server_setup(const char *name, int flags,
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
if (flags & FLAGS_PID_FILE) {
|
|
|
905b4d |
- ret = pidfile(PID_PATH, name);
|
|
|
905b4d |
+ ret = pidfile(get_pid_path(), name);
|
|
|
905b4d |
if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_FATAL_FAILURE, "Error creating pidfile: %s/%s! "
|
|
|
905b4d |
- "(%d [%s])\n", PID_PATH, name, ret, strerror(ret));
|
|
|
905b4d |
+ DEBUG(SSSDBG_FATAL_FAILURE, "Error creating pidfile: %s/%s.pid! "
|
|
|
905b4d |
+ "(%d [%s])\n", get_pid_path(), name, ret, strerror(ret));
|
|
|
905b4d |
return ret;
|
|
|
905b4d |
}
|
|
|
905b4d |
}
|
|
|
905b4d |
@@ -513,7 +539,8 @@ int server_setup(const char *name, int flags,
|
|
|
905b4d |
ctx->parent_pid = getppid();
|
|
|
905b4d |
ctx->event_ctx = event_ctx;
|
|
|
905b4d |
|
|
|
905b4d |
- conf_db = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
|
|
|
905b4d |
+ conf_db = talloc_asprintf(ctx, "%s/%s",
|
|
|
905b4d |
+ get_db_path(), CONFDB_FILE);
|
|
|
905b4d |
if (conf_db == NULL) {
|
|
|
905b4d |
DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory, aborting!\n");
|
|
|
905b4d |
return ENOMEM;
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|