More Solaris compatibility fixes

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@289543 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2010-09-30 17:50:52 +00:00
parent 37ad96f682
commit f48a6f6cfe
5 changed files with 61 additions and 12 deletions

View File

@@ -98,6 +98,7 @@ char *ast_strptime_locale(const char *s, const char *format, struct ast_tm *tm,
* between checks to verify whether a timezone file has changed. This routine * between checks to verify whether a timezone file has changed. This routine
* forces the monitor thread to wakeup immediately and check the timezone files. * forces the monitor thread to wakeup immediately and check the timezone files.
*/ */
void ast_localtime_wakeup_monitor(void); struct ast_test;
void ast_localtime_wakeup_monitor(struct ast_test *info);
#endif /* _ASTERISK_LOCALTIME_H */ #endif /* _ASTERISK_LOCALTIME_H */

View File

@@ -52,6 +52,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <float.h> #include <float.h>
#include <stdlib.h>
#ifdef HAVE_INOTIFY #ifdef HAVE_INOTIFY
#include <sys/inotify.h> #include <sys/inotify.h>
#elif defined(HAVE_KQUEUE) #elif defined(HAVE_KQUEUE)
@@ -71,6 +72,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/strings.h" #include "asterisk/strings.h"
#include "asterisk/linkedlists.h" #include "asterisk/linkedlists.h"
#include "asterisk/utils.h" #include "asterisk/utils.h"
#include "asterisk/test.h"
#ifndef lint #ifndef lint
#ifndef NOID #ifndef NOID
@@ -105,6 +107,13 @@ static char __attribute__((unused)) elsieid[] = "@(#)localtime.c 8.5";
static const char gmt[] = "GMT"; static const char gmt[] = "GMT";
static const struct timeval WRONG = { 0, 0 }; static const struct timeval WRONG = { 0, 0 };
#ifdef TEST_FRAMEWORK
/* Protected from multiple threads by the zonelist lock */
static struct ast_test *test = NULL;
#else
struct ast_test;
#endif
/*! \note /*! \note
* The DST rules to use if TZ has no rules and we can't load TZDEFRULES. * The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
* We default to US rules as of 1999-08-17. * We default to US rules as of 1999-08-17.
@@ -545,7 +554,11 @@ static void *notify_daemon(void *data)
stat(name, &st); stat(name, &st);
lstat(name, &lst); lstat(name, &lst);
if (st.st_mtime > cur->mtime[0] || lst.st_mtime > cur->mtime[1]) { if (st.st_mtime > cur->mtime[0] || lst.st_mtime > cur->mtime[1]) {
ast_log(LOG_NOTICE, "Removing cached TZ entry '%s' because underlying file changed.\n", name); if (test) {
ast_test_status_update(test, "Removing cached TZ entry '%s' because underlying file changed. (%ld != %ld) or (%ld != %ld)\n", name, st.st_mtime, cur->mtime[0], lst.st_mtime, cur->mtime[1]);
} else {
ast_log(LOG_NOTICE, "Removing cached TZ entry '%s' because underlying file changed.\n", name);
}
AST_LIST_REMOVE_CURRENT(list); AST_LIST_REMOVE_CURRENT(list);
ast_free(cur); ast_free(cur);
continue; continue;
@@ -581,12 +594,18 @@ static void add_notify(struct state *sp, const char *path)
} }
#endif #endif
void ast_localtime_wakeup_monitor(void) void ast_localtime_wakeup_monitor(struct ast_test *info)
{ {
if (inotify_thread != AST_PTHREADT_NULL) { if (inotify_thread != AST_PTHREADT_NULL) {
AST_LIST_LOCK(&zonelist); AST_LIST_LOCK(&zonelist);
#ifdef TEST_FRAMEWORK
test = info;
#endif
pthread_kill(inotify_thread, SIGURG); pthread_kill(inotify_thread, SIGURG);
ast_cond_wait(&initialization, &(&zonelist)->lock); ast_cond_wait(&initialization, &(&zonelist)->lock);
#ifdef TEST_FRAMEWORK
test = NULL;
#endif
AST_LIST_UNLOCK(&zonelist); AST_LIST_UNLOCK(&zonelist);
} }
} }
@@ -1386,8 +1405,16 @@ static const struct state *ast_tzset(const char *zone)
{ {
struct state *sp; struct state *sp;
if (ast_strlen_zero(zone)) if (ast_strlen_zero(zone)) {
#ifdef SOLARIS
zone = getenv("TZ");
if (ast_strlen_zero(zone)) {
zone = "GMT";
}
#else
zone = "/etc/localtime"; zone = "/etc/localtime";
#endif
}
AST_LIST_LOCK(&zonelist); AST_LIST_LOCK(&zonelist);
AST_LIST_TRAVERSE(&zonelist, sp, list) { AST_LIST_TRAVERSE(&zonelist, sp, list) {

View File

@@ -3029,11 +3029,20 @@ int AST_OPTIONAL_API_NAME(ast_agi_register)(struct ast_module *mod, agi_command
*((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd); *((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd);
*((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd); *((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd);
*((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC; *((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC;
#elif (!defined(HAVE_NULLSAFE_PRINTF)) #endif
*((char **) &cmd->summary) = ast_strdup(""); #ifndef HAVE_NULLSAFE_PRINTF
*((char **) &cmd->usage) = ast_strdup(""); if (!cmd->summary) {
*((char **) &cmd->syntax) = ast_strdup(""); *((char **) &cmd->summary) = ast_strdup("");
*((char **) &cmd->seealso) = ast_strdup(""); }
if (!cmd->usage) {
*((char **) &cmd->usage) = ast_strdup("");
}
if (!cmd->syntax) {
*((char **) &cmd->syntax) = ast_strdup("");
}
if (!cmd->seealso) {
*((char **) &cmd->seealso) = ast_strdup("");
}
#endif #endif
} }
@@ -3802,15 +3811,18 @@ AST_TEST_DEFINE(test_agi_null_docs)
} }
if (ast_agi_register(ast_module_info->self, &noop_command) == 0) { if (ast_agi_register(ast_module_info->self, &noop_command) == 0) {
ast_test_status_update(test, "Unable to register testnoop command, because res_agi is not loaded.\n");
return AST_TEST_NOT_RUN; return AST_TEST_NOT_RUN;
} }
#ifndef HAVE_NULLSAFE_PRINTF #ifndef HAVE_NULLSAFE_PRINTF
/* Test for condition without actually crashing Asterisk */ /* Test for condition without actually crashing Asterisk */
if (noop_command.usage == NULL) { if (noop_command.usage == NULL) {
ast_test_status_update(test, "AGI testnoop usage was not updated properly.\n");
res = AST_TEST_FAIL; res = AST_TEST_FAIL;
} }
if (noop_command.syntax == NULL) { if (noop_command.syntax == NULL) {
ast_test_status_update(test, "AGI testnoop syntax was not updated properly.\n");
res = AST_TEST_FAIL; res = AST_TEST_FAIL;
} }
#endif #endif

View File

@@ -73,7 +73,13 @@ AST_TEST_DEFINE(test_timezone_watch)
} }
snprintf(tzfile, sizeof(tzfile), "%s/test", tmpdir); snprintf(tzfile, sizeof(tzfile), "%s/test", tmpdir);
for (type = 0; type < 2; type++) { for (type = 0; type <
#ifdef SOLARIS
1 /* Solaris doesn't use symlinks for timezones */
#else
2
#endif
; type++) {
ast_test_status_update(test, "Executing %s test...\n", type == 0 ? "deletion" : "symlink"); ast_test_status_update(test, "Executing %s test...\n", type == 0 ? "deletion" : "symlink");
for (i = 0; i < ARRAY_LEN(zones); i++) { for (i = 0; i < ARRAY_LEN(zones); i++) {
int system_res; int system_res;
@@ -81,8 +87,8 @@ AST_TEST_DEFINE(test_timezone_watch)
if ((system_res = ast_safe_system(syscmd))) { if ((system_res = ast_safe_system(syscmd))) {
ast_log(LOG_WARNING, "system(%s) returned non-zero: %d\n", syscmd, system_res); ast_log(LOG_WARNING, "system(%s) returned non-zero: %d\n", syscmd, system_res);
} }
ast_localtime_wakeup_monitor(); ast_localtime_wakeup_monitor(test);
sched_yield(); ast_test_status_update(test, "Querying timezone %s\n", tzfile);
ast_localtime(&tv, &atm[i], tzfile); ast_localtime(&tv, &atm[i], tzfile);
if (i != 0) { if (i != 0) {
if (atm[i].tm_hour == atm[i - 1].tm_hour) { if (atm[i].tm_hour == atm[i - 1].tm_hour) {

View File

@@ -325,15 +325,18 @@ AST_TEST_DEFINE(agi_loaded_test)
#endif #endif
if (ast_agi_register(ast_module_info->self, &noop_command) == AST_OPTIONAL_API_UNAVAILABLE) { if (ast_agi_register(ast_module_info->self, &noop_command) == AST_OPTIONAL_API_UNAVAILABLE) {
ast_test_status_update(test, "Unable to register testnoop command, because res_agi is not loaded.\n");
return AST_TEST_FAIL; return AST_TEST_FAIL;
} }
#ifndef HAVE_NULLSAFE_PRINTF #ifndef HAVE_NULLSAFE_PRINTF
/* Test for condition without actually crashing Asterisk */ /* Test for condition without actually crashing Asterisk */
if (noop_command.usage == NULL) { if (noop_command.usage == NULL) {
ast_test_status_update(test, "AGI testnoop usage was not updated properly.\n");
res = AST_TEST_FAIL; res = AST_TEST_FAIL;
} }
if (noop_command.syntax == NULL) { if (noop_command.syntax == NULL) {
ast_test_status_update(test, "AGI testnoop syntax was not updated properly.\n");
res = AST_TEST_FAIL; res = AST_TEST_FAIL;
} }
#endif #endif