diff --git a/src/apps/config/config.c b/src/apps/config/config.c
index 28d6bb5..5b8ea44 100644
--- a/src/apps/config/config.c
+++ b/src/apps/config/config.c
@@ -373,7 +373,7 @@ GetInstallParameters(void){
/* this is a little messy here due to the way the array works */
if (!config.domains && config.interactive) {
- config.domains = BongoJsonNodeNewArray(g_array_new(FALSE, FALSE, sizeof(char *)));
+ config.domains = BongoJsonNodeNewArray(BongoJsonArrayNew(4));
while (1) {
char *tmp = NULL;
GetInteractiveData(_("Mail Domains (one per line, blank line to finish):"), &tmp, "");
@@ -587,6 +587,7 @@ LoadDefaultStoreConfiguration(void)
pid_t store_pid;
StoreClient *client = NULL;
char *args[3];
+ unsigned int connect_attempt;
store_pid = fork();
if (store_pid < 0) {
@@ -607,8 +608,6 @@ LoadDefaultStoreConfiguration(void)
XplConsolePrintf(_("ERROR: Couldn't start the store!\n"));
exit(1);
} else { // parent
- XplDelay(1000); // FIXME: small hack, wait for store to start.
-
client = malloc(sizeof(StoreClient));
if (!client) {
XplConsolePrintf(_("ERROR: Out of memory\n"));
@@ -616,7 +615,12 @@ LoadDefaultStoreConfiguration(void)
goto storecleanup;
}
client->conn = NULL;
- client->conn = NMAPConnect("127.0.0.1", NULL);
+ for (connect_attempt = 0; connect_attempt < 100; connect_attempt++) {
+ client->conn = NMAPConnect("127.0.0.1", NULL);
+ if (client->conn)
+ break;
+ XplDelay(100);
+ }
if (!client->conn) {
XplConsolePrintf(_("ERROR: Could not connect to store\n"));
config.store_install_failed = TRUE;
@@ -1339,10 +1343,9 @@ main(int argc, char *argv[]) {
XplConsolePrintf(_("ERROR: --domain requires an argument.\n"));
return 1;
}
- if (!config.domains) {
- config.domains = BongoJsonNodeNewArray(g_array_new(FALSE, FALSE, sizeof(char *)));
- }
- BongoJsonArrayAppendString(BongoJsonNodeAsArray(config.domains), MemStrdup(argv[next_arg]));
+ if (!config.domains)
+ config.domains = BongoJsonNodeNewArray(BongoJsonArrayNew(4));
+ BongoJsonArrayAppendString(BongoJsonNodeAsArray(config.domains), argv[next_arg]);
} else if (!strcmp(arg, "--tls-name")) {
if (++next_arg >= argc) {
XplConsolePrintf(_("ERROR: --tls-name requires an argument.\n"));
@@ -1513,6 +1516,7 @@ main(int argc, char *argv[]) {
MemFree(config.admin_password);
}
if (config.domains) BongoJsonNodeFree(config.domains);
+ if (config.tls_names) BongoJsonNodeFree(config.tls_names);
if (config.configuration_bundle)
BongoJsonNodeFree(config.configuration_bundle);
diff --git a/src/libs/cal/CMakeLists.txt b/src/libs/cal/CMakeLists.txt
index 7bac8c6..169157a 100644
--- a/src/libs/cal/CMakeLists.txt
+++ b/src/libs/cal/CMakeLists.txt
@@ -25,3 +25,12 @@ target_link_libraries(bongocal
)
install(TARGETS bongocal DESTINATION ${LIB_INSTALL_DIR})
+
+if(BUILD_TESTING)
+ add_executable(cal-timezone-lifecycle-test
+ tests/timezone-lifecycle-test.c)
+ target_link_libraries(cal-timezone-lifecycle-test
+ bongocal)
+ add_test(NAME cal-timezone-lifecycle
+ COMMAND cal-timezone-lifecycle-test)
+endif()
diff --git a/src/libs/cal/bongo-cal-timezone.c b/src/libs/cal/bongo-cal-timezone.c
index f860a71..17f50b5 100644
--- a/src/libs/cal/bongo-cal-timezone.c
+++ b/src/libs/cal/bongo-cal-timezone.c
@@ -847,7 +847,10 @@ LoadSystemTimezones(FILE *f)
static void
UnloadSystemTimezones() {
- BongoHashtableDelete(systemTimezones);
+ if (systemTimezones) {
+ BongoHashtableDelete(systemTimezones);
+ systemTimezones = NULL;
+ }
}
static BOOL
@@ -937,6 +940,7 @@ CacheSystemTimezones(const char *cachedir)
dir = opendir(ZONEINFODIR);
if (!dir) {
printf("libbongocal: Couldn't find zoneinfo in %s\n", ZONEINFODIR);
+ return FALSE;
}
f = XplOpenTemp(cachedir, "wb", filename);
@@ -999,6 +1003,7 @@ BongoCalTimezoneInit(const char *cachedir)
}
if (LoadCachedTimezones(cachedir)) {
+ timezonesInitialized = TRUE;
return TRUE;
}
@@ -1007,12 +1012,19 @@ BongoCalTimezoneInit(const char *cachedir)
return FALSE;
}
- timezonesInitialized = TRUE;
+ if (!LoadCachedTimezones(cachedir)) {
+ return FALSE;
+ }
- return LoadCachedTimezones(cachedir);
+ timezonesInitialized = TRUE;
+ return TRUE;
}
void
BongoCalTimezoneDeInit() {
+ if (!timezonesInitialized) {
+ return;
+ }
UnloadCachedTimezones();
+ timezonesInitialized = FALSE;
}
diff --git a/src/libs/cal/tests/timezone-lifecycle-test.c b/src/libs/cal/tests/timezone-lifecycle-test.c
new file mode 100644
index 0000000..481ab6b
--- /dev/null
+++ b/src/libs/cal/tests/timezone-lifecycle-test.c
@@ -0,0 +1,38 @@
+/****************************************************************************
+ *
+ * Copyright (c) 2006 Novell, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you
+ * may find current contact information at www.novell.com.
+ *
+ ****************************************************************************/
+
+#include
+
+#include
+
+int
+main(void)
+{
+ const char *missing = "/bongo-test-missing-timezone-cache";
+
+ assert(BongoCalInit(missing) == FALSE);
+ BongoCalDeInit();
+ BongoCalDeInit();
+
+ assert(BongoCalInit(missing) == FALSE);
+ BongoCalDeInit();
+ return 0;
+}