diff --git a/loader.c b/loader.c index 960eda4c89ac4109e6d96f85834a21338278a472..03b6b018b08708ff4ec8720fab34e20dded51ce9 100755 --- a/loader.c +++ b/loader.c @@ -21,6 +21,7 @@ #include <asterisk/config.h> #include <asterisk/logger.h> #include <asterisk/channel.h> +#include <asterisk/term.h> #include <dlfcn.h> #include <asterisk/md5.h> #define __USE_GNU @@ -86,7 +87,7 @@ static struct loadupdate { struct loadupdate *next; } *updaters = NULL; -static pthread_mutex_t modlock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t modlock = AST_MUTEX_INITIALIZER; static struct module *module_list=NULL; @@ -158,11 +159,12 @@ int ast_load_resource(char *resource_name) int errors=0; int res; struct module *m; - int flags=0; + int flags=RTLD_NOW; char *val; char *key; int o; struct ast_config *cfg; + char tmp[80]; /* Keep the module file parsing silent */ o = option_verbose; if (strncasecmp(resource_name, "res_", 4)) { @@ -176,8 +178,8 @@ int ast_load_resource(char *resource_name) ast_destroy(cfg); } } else { - /* Resource modules are always loaded global */ - flags |= RTLD_GLOBAL; + /* Resource modules are always loaded global and lazy */ + flags = (RTLD_GLOBAL | RTLD_LAZY); } if (ast_pthread_mutex_lock(&modlock)) @@ -203,7 +205,7 @@ int ast_load_resource(char *resource_name) } else { snprintf(fn, sizeof(fn), "%s/%s", AST_MODULE_DIR, resource_name); } - m->lib = dlopen(fn, RTLD_NOW | flags); + m->lib = dlopen(fn, flags); if (!m->lib) { ast_log(LOG_WARNING, "%s\n", dlerror()); free(m); @@ -254,7 +256,7 @@ int ast_load_resource(char *resource_name) } if (!fully_booted) { if (option_verbose) - ast_verbose( " => (%s)\n", m->description()); + ast_verbose( " => (%s)\n", term_color(tmp, m->description(), COLOR_BROWN, COLOR_BLACK, sizeof(tmp))); if (option_console && !option_verbose) ast_verbose( "."); } else { @@ -296,6 +298,7 @@ int load_modules() { struct ast_config *cfg; struct ast_variable *v; + char tmp[80]; if (option_verbose) ast_verbose( "Asterisk Dynamic Loader Starting:\n"); cfg = ast_load(AST_MODULE_CONFIG); @@ -307,7 +310,7 @@ int load_modules() if (option_debug && !option_verbose) ast_log(LOG_DEBUG, "Loading module %s\n", v->value); if (option_verbose) { - ast_verbose( " [%s]", v->value); + ast_verbose( VERBOSE_PREFIX_1 "[%s]", term_color(tmp, v->value, COLOR_BRWHITE, 0, sizeof(tmp))); fflush(stdout); } if (ast_load_resource(v->value)) { @@ -356,7 +359,7 @@ int load_modules() if (option_debug && !option_verbose) ast_log(LOG_DEBUG, "Loading module %s\n", d->d_name); if (option_verbose) { - ast_verbose( VERBOSE_PREFIX_1 "[%s]", d->d_name); + ast_verbose( VERBOSE_PREFIX_1 "[%s]", term_color(tmp, d->d_name, COLOR_BRWHITE, 0, sizeof(tmp))); fflush(stdout); } if (ast_load_resource(d->d_name)) { diff --git a/term.c b/term.c new file mode 100755 index 0000000000000000000000000000000000000000..e42c152248cd53f697eaee2ae3c364abcbd9f7e4 --- /dev/null +++ b/term.c @@ -0,0 +1,124 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Channel Management + * + * Copyright (C) 1999, Mark Spencer + * + * Mark Spencer <markster@linux-support.net> + * + * This program is free software, distributed under the terms of + * the GNU General Public License + */ + +#include <stdio.h> +#include <stdlib.h> +#include <pthread.h> +#include <string.h> +#include <sys/time.h> +#include <signal.h> +#include <errno.h> +#include <unistd.h> +#include <asterisk/term.h> +#include <asterisk/options.h> +#include "asterisk.h" + +static int vt100compat = 0; + +static char prepdata[80] = ""; +static char enddata[80] = ""; +static char quitdata[80] = ""; + +int term_init(void) +{ + char *term = getenv("TERM"); + if (!term) + return 0; + if (!option_console || option_nocolor || !option_nofork) + return 0; + if (!strncasecmp(term, "linux", 5)) + vt100compat = 1; else + if (!strncasecmp(term, "xterm", 5)) + vt100compat = 1; else + if (!strncasecmp(term, "vt", 2)) + vt100compat = 1; + if (vt100compat) { + /* Make commands show up in nice colors */ + snprintf(prepdata, sizeof(prepdata), "%c[%d;%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN, COLOR_BLACK + 10); + snprintf(enddata, sizeof(enddata), "%c[%d;%d;%dm", ESC, ATTR_RESET, COLOR_WHITE, COLOR_BLACK + 10); + snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC); + } + return 0; +} + +char *term_color(char *outbuf, char *inbuf, int fgcolor, int bgcolor, int maxout) +{ + int attr=0; + char tmp[40]; + if (!vt100compat) { + strncpy(outbuf, inbuf, maxout -1); + return outbuf; + } + if (!fgcolor && !bgcolor) { + strncpy(outbuf, inbuf, maxout - 1); + return outbuf; + } + if ((fgcolor & 128) && (bgcolor & 128)) { + /* Can't both be highlighted */ + strncpy(outbuf, inbuf, maxout - 1); + return outbuf; + } + if (!bgcolor) + bgcolor = COLOR_BLACK; + + if (bgcolor) { + bgcolor &= ~128; + bgcolor += 10; + } + if (fgcolor & 128) { + attr = ATTR_BRIGHT; + fgcolor &= ~128; + } + if (fgcolor && bgcolor) { + snprintf(tmp, sizeof(tmp), "%d;%d", fgcolor, bgcolor); + } else if (bgcolor) { + snprintf(tmp, sizeof(tmp), "%d", bgcolor); + } else if (fgcolor) { + snprintf(tmp, sizeof(tmp), "%d", fgcolor); + } + if (attr) { + snprintf(outbuf, maxout, "%c[%d;%sm%s%c[0;%d;%dm", ESC, attr, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10); + } else { + snprintf(outbuf, maxout, "%c[%sm%s%c[0;%d;%dm", ESC, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10); + } + return outbuf; +} + +char *term_prompt(char *outbuf, char *inbuf, int maxout) +{ + if (!vt100compat) { + strncpy(outbuf, inbuf, maxout -1); + return outbuf; + } + snprintf(outbuf, maxout, "%c[%d;%d;%dm%c%c[%d;%d;%dm%s", + ESC, ATTR_BRIGHT, COLOR_BLUE, COLOR_BLACK + 10, + inbuf[0], + ESC, 0, COLOR_WHITE, COLOR_BLACK + 10, + inbuf + 1); + return outbuf; +} + +char *term_prep(void) +{ + return prepdata; +} + +char *term_end(void) +{ + return enddata; +} + +char *term_quit(void) +{ + return quitdata; +}