Index: main/config.c =================================================================== --- main/config.c (revision 188456) +++ main/config.c (working copy) @@ -47,6 +47,8 @@ #include "asterisk/app.h" #include "asterisk/astobj2.h" #include "asterisk/strings.h" /* for the ast_str_*() API */ +#include "asterisk/buildinfo.h" +#include "asterisk/ast_version.h" #define MAX_NESTED_COMMENTS 128 #define COMMENT_START ";--" @@ -1073,7 +1075,7 @@ if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE)) config_cache_attribute(configfile, ATTRIBUTE_EXEC, NULL, who_asked); snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%d%d.%ld", (int)now.tv_sec, (int)now.tv_usec, (long)pthread_self()); - snprintf(cmd, sizeof(cmd), "%s > %s 2>&1", cur, exec_file); + snprintf(cmd, sizeof(cmd),"export AST_SYSTEMNAME=\"%s\"; export AST_BUILD_HOST=\"%s\"; export AST_BUILD_DATE=\"%s\"; export AST_BUILD_KERNEL=\"%s\"; export AST_BUILD_MACHINE=\"%s\"; export AST_BUILD_OS=\"%s\"; export AST_BUILD_USER=\"%s\"; export AST_VERSION=\"%s\"; %s > %s 2>&1", ast_config_AST_SYSTEM_NAME, ast_build_hostname, ast_build_date, ast_build_kernel, ast_build_machine, ast_build_os, ast_build_user, ast_get_version(), cur, exec_file); ast_safe_system(cmd); cur = exec_file; } else { Index: funcs/func_build.c =================================================================== --- funcs/func_build.c (revision 0) +++ funcs/func_build.c (revision 0) @@ -0,0 +1,100 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 1999 - 2009, Digium, Inc. + * + * Mark Spencer + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * + * \brief build variables dialplan function + * + * \author Julian Lyndon-Smith + * \ingroup functions + */ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision:$") + +#include "asterisk/module.h" +#include "asterisk/channel.h" +#include "asterisk/pbx.h" +#include "asterisk/utils.h" +#include "asterisk/app.h" +#include "asterisk/buildinfo.h" +#include "asterisk/ast_version.h" + +static int buildinfo_read(struct ast_channel *chan, const char *cmd, char *data, + char *buf, size_t len) +{ + if (!chan) + return -1; + + if (!data) { + ast_log(LOG_ERROR, "Must specify build variable to get.\n"); + return -1; + } + + if (!strncasecmp("all", data, 3)) { + snprintf(buf, len, "%s,%s,%s,%s,%s,%s,%s", + ast_build_hostname,ast_build_kernel,ast_build_machine,ast_build_os,ast_build_date,ast_build_user,ast_get_version()); + } else if (!strncasecmp("hostname", data, 8)) { + ast_copy_string(buf, ast_build_hostname, len); + } else if (!strncasecmp("kernel", data, 6)) { + ast_copy_string(buf, ast_build_kernel, len); + } else if (!strncasecmp("machine", data, 7)) { + ast_copy_string(buf, ast_build_machine, len); + } else if (!strncasecmp("os", data, 2)) { + ast_copy_string(buf, ast_build_os, len); + } else if (!strncasecmp("date", data, 4)) { + ast_copy_string(buf, ast_build_date, len); + } else if (!strncasecmp("user", data, 4)) { + ast_copy_string(buf, ast_build_kernel, len); + } else if (!strncasecmp("version", data, 6)) { + ast_copy_string(buf, ast_get_version(), len); + } + return 0; +} + +static struct ast_custom_function build_function = { + .name = "AST_BUILD", + .synopsis = "Gets various build variables.", + .syntax = "AST_BUILD(variablename)", + .desc = + "Gets various build variables. The variables that are available are:\n" + "\n" + " all : build hostname,build kernel,build machine,build os,build date,build user,build version\n" + " hostname : build hostname\n" + " kernel : build kernel\n" + " machine : build machine\n" + " os : build os\n" + " date : build date\n" + " user : build user\n" + " version : build version\n", + .read = buildinfo_read, +}; + +static int unload_module(void) +{ + return ast_custom_function_unregister(&build_function); +} + +static int load_module(void) +{ + return ast_custom_function_register(&build_function); +} + +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Build variables dialplan function"); +