[asterisk-commits] rizzo: trunk r94168 - in /trunk: include/asterisk/ main/ res/snmp/ utils/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Dec 20 03:55:10 CST 2007
Author: rizzo
Date: Thu Dec 20 03:55:05 2007
New Revision: 94168
URL: http://svn.digium.com/view/asterisk?view=rev&rev=94168
Log:
modify http://svn.digium.com/view/asterisk?view=rev&rev=93603
so that paths and filename are writable by asterisk.c without
causing segfaults.
This involves defining the variables as const char *,
and having them point to as static, writable buffer
defined in asterisk.c
On passing, fix some errors in using these variables
in some files in utils/ , and in res/snmp/agent.c
which was redefining a variable without using paths.h
(not applicable to 1.4)
Modified:
trunk/include/asterisk/paths.h
trunk/main/asterisk.c
trunk/res/snmp/agent.c
trunk/utils/ael_main.c
trunk/utils/conf2ael.c
trunk/utils/extconf.c
Modified: trunk/include/asterisk/paths.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/paths.h?view=diff&rev=94168&r1=94167&r2=94168
==============================================================================
--- trunk/include/asterisk/paths.h (original)
+++ trunk/include/asterisk/paths.h Thu Dec 20 03:55:05 2007
@@ -18,22 +18,22 @@
#ifndef _ASTERISK_PATHS_H
#define _ASTERISK_PATHS_H
-extern const char ast_config_AST_CONFIG_DIR[PATH_MAX];
-extern const char ast_config_AST_CONFIG_FILE[PATH_MAX];
-extern const char ast_config_AST_MODULE_DIR[PATH_MAX];
-extern const char ast_config_AST_SPOOL_DIR[PATH_MAX];
-extern const char ast_config_AST_MONITOR_DIR[PATH_MAX];
-extern const char ast_config_AST_VAR_DIR[PATH_MAX];
-extern const char ast_config_AST_DATA_DIR[PATH_MAX];
-extern const char ast_config_AST_LOG_DIR[PATH_MAX];
-extern const char ast_config_AST_AGI_DIR[PATH_MAX];
-extern const char ast_config_AST_DB[PATH_MAX];
-extern const char ast_config_AST_KEY_DIR[PATH_MAX];
-extern const char ast_config_AST_PID[PATH_MAX];
-extern const char ast_config_AST_SOCKET[PATH_MAX];
-extern const char ast_config_AST_RUN_DIR[PATH_MAX];
-extern const char ast_config_AST_RUN_GROUP[PATH_MAX];
-extern const char ast_config_AST_RUN_USER[PATH_MAX];
-extern const char ast_config_AST_SYSTEM_NAME[20];
+extern const char *ast_config_AST_CONFIG_DIR;
+extern const char *ast_config_AST_CONFIG_FILE;
+extern const char *ast_config_AST_MODULE_DIR;
+extern const char *ast_config_AST_SPOOL_DIR;
+extern const char *ast_config_AST_MONITOR_DIR;
+extern const char *ast_config_AST_VAR_DIR;
+extern const char *ast_config_AST_DATA_DIR;
+extern const char *ast_config_AST_LOG_DIR;
+extern const char *ast_config_AST_AGI_DIR;
+extern const char *ast_config_AST_DB;
+extern const char *ast_config_AST_KEY_DIR;
+extern const char *ast_config_AST_PID;
+extern const char *ast_config_AST_SOCKET;
+extern const char *ast_config_AST_RUN_DIR;
+extern const char *ast_config_AST_RUN_GROUP;
+extern const char *ast_config_AST_RUN_USER;
+extern const char *ast_config_AST_SYSTEM_NAME;
#endif /* _ASTERISK_PATHS_H */
Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=94168&r1=94167&r2=94168
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Thu Dec 20 03:55:05 2007
@@ -200,27 +200,52 @@
static int ast_el_read_history(char *);
static int ast_el_write_history(char *);
-const char ast_config_AST_CONFIG_DIR[PATH_MAX];
-const char ast_config_AST_CONFIG_FILE[PATH_MAX];
-const char ast_config_AST_MODULE_DIR[PATH_MAX];
-const char ast_config_AST_SPOOL_DIR[PATH_MAX];
-const char ast_config_AST_MONITOR_DIR[PATH_MAX];
-const char ast_config_AST_VAR_DIR[PATH_MAX];
-const char ast_config_AST_DATA_DIR[PATH_MAX];
-const char ast_config_AST_LOG_DIR[PATH_MAX];
-const char ast_config_AST_AGI_DIR[PATH_MAX];
-const char ast_config_AST_DB[PATH_MAX];
-const char ast_config_AST_KEY_DIR[PATH_MAX];
-const char ast_config_AST_PID[PATH_MAX];
-const char ast_config_AST_SOCKET[PATH_MAX];
-const char ast_config_AST_RUN_DIR[PATH_MAX];
-const char ast_config_AST_RUN_USER[PATH_MAX];
-const char ast_config_AST_RUN_GROUP[PATH_MAX];
-static const char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
-static const char ast_config_AST_CTL_OWNER[PATH_MAX] = "\0";
-static const char ast_config_AST_CTL_GROUP[PATH_MAX] = "\0";
-static const char ast_config_AST_CTL[PATH_MAX] = "asterisk.ctl";
-const char ast_config_AST_SYSTEM_NAME[20] = "";
+struct _cfg_paths {
+ char config_dir[PATH_MAX];
+ char module_dir[PATH_MAX];
+ char spool_dir[PATH_MAX];
+ char monitor_dir[PATH_MAX];
+ char var_dir[PATH_MAX];
+ char data_dir[PATH_MAX];
+ char log_dir[PATH_MAX];
+ char agi_dir[PATH_MAX];
+ char run_dir[PATH_MAX];
+ char key_dir[PATH_MAX];
+
+ char config_file[PATH_MAX];
+ char db_path[PATH_MAX];
+ char pid_path[PATH_MAX];
+ char socket_path[PATH_MAX];
+ char run_user[PATH_MAX];
+ char run_group[PATH_MAX];
+ char system_name[128];
+};
+
+static struct _cfg_paths cfg_paths;
+
+const char *ast_config_AST_CONFIG_DIR = cfg_paths.config_dir;
+const char *ast_config_AST_CONFIG_FILE = cfg_paths.config_file;
+const char *ast_config_AST_MODULE_DIR = cfg_paths.module_dir;
+const char *ast_config_AST_SPOOL_DIR = cfg_paths.spool_dir;
+const char *ast_config_AST_MONITOR_DIR = cfg_paths.monitor_dir;
+const char *ast_config_AST_VAR_DIR = cfg_paths.var_dir;
+const char *ast_config_AST_DATA_DIR = cfg_paths.data_dir;
+const char *ast_config_AST_LOG_DIR = cfg_paths.log_dir;
+const char *ast_config_AST_AGI_DIR = cfg_paths.agi_dir;
+const char *ast_config_AST_KEY_DIR = cfg_paths.key_dir;
+const char *ast_config_AST_RUN_DIR = cfg_paths.run_dir;
+
+const char *ast_config_AST_DB = cfg_paths.db_path;
+const char *ast_config_AST_PID = cfg_paths.pid_path;
+const char *ast_config_AST_SOCKET = cfg_paths.socket_path;
+const char *ast_config_AST_RUN_USER = cfg_paths.run_user;
+const char *ast_config_AST_RUN_GROUP = cfg_paths.run_group;
+const char *ast_config_AST_SYSTEM_NAME = cfg_paths.system_name;
+
+static char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
+static char ast_config_AST_CTL_OWNER[PATH_MAX] = "\0";
+static char ast_config_AST_CTL_GROUP[PATH_MAX] = "\0";
+static char ast_config_AST_CTL[PATH_MAX] = "asterisk.ctl";
extern const char *ast_build_hostname;
extern const char *ast_build_kernel;
@@ -2423,20 +2448,19 @@
cfg = ast_config_load(config, config_flags);
/* init with buildtime config */
-#define _SETVAR(dst, src) ast_copy_string((char *)dst, src, sizeof(dst))
- _SETVAR(ast_config_AST_CONFIG_DIR, DEFAULT_CONFIG_DIR);
- _SETVAR(ast_config_AST_SPOOL_DIR, DEFAULT_SPOOL_DIR);
- _SETVAR(ast_config_AST_MODULE_DIR, DEFAULT_MODULE_DIR);
- snprintf((char *)ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", ast_config_AST_SPOOL_DIR);
- _SETVAR(ast_config_AST_VAR_DIR, DEFAULT_VAR_DIR);
- _SETVAR(ast_config_AST_DATA_DIR, DEFAULT_DATA_DIR);
- _SETVAR(ast_config_AST_LOG_DIR, DEFAULT_LOG_DIR);
- _SETVAR(ast_config_AST_AGI_DIR, DEFAULT_AGI_DIR);
- _SETVAR(ast_config_AST_DB, DEFAULT_DB);
- _SETVAR(ast_config_AST_KEY_DIR, DEFAULT_KEY_DIR);
- _SETVAR(ast_config_AST_PID, DEFAULT_PID);
- _SETVAR(ast_config_AST_SOCKET, DEFAULT_SOCKET);
- _SETVAR(ast_config_AST_RUN_DIR, DEFAULT_RUN_DIR);
+ ast_copy_string(cfg_paths.config_dir, DEFAULT_CONFIG_DIR, sizeof(cfg_paths.config_dir));
+ ast_copy_string(cfg_paths.spool_dir, DEFAULT_SPOOL_DIR, sizeof(cfg_paths.spool_dir));
+ ast_copy_string(cfg_paths.module_dir, DEFAULT_MODULE_DIR, sizeof(cfg_paths.module_dir));
+ snprintf(cfg_paths.monitor_dir, sizeof(cfg_paths.monitor_dir) - 1, "%s/monitor", cfg_paths.spool_dir);
+ ast_copy_string(cfg_paths.var_dir, DEFAULT_VAR_DIR, sizeof(cfg_paths.var_dir));
+ ast_copy_string(cfg_paths.data_dir, DEFAULT_DATA_DIR, sizeof(cfg_paths.data_dir));
+ ast_copy_string(cfg_paths.log_dir, DEFAULT_LOG_DIR, sizeof(cfg_paths.log_dir));
+ ast_copy_string(cfg_paths.agi_dir, DEFAULT_AGI_DIR, sizeof(cfg_paths.agi_dir));
+ ast_copy_string(cfg_paths.db_path, DEFAULT_DB, sizeof(cfg_paths.db_path));
+ ast_copy_string(cfg_paths.key_dir, DEFAULT_KEY_DIR, sizeof(cfg_paths.key_dir));
+ ast_copy_string(cfg_paths.pid_path, DEFAULT_PID, sizeof(cfg_paths.pid_path));
+ ast_copy_string(cfg_paths.socket_path, DEFAULT_SOCKET, sizeof(cfg_paths.socket_path));
+ ast_copy_string(cfg_paths.run_dir, DEFAULT_RUN_DIR, sizeof(cfg_paths.run_dir));
/* no asterisk.conf? no problem, use buildtime config! */
if (!cfg) {
@@ -2445,45 +2469,45 @@
for (v = ast_variable_browse(cfg, "files"); v; v = v->next) {
if (!strcasecmp(v->name, "astctlpermissions"))
- _SETVAR(ast_config_AST_CTL_PERMISSIONS, v->value);
+ ast_copy_string(ast_config_AST_CTL_PERMISSIONS, v->value, sizeof(ast_config_AST_CTL_PERMISSIONS));
else if (!strcasecmp(v->name, "astctlowner"))
- _SETVAR(ast_config_AST_CTL_OWNER, v->value);
+ ast_copy_string(ast_config_AST_CTL_OWNER, v->value, sizeof(ast_config_AST_CTL_OWNER));
else if (!strcasecmp(v->name, "astctlgroup"))
- _SETVAR(ast_config_AST_CTL_GROUP, v->value);
+ ast_copy_string(ast_config_AST_CTL_GROUP, v->value, sizeof(ast_config_AST_CTL_GROUP));
else if (!strcasecmp(v->name, "astctl"))
- _SETVAR(ast_config_AST_CTL, v->value);
+ ast_copy_string(ast_config_AST_CTL, v->value, sizeof(ast_config_AST_CTL));
}
for (v = ast_variable_browse(cfg, "directories"); v; v = v->next) {
if (!strcasecmp(v->name, "astetcdir")) {
- _SETVAR(ast_config_AST_CONFIG_DIR, v->value);
+ ast_copy_string(cfg_paths.config_dir, v->value, sizeof(cfg_paths.config_dir));
} else if (!strcasecmp(v->name, "astspooldir")) {
- _SETVAR(ast_config_AST_SPOOL_DIR, v->value);
- snprintf((char *)ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", v->value);
+ ast_copy_string(cfg_paths.spool_dir, v->value, sizeof(cfg_paths.spool_dir));
+ snprintf(cfg_paths.monitor_dir, sizeof(cfg_paths.monitor_dir) - 1, "%s/monitor", v->value);
} else if (!strcasecmp(v->name, "astvarlibdir")) {
- _SETVAR(ast_config_AST_VAR_DIR, v->value);
+ ast_copy_string(cfg_paths.var_dir, v->value, sizeof(cfg_paths.var_dir));
if (!found.dbdir)
- snprintf((char *)ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
+ snprintf(cfg_paths.db_path, sizeof(cfg_paths.db_path), "%s/astdb", v->value);
} else if (!strcasecmp(v->name, "astdbdir")) {
- snprintf((char *)ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
+ snprintf(cfg_paths.db_path, sizeof(cfg_paths.db_path), "%s/astdb", v->value);
found.dbdir = 1;
} else if (!strcasecmp(v->name, "astdatadir")) {
- _SETVAR(ast_config_AST_DATA_DIR, v->value);
+ ast_copy_string(cfg_paths.data_dir, v->value, sizeof(cfg_paths.data_dir));
if (!found.keydir)
- snprintf((char *)ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
+ snprintf(cfg_paths.key_dir, sizeof(cfg_paths.key_dir), "%s/keys", v->value);
} else if (!strcasecmp(v->name, "astkeydir")) {
- snprintf((char *)ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
+ snprintf(cfg_paths.key_dir, sizeof(cfg_paths.key_dir), "%s/keys", v->value);
found.keydir = 1;
} else if (!strcasecmp(v->name, "astlogdir")) {
- _SETVAR(ast_config_AST_LOG_DIR, v->value);
+ ast_copy_string(cfg_paths.log_dir, v->value, sizeof(cfg_paths.log_dir));
} else if (!strcasecmp(v->name, "astagidir")) {
- _SETVAR(ast_config_AST_AGI_DIR, v->value);
+ ast_copy_string(cfg_paths.agi_dir, v->value, sizeof(cfg_paths.agi_dir));
} else if (!strcasecmp(v->name, "astrundir")) {
- snprintf((char *)ast_config_AST_PID, sizeof(ast_config_AST_PID), "%s/%s", v->value, "asterisk.pid");
- snprintf((char *)ast_config_AST_SOCKET, sizeof(ast_config_AST_SOCKET), "%s/%s", v->value, ast_config_AST_CTL);
- _SETVAR(ast_config_AST_RUN_DIR, v->value);
+ snprintf(cfg_paths.pid_path, sizeof(cfg_paths.pid_path), "%s/%s", v->value, "asterisk.pid");
+ snprintf(cfg_paths.socket_path, sizeof(cfg_paths.socket_path), "%s/%s", v->value, ast_config_AST_CTL);
+ ast_copy_string(cfg_paths.run_dir, v->value, sizeof(cfg_paths.run_dir));
} else if (!strcasecmp(v->name, "astmoddir")) {
- _SETVAR(ast_config_AST_MODULE_DIR, v->value);
+ ast_copy_string(cfg_paths.module_dir, v->value, sizeof(cfg_paths.module_dir));
}
}
@@ -2566,19 +2590,19 @@
set_ulimit(option_maxfiles);
/* What user to run as */
} else if (!strcasecmp(v->name, "runuser")) {
- _SETVAR(ast_config_AST_RUN_USER, v->value);
+ ast_copy_string(cfg_paths.run_user, v->value, sizeof(cfg_paths.run_user));
/* What group to run as */
} else if (!strcasecmp(v->name, "rungroup")) {
- _SETVAR(ast_config_AST_RUN_GROUP, v->value);
+ ast_copy_string(cfg_paths.run_group, v->value, sizeof(cfg_paths.run_group));
} else if (!strcasecmp(v->name, "systemname")) {
- _SETVAR(ast_config_AST_SYSTEM_NAME, v->value);
+ ast_copy_string(cfg_paths.system_name, v->value, sizeof(cfg_paths.system_name));
} else if (!strcasecmp(v->name, "autosystemname")) {
if (ast_true(v->value)) {
if (!gethostname(hostname, sizeof(hostname) - 1))
- _SETVAR(ast_config_AST_SYSTEM_NAME, hostname);
+ ast_copy_string(cfg_paths.system_name, hostname, sizeof(cfg_paths.system_name));
else {
if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)){
- _SETVAR(ast_config_AST_SYSTEM_NAME, "localhost");
+ ast_copy_string(cfg_paths.system_name, "localhost", sizeof(cfg_paths.system_name));
}
ast_log(LOG_ERROR, "Cannot obtain hostname for this system. Using '%s' instead.\n", ast_config_AST_SYSTEM_NAME);
}
@@ -2767,7 +2791,7 @@
xarg = optarg;
break;
case 'C':
- _SETVAR(ast_config_AST_CONFIG_FILE, optarg);
+ ast_copy_string(cfg_paths.config_file, optarg, sizeof(cfg_paths.config_file));
ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG);
break;
case 'I':
Modified: trunk/res/snmp/agent.c
URL: http://svn.digium.com/view/asterisk/trunk/res/snmp/agent.c?view=diff&rev=94168&r1=94167&r2=94168
==============================================================================
--- trunk/res/snmp/agent.c (original)
+++ trunk/res/snmp/agent.c Thu Dec 20 03:55:05 2007
@@ -51,6 +51,7 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include "asterisk/paths.h" /* need ast_config_AST_SOCKET */
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
@@ -70,9 +71,6 @@
int header_simple_table(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **, int);
int register_sysORTable(oid *, size_t, const char *);
int unregister_sysORTable(oid *, size_t);
-
-/* Not defined in header files */
-extern char ast_config_AST_SOCKET[];
/* Forward declaration */
static void init_asterisk_mib(void);
Modified: trunk/utils/ael_main.c
URL: http://svn.digium.com/view/asterisk/trunk/utils/ael_main.c?view=diff&rev=94168&r1=94167&r2=94168
==============================================================================
--- trunk/utils/ael_main.c (original)
+++ trunk/utils/ael_main.c Thu Dec 20 03:55:05 2007
@@ -82,8 +82,11 @@
int conts=0, extens=0, priors=0;
char last_exten[18000];
-const char ast_config_AST_CONFIG_DIR[PATH_MAX];
-const char ast_config_AST_VAR_DIR[PATH_MAX];
+
+static char config_dir[PATH_MAX];
+static char var_dir[PATH_MAX];
+const char *ast_config_AST_CONFIG_DIR = config_dir;
+const char *ast_config_AST_VAR_DIR = var_dir;
void ast_cli_register_multiple(void);
int ast_add_extension2(struct ast_context *con,
@@ -514,14 +517,14 @@
}
if( use_curr_dir ) {
- strcpy((char *)ast_config_AST_CONFIG_DIR, ".");
+ strcpy(config_dir, ".");
localized_use_local_dir();
}
else {
- strcpy((char *)ast_config_AST_CONFIG_DIR, "/etc/asterisk");
+ strcpy(config_dir, "/etc/asterisk");
localized_use_conf_dir();
}
- strcpy((char *)ast_config_AST_VAR_DIR, "/var/lib/asterisk");
+ strcpy(var_dir, "/var/lib/asterisk");
if( dump_extensions ) {
dumpfile = fopen("extensions.conf.aeldump","w");
Modified: trunk/utils/conf2ael.c
URL: http://svn.digium.com/view/asterisk/trunk/utils/conf2ael.c?view=diff&rev=94168&r1=94167&r2=94168
==============================================================================
--- trunk/utils/conf2ael.c (original)
+++ trunk/utils/conf2ael.c Thu Dec 20 03:55:05 2007
@@ -29,19 +29,13 @@
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
+#include "asterisk/paths.h" /* CONFIG_DIR */
#include <locale.h>
#include <ctype.h>
#if !defined(SOLARIS) && !defined(__CYGWIN__)
#include <err.h>
#endif
-#include <errno.h>
#include <regex.h>
-#include <limits.h>
#include "asterisk.h"
#include "asterisk/pbx.h"
@@ -59,11 +53,12 @@
#include "asterisk/pval.h"
#include "asterisk/extconf.h"
+const char *ast_config_AST_CONFIG_DIR = "/etc/asterisk"; /* placeholder */
+
void get_start_stop(unsigned int *word, int bitsperword, int totalbits, int *start, int *end);
int all_bits_set(unsigned int *word, int bitsperword, int totalbits);
extern char *days[];
extern char *months[];
-const char ast_config_AST_CONFIG_DIR[PATH_MAX];
char *config = "extensions.conf";
Modified: trunk/utils/extconf.c
URL: http://svn.digium.com/view/asterisk/trunk/utils/extconf.c?view=diff&rev=94168&r1=94167&r2=94168
==============================================================================
--- trunk/utils/extconf.c (original)
+++ trunk/utils/extconf.c Thu Dec 20 03:55:05 2007
@@ -25,6 +25,7 @@
*/
#include "asterisk/compat.h"
+#include "asterisk/paths.h" /* we use AST_CONFIG_DIR */
#include <errno.h>
#include <time.h>
@@ -53,7 +54,6 @@
# include <glob.h>
#endif
-static const char ast_config_AST_CONFIG_DIR[PATH_MAX] = {"/etc/asterisk"};
#define AST_API_MODULE 1 /* gimme the inline defs! */
struct ast_channel
{
More information about the asterisk-commits
mailing list