FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Functions | Variables
switch_core.c File Reference
#include <switch.h>
#include <switch_ssl.h>
#include <switch_stun.h>
#include <switch_nat.h>
#include "private/switch_core_pvt.h"
#include <switch_curl.h>
#include <switch_private.h>
#include <errno.h>
#include <sqlite3.h>
#include "cc.h"
+ Include dependency graph for switch_core.c:

Go to the source code of this file.

Data Structures

struct  switch_ip_list_t
 
struct  system_thread_handle
 

Macros

#define BUFSIZE   1024
 

Functions

static void switch_load_core_config (const char *file)
 
static void send_heartbeat (void)
 
static void check_ip (void)
 
 SWITCH_STANDARD_SCHED_FUNC (heartbeat_callback)
 
 SWITCH_STANDARD_SCHED_FUNC (check_ip_callback)
 
switch_status_t switch_core_set_console (const char *console)
 Set the output console to the desired file. More...
 
FILE * switch_core_get_console (void)
 Get the output console. More...
 
void switch_core_screen_size (int *x, int *y)
 
FILE * switch_core_data_channel (switch_text_channel_t channel)
 Retrieve a FILE stream of a given text channel name. More...
 
void switch_core_remove_state_handler (const switch_state_handler_table_t *state_handler)
 
int switch_core_add_state_handler (const switch_state_handler_table_t *state_handler)
 
const
switch_state_handler_table_t
switch_core_get_state_handler (int index)
 
void switch_core_dump_variables (switch_stream_handle_t *stream)
 
const char * switch_core_get_hostname (void)
 
const char * switch_core_get_switchname (void)
 
char * switch_core_get_domain (switch_bool_t dup)
 
switch_status_t switch_core_get_variables (switch_event_t **event)
 
char * switch_core_get_variable (const char *varname)
 
char * switch_core_get_variable_dup (const char *varname)
 
char * switch_core_get_variable_pdup (const char *varname, switch_memory_pool_t *pool)
 
static void switch_core_unset_variables (void)
 
void switch_core_set_variable (const char *varname, const char *value)
 
switch_bool_t switch_core_set_var_conditional (const char *varname, const char *value, const char *val2)
 
char * switch_core_get_uuid (void)
 Retrieve the unique identifier from the core. More...
 
static void *SWITCH_THREAD_FUNC switch_core_service_thread (switch_thread_t *thread, void *obj)
 
void switch_core_thread_session_end (switch_core_session_t *session)
 
void switch_core_service_session_av (switch_core_session_t *session, switch_bool_t audio, switch_bool_t video)
 
switch_thread_tswitch_core_launch_thread (switch_thread_start_t func, void *obj, switch_memory_pool_t *pool)
 
void switch_core_set_globals (void)
 Initiate Globals. More...
 
int32_t switch_core_set_process_privileges (void)
 Switch on the privilege awareness for the process and request required privileges. More...
 
int32_t set_low_priority (void)
 
int32_t set_realtime_priority (void)
 
uint32_t switch_core_cpu_count (void)
 
int32_t set_normal_priority (void)
 Set the maximum priority the process can obtain. More...
 
int32_t set_auto_priority (void)
 
int32_t change_user_group (const char *user, const char *group)
 Change user and/or group of the running process. More...
 
void switch_core_runtime_loop (int bg)
 Run endlessly until the system is shutdown. More...
 
const char * switch_core_mime_ext2type (const char *ext)
 
const char * switch_core_mime_type2ext (const char *mime)
 
switch_hash_index_tswitch_core_mime_index (void)
 
switch_status_t switch_core_mime_add_type (const char *type, const char *ext)
 
static void load_mime_types (void)
 
void switch_core_setrlimits (void)
 
switch_bool_t switch_check_network_list_ip_token (const char *ip_str, const char *list_name, const char **token)
 
void switch_load_network_lists (switch_bool_t reload)
 
uint32_t switch_core_max_dtmf_duration (uint32_t duration)
 
uint32_t switch_core_default_dtmf_duration (uint32_t duration)
 
uint32_t switch_core_min_dtmf_duration (uint32_t duration)
 
switch_status_t switch_core_thread_set_cpu_affinity (int cpu)
 
int switch_core_test_flag (int flag)
 
switch_status_t switch_core_init (switch_core_flag_t flags, switch_bool_t console, const char **err)
 
static void handle_SIGHUP (int sig)
 
uint32_t switch_default_ptime (const char *name, uint32_t number)
 
uint32_t switch_default_rate (const char *name, uint32_t number)
 
const char * switch_core_banner (void)
 
switch_status_t switch_core_init_and_modload (switch_core_flag_t flags, switch_bool_t console, const char **err)
 
void switch_core_measure_time (switch_time_t total_ms, switch_core_time_duration_t *duration)
 Breakdown a number of milliseconds into various time spec. More...
 
switch_time_t switch_core_uptime (void)
 Number of microseconds the system has been up. More...
 
void switch_core_set_signal_handlers (void)
 
uint32_t switch_core_debug_level (void)
 
int32_t switch_core_session_ctl (switch_session_ctl_t cmd, void *val)
 send a control message to the core More...
 
switch_core_flag_t switch_core_flags (void)
 return core flags More...
 
switch_bool_t switch_core_running (void)
 
switch_bool_t switch_core_ready (void)
 Determines if the core is ready to take calls. More...
 
switch_bool_t switch_core_ready_inbound (void)
 Determines if the core is ready to take inbound calls. More...
 
switch_bool_t switch_core_ready_outbound (void)
 Determines if the core is ready to place outbound calls. More...
 
switch_status_t switch_core_destroy (void)
 Destroy the core. More...
 
switch_status_t switch_core_management_exec (char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
 Execute a management operation. More...
 
void switch_core_memory_reclaim_all (void)
 
static void *SWITCH_THREAD_FUNC system_thread (switch_thread_t *thread, void *obj)
 
static int switch_system_thread (const char *cmd, switch_bool_t wait)
 
int switch_max_file_desc (void)
 
void switch_close_extra_files (int *keep, int keep_ttl)
 
pid_t switch_fork (void)
 
static int switch_system_fork (const char *cmd, switch_bool_t wait)
 
int switch_system (const char *cmd, switch_bool_t wait)
 
int switch_stream_system_fork (const char *cmd, switch_stream_handle_t *stream)
 
switch_status_t switch_core_get_stacksizes (switch_size_t *cur, switch_size_t *max)
 
int switch_stream_system (const char *cmd, switch_stream_handle_t *stream)
 
uint16_t switch_core_get_rtp_port_range_start_port ()
 Get RTP port range start value. More...
 
uint16_t switch_core_get_rtp_port_range_end_port ()
 Get RTP port range end value. More...
 

Variables

switch_directories SWITCH_GLOBAL_dirs = { 0 }
 
switch_filenames SWITCH_GLOBAL_filenames = { 0 }
 
struct switch_runtime runtime = { 0 }
 
static char main_ip4 [256] = ""
 
static char main_ip6 [256] = ""
 
static switch_ip_list_t IP_LIST = { 0 }
 
static uint32_t d_30 = 30
 

Macro Definition Documentation

#define BUFSIZE   1024

Referenced by switch_core_set_globals().

Function Documentation

static void check_ip ( void  )
static

Definition at line 109 of file switch_core.c.

References switch_runtime::hostname, main_ip4, main_ip6, switch_core_get_variable(), switch_core_set_variable(), switch_event_add_header(), switch_event_add_header_string(), switch_event_create, switch_event_fire, SWITCH_EVENT_TRAP, switch_find_local_ip(), switch_set_string, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by SWITCH_STANDARD_SCHED_FUNC().

110 {
111  char guess_ip4[256] = "";
112  char guess_ip6[256] = "";
113  char old_ip4[256] = "";
114  char old_ip6[256] = "";
115  int ok4 = 1, ok6 = 1;
116  int mask = 0;
117  switch_status_t check6, check4;
118  switch_event_t *event;
119  char *hostname = switch_core_get_variable("hostname");
120 
121  gethostname(runtime.hostname, sizeof(runtime.hostname));
122 
123  if (zstr(hostname)) {
125  } else if (strcmp(hostname, runtime.hostname)) {
127  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "hostname-change");
128  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "old-hostname", hostname ? hostname : "nil");
130  switch_event_fire(&event);
131  }
132 
134  }
135 
136  check4 = switch_find_local_ip(guess_ip4, sizeof(guess_ip4), &mask, AF_INET);
137  check6 = switch_find_local_ip(guess_ip6, sizeof(guess_ip6), NULL, AF_INET6);
138 
139  if (check6 != SWITCH_STATUS_SUCCESS && (zstr(main_ip6) || !strcasecmp(main_ip6, "::1"))) {
140  check6 = SWITCH_STATUS_SUCCESS;
141  }
142 
143  if (check4 != SWITCH_STATUS_SUCCESS) {
144  ok4 = 2;
145  } else if (!*main_ip4) {
146  switch_set_string(main_ip4, guess_ip4);
147  } else {
148  if (!(ok4 = !strcmp(main_ip4, guess_ip4))) {
149  struct in_addr in;
150 
151  in.s_addr = mask;
152  switch_set_string(old_ip4, main_ip4);
153  switch_set_string(main_ip4, guess_ip4);
154  switch_core_set_variable("local_ip_v4", guess_ip4);
155  switch_core_set_variable("local_mask_v4", inet_ntoa(in));
156  }
157  }
158 
159  if (check6 != SWITCH_STATUS_SUCCESS) {
160  ok6 = 2;
161  } else if (!*main_ip6) {
162  switch_set_string(main_ip6, guess_ip6);
163  } else {
164  if (!(ok6 = !strcmp(main_ip6, guess_ip6))) {
165  switch_set_string(old_ip6, main_ip6);
166  switch_set_string(main_ip6, guess_ip6);
167  switch_core_set_variable("local_ip_v6", guess_ip6);
168  }
169  }
170 
171  if (!ok4 || !ok6) {
173  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "network-address-change");
174  if (!ok4) {
175  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-previous-v4", old_ip4);
176  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-change-v4", main_ip4);
177  }
178  if (!ok6) {
179  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-previous-v6", old_ip6);
180  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-change-v6", main_ip6);
181  }
182  switch_event_fire(&event);
183  }
184  }
185 
186  if (ok4 == 2 || ok6 == 2) {
188  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "network-outage");
189 
190  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-status-v4", ok4 == 2 ? "disconnected" : "active");
191  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-v4", main_ip4);
192 
193  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-status-v6", ok6 == 2 ? "disconnected" : "active");
194  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-v6", main_ip6);
195 
196  switch_event_fire(&event);
197  }
198  }
199 
200 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
char hostname[256]
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
switch_byte_t in
static char main_ip6[256]
Definition: switch_core.c:107
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
void switch_core_set_variable(const char *varname, const char *value)
Definition: switch_core.c:430
static char main_ip4[256]
Definition: switch_core.c:106
switch_status_t
Common return values.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:383
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:665
char * switch_core_get_variable(const char *varname)
Definition: switch_core.c:383
switch_status_t switch_find_local_ip(_Out_opt_bytecapcount_(len) char *buf, _In_ int len, _In_opt_ int *mask, _In_ int family)
find local ip of the box
static void handle_SIGHUP ( int  sig)
static

Definition at line 2012 of file switch_core.c.

References switch_event_add_header(), switch_event_create, switch_event_fire, SWITCH_EVENT_TRAP, SWITCH_STACK_BOTTOM, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_session_ctl(), and switch_core_set_signal_handlers().

2013 {
2014  if (sig) {
2015  switch_event_t *event;
2016 
2018  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Trapped-Signal", "HUP");
2019  switch_event_fire(&event);
2020  }
2021  }
2022  return;
2023 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:383
static void load_mime_types ( void  )
static

Definition at line 1260 of file switch_core.c.

References switch_directories::conf_dir, switch_assert, switch_core_mime_add_type(), switch_fp_read_dline(), SWITCH_GLOBAL_dirs, switch_mprintf(), and switch_safe_free.

Referenced by switch_core_init().

1261 {
1262  char *cf = "mime.types";
1263  FILE *fd = NULL;
1264  char *line_buf = NULL;
1265  switch_size_t llen = 0;
1266  char *mime_path = NULL;
1267 
1268  mime_path = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.conf_dir, cf);
1269  switch_assert(mime_path);
1270 
1271  fd = fopen(mime_path, "rb");
1272 
1273  if (fd == NULL) {
1274  goto end;
1275  }
1276 
1277  while ((switch_fp_read_dline(fd, &line_buf, &llen))) {
1278  char *p;
1279  char *type = line_buf;
1280 
1281  if (*line_buf == '#') {
1282  continue;
1283  }
1284 
1285  if ((p = strchr(line_buf, '\r')) || (p = strchr(line_buf, '\n'))) {
1286  *p = '\0';
1287  }
1288 
1289  if ((p = strchr(type, '\t')) || (p = strchr(type, ' '))) {
1290  *p++ = '\0';
1291 
1292  while (*p == ' ' || *p == '\t') {
1293  p++;
1294  }
1295 
1296  switch_core_mime_add_type(type, p);
1297  }
1298 
1299  }
1300 
1301  switch_safe_free(line_buf);
1302 
1303  if (fd) {
1304  fclose(fd);
1305  fd = NULL;
1306  }
1307 
1308  end:
1309 
1310  switch_safe_free(mime_path);
1311 
1312 }
switch_status_t switch_core_mime_add_type(const char *type, const char *ext)
Definition: switch_core.c:1220
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
uintptr_t switch_size_t
switch_size_t switch_fp_read_dline(FILE *fd, char **buf, switch_size_t *len)
Definition: switch_utils.c:757
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
#define switch_assert(expr)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
static void send_heartbeat ( void  )
static

Definition at line 67 of file switch_core.c.

References switch_core_time_duration::day, switch_core_time_duration::hr, switch_core_time_duration::min, switch_core_time_duration::mms, switch_core_time_duration::ms, switch_core_time_duration::sec, switch_runtime::sessions_peak, switch_runtime::sessions_peak_fivemin, switch_runtime::sps, switch_runtime::sps_peak, switch_runtime::sps_peak_fivemin, switch_core_idle_cpu(), switch_core_measure_time(), switch_core_session_count(), switch_core_session_id(), switch_core_session_limit(), switch_core_uptime(), switch_event_add_header(), switch_event_create, switch_event_fire, SWITCH_EVENT_HEARTBEAT, SWITCH_SIZE_T_FMT, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, SWITCH_TIME_T_FMT, switch_version_full(), and switch_core_time_duration::yr.

Referenced by SWITCH_STANDARD_SCHED_FUNC().

68 {
69  switch_event_t *event;
71 
73 
75  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
77  "%u year%s, "
78  "%u day%s, "
79  "%u hour%s, "
80  "%u minute%s, "
81  "%u second%s, "
82  "%u millisecond%s, "
83  "%u microsecond%s",
84  duration.yr, duration.yr == 1 ? "" : "s",
85  duration.day, duration.day == 1 ? "" : "s",
86  duration.hr, duration.hr == 1 ? "" : "s",
87  duration.min, duration.min == 1 ? "" : "s",
88  duration.sec, duration.sec == 1 ? "" : "s",
89  duration.ms, duration.ms == 1 ? "" : "s", duration.mms, duration.mms == 1 ? "" : "s");
90 
91  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FreeSWITCH-Version", "%s", switch_version_full());
95  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec", "%u", runtime.sps);
96  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec-Max", "%u", runtime.sps_peak);
97  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec-FiveMin", "%u", runtime.sps_peak_fivemin);
98  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Since-Startup", "%" SWITCH_SIZE_T_FMT, switch_core_session_id() - 1);
99  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Peak-Max", "%u", runtime.sessions_peak);
100  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Peak-FiveMin", "%u", runtime.sessions_peak_fivemin);
102  switch_event_fire(&event);
103  }
104 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
switch_time_t switch_core_uptime(void)
Number of microseconds the system has been up.
Definition: switch_core.c:2467
const char * switch_version_full(void)
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
struct switch_runtime runtime
Definition: switch_core.c:64
switch_size_t switch_core_session_id(void)
Provide the current session_id.
double switch_core_idle_cpu(void)
int32_t sessions_peak_fivemin
#define SWITCH_TIME_T_FMT
uint32_t switch_core_session_count(void)
Provide the total number of sessions.
uint32_t switch_core_session_limit(_In_ uint32_t new_limit)
Set/Get Session Limit.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:383
int32_t sps_peak_fivemin
void switch_core_measure_time(switch_time_t total_ms, switch_core_time_duration_t *duration)
Breakdown a number of milliseconds into various time spec.
Definition: switch_core.c:2450
#define SWITCH_SIZE_T_FMT
void switch_close_extra_files ( int *  keep,
int  keep_ttl 
)

Definition at line 3096 of file switch_core.c.

References skip(), and switch_max_file_desc().

Referenced by preprocess_exec(), switch_stream_system_fork(), and switch_system_fork().

3097 {
3098  int open_max = switch_max_file_desc();
3099  int i, j;
3100 
3101  for (i = 3; i < open_max; i++) {
3102  if (keep) {
3103  for (j = 0; j < keep_ttl; j++) {
3104  if (i == keep[j]) {
3105  goto skip;
3106  }
3107  }
3108  }
3109 
3110  close(i);
3111 
3112  skip:
3113 
3114  continue;
3115 
3116  }
3117 }
int switch_max_file_desc(void)
Definition: switch_core.c:3080
static const char * skip(const char *in)
Definition: switch_json.c:270
int switch_core_add_state_handler ( const switch_state_handler_table_t state_handler)

Definition at line 306 of file switch_core.c.

References switch_runtime::global_mutex, switch_runtime::state_handler_index, switch_runtime::state_handlers, SWITCH_MAX_STATE_HANDLERS, switch_mutex_lock(), and switch_mutex_unlock().

307 {
308  int index;
309 
311  index = runtime.state_handler_index++;
312 
314  index = -1;
315  } else {
316  runtime.state_handlers[index] = state_handler;
317  }
318 
320  return index;
321 }
const switch_state_handler_table_t * state_handlers[SWITCH_MAX_STATE_HANDLERS]
#define SWITCH_MAX_STATE_HANDLERS
Definition: switch_types.h:559
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * global_mutex
const char* switch_core_banner ( void  )

Definition at line 2342 of file switch_core.c.

Referenced by switch_core_init_and_modload().

2343 {
2344 
2345  return ("\n"
2346  ".=============================================================.\n"
2347  "| _____ ______ _____ _____ ____ _ _ |\n"
2348  "| | ___| __ ___ ___/ ___\\ \\ / /_ _|_ _/ ___| | | | |\n"
2349  "| | |_ | '__/ _ \\/ _ \\___ \\\\ \\ /\\ / / | | | || | | |_| | |\n"
2350  "| | _|| | | __/ __/___) |\\ V V / | | | || |___| _ | |\n"
2351  "| |_| |_| \\___|\\___|____/ \\_/\\_/ |___| |_| \\____|_| |_| |\n"
2352  "| |\n"
2353  ".=============================================================."
2354  "\n"
2355 
2356  "| Anthony Minessale II, Michael Jerris, Brian West, Others |\n"
2357  "| FreeSWITCH (http://www.freeswitch.org) |\n"
2358  "| Paypal Donations Appreciated: paypal@freeswitch.org |\n"
2359  "| Brought to you by ClueCon http://www.cluecon.com/ |\n"
2360  ".=============================================================.\n"
2361  "\n");
2362 }
uint32_t switch_core_debug_level ( void  )

Definition at line 2522 of file switch_core.c.

References switch_runtime::debug_level.

2523 {
2524  return runtime.debug_level;
2525 }
struct switch_runtime runtime
Definition: switch_core.c:64
uint32_t debug_level
void switch_core_dump_variables ( switch_stream_handle_t stream)

Definition at line 333 of file switch_core.c.

References switch_runtime::global_mutex, switch_runtime::global_vars, switch_event::headers, switch_event_header::name, switch_event_header::next, switch_mutex_lock(), switch_mutex_unlock(), and switch_event_header::value.

334 {
336 
338  for (hi = runtime.global_vars->headers; hi; hi = hi->next) {
339  stream->write_function(stream, "%s=%s\n", hi->name, hi->value);
340  }
342 }
An event Header.
Definition: switch_event.h:65
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * global_mutex
switch_stream_handle_write_function_t write_function
struct switch_event_header * next
Definition: switch_event.h:76
switch_event_header_t * headers
Definition: switch_event.h:90
uint16_t switch_core_get_rtp_port_range_end_port ( void  )

Get RTP port range end value.

Parameters
[in]void
[out]RTPport range end value

Definition at line 3295 of file switch_core.c.

References switch_rtp_set_end_port().

3296 {
3297  uint16_t end_port = 0;
3298 
3299  /* By default pass rtp port range end value as zero in order to get actual
3300  * RTP port range end value as configured */
3301  end_port = (uint16_t)switch_rtp_set_end_port((switch_port_t)end_port);
3302 
3303  return end_port;
3304 }
switch_port_t switch_rtp_set_end_port(switch_port_t port)
Set/Get RTP end port.
Definition: switch_rtp.c:2401
uint16_t switch_port_t
uint16_t switch_core_get_rtp_port_range_start_port ( void  )

Get RTP port range start value.

Parameters
[in]void
[out]RTPport range start value

Definition at line 3284 of file switch_core.c.

References switch_rtp_set_start_port().

3285 {
3286  uint16_t start_port = 0;
3287 
3288  /* By default pass rtp port range start value as zero in order to get actual
3289  * RTP port range start value as configured */
3290  start_port = (uint16_t)switch_rtp_set_start_port((switch_port_t)start_port);
3291 
3292  return start_port;
3293 }
switch_port_t switch_rtp_set_start_port(switch_port_t port)
Set/Get RTP start port.
Definition: switch_rtp.c:2387
uint16_t switch_port_t
switch_status_t switch_core_get_stacksizes ( switch_size_t cur,
switch_size_t max 
)

Definition at line 3249 of file switch_core.c.

References memset(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3250 {
3251 #ifdef HAVE_SETRLIMIT
3252  struct rlimit rlp;
3253 
3254  memset(&rlp, 0, sizeof(rlp));
3255  getrlimit(RLIMIT_STACK, &rlp);
3256 
3257  *cur = rlp.rlim_cur;
3258  *max = rlp.rlim_max;
3259 
3260  return SWITCH_STATUS_SUCCESS;
3261 
3262 #else
3263 
3264  return SWITCH_STATUS_FALSE;
3265 
3266 #endif
3267 
3268 
3269 
3270 }
pack cur
memset(buf, 0, buflen)
const switch_state_handler_table_t* switch_core_get_state_handler ( int  index)

Definition at line 323 of file switch_core.c.

References switch_runtime::state_handler_index, switch_runtime::state_handlers, and SWITCH_MAX_STATE_HANDLERS.

324 {
325 
326  if (index >= SWITCH_MAX_STATE_HANDLERS || index > runtime.state_handler_index) {
327  return NULL;
328  }
329 
330  return runtime.state_handlers[index];
331 }
const switch_state_handler_table_t * state_handlers[SWITCH_MAX_STATE_HANDLERS]
#define SWITCH_MAX_STATE_HANDLERS
Definition: switch_types.h:559
struct switch_runtime runtime
Definition: switch_core.c:64
char* switch_core_get_variable ( const char *  varname)

Definition at line 383 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_event_get_header, switch_thread_rwlock_rdlock(), and switch_thread_rwlock_unlock().

Referenced by check_ip(), and switch_core_get_domain().

384 {
385  char *val;
387  val = (char *) switch_event_get_header(runtime.global_vars, varname);
389  return val;
390 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:227
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
char* switch_core_get_variable_dup ( const char *  varname)

Definition at line 392 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_event_get_header, switch_thread_rwlock_rdlock(), and switch_thread_rwlock_unlock().

Referenced by switch_core_init_and_modload().

393 {
394  char *val = NULL, *v;
395 
396  if (varname) {
398  if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
399  val = strdup(v);
400  }
402  }
403 
404  return val;
405 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:227
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
char* switch_core_get_variable_pdup ( const char *  varname,
switch_memory_pool_t pool 
)

Definition at line 407 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_core_strdup, switch_event_get_header, switch_thread_rwlock_rdlock(), and switch_thread_rwlock_unlock().

408 {
409  char *val = NULL, *v;
410 
411  if (varname) {
413  if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
414  val = switch_core_strdup(pool, v);
415  }
417  }
418 
419  return val;
420 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_memory_pool_t * pool
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:227
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
switch_status_t switch_core_init ( switch_core_flag_t  flags,
switch_bool_t  console,
const char **  err 
)

Definition at line 1806 of file switch_core.c.

References switch_directories::base_dir, switch_frame::buflen, switch_directories::cache_dir, switch_directories::certs_dir, switch_runtime::colorize_console, switch_directories::conf_dir, switch_runtime::console, switch_runtime::cpu_count, switch_frame::data, switch_directories::data_dir, switch_frame::datalen, switch_directories::db_dir, switch_runtime::db_handle_timeout, switch_runtime::dbname, DBTYPE_DEFAULT, switch_runtime::default_dtmf_duration, switch_runtime::dummy_cng_frame, switch_runtime::dummy_data, switch_runtime::flags, switch_directories::fonts_dir, switch_runtime::global_mutex, switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_directories::grammar_dir, switch_runtime::hard_log_level, switch_runtime::hostname, switch_directories::htdocs_dir, switch_directories::images_dir, switch_runtime::initiated, load_mime_types(), switch_directories::localstate_dir, switch_directories::log_dir, switch_runtime::mailer_app, switch_runtime::mailer_app_args, switch_runtime::max_db_handles, switch_runtime::max_dtmf_duration, switch_runtime::memory_pool, memset(), switch_runtime::microseconds_per_tick, switch_runtime::mime_type_exts, switch_runtime::mime_types, switch_runtime::min_dtmf_duration, switch_directories::mod_dir, switch_runtime::odbc_dbtype, switch_runtime::ptimes, switch_directories::recordings_dir, switch_directories::run_dir, switch_runtime::runlevel, switch_runtime::running, SCF_API_EXPANSION, SCF_AUTO_SCHEMAS, SCF_CLEAR_SQL, SCF_MINIMAL, SCF_NO_NEW_SESSIONS, SCF_SESSION_THREAD_POOL, SCF_THREADED_SYSTEM_EXEC, SCF_USE_AUTO_NAT, SCF_USE_NAT_MAPPING, SCF_USE_SQL, switch_directories::script_dir, switch_runtime::session_hash_mutex, SFF_CNG, switch_directories::sounds_dir, switch_runtime::sps_total, SSHF_NO_DEL, SSHF_NONE, SSHF_OWN_THREAD, switch_directories::storage_dir, switch_assert, switch_channel_global_init(), switch_console_init(), switch_core_hash_init_case(), switch_core_media_init(), switch_core_memory_init(), switch_core_session_init(), switch_core_set_globals(), switch_core_set_variable(), switch_core_sqldb_start(), switch_core_state_machine_init(), switch_curl_init(), SWITCH_DEFAULT_DIR_PERMS, SWITCH_DEFAULT_DTMF_DURATION, switch_dir_make_recursive(), switch_epoch_time_now(), SWITCH_EVENT_CHANNEL_DATA, switch_event_create_plain(), switch_event_init(), SWITCH_FALSE, switch_find_local_ip(), SWITCH_GLOBAL_dirs, switch_load_core_config(), SWITCH_LOG_DEBUG, switch_log_init(), SWITCH_MAX_DTMF_DURATION, SWITCH_MIN_DTMF_DURATION, switch_mono_micro_time_now(), switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_nat_init(), switch_nat_late_init(), switch_rtp_init(), switch_scheduler_add_task(), switch_scheduler_task_thread_start(), switch_set_flag, switch_ssl_init_ssl_locks(), SWITCH_STATUS_FALSE, SWITCH_STATUS_MEMERR, SWITCH_STATUS_SUCCESS, switch_test_flag, switch_thread_rwlock_create(), SWITCH_TRUE, switch_uuid_format(), switch_uuid_get(), switch_xml_init(), switch_directories::temp_dir, switch_runtime::throttle_mutex, switch_runtime::timer_affinity, switch_runtime::tipping_point, switch_runtime::uuid_mutex, and switch_runtime::uuid_str.

Referenced by switch_core_init_and_modload().

1807 {
1808  switch_uuid_t uuid;
1809  char guess_ip[256];
1810  int mask = 0;
1811  struct in_addr in;
1812 
1813 
1814  if (runtime.runlevel > 0) {
1815  /* one per customer */
1816  return SWITCH_STATUS_SUCCESS;
1817  }
1818 
1819  memset(&runtime, 0, sizeof(runtime));
1820  gethostname(runtime.hostname, sizeof(runtime.hostname));
1821 
1822  runtime.max_db_handles = 50;
1823  runtime.db_handle_timeout = 5000000;
1824 
1825  runtime.runlevel++;
1829  runtime.dbname = "core";
1835 #ifdef WIN32
1837 #endif
1840  runtime.mailer_app = "sendmail";
1841  runtime.mailer_app_args = "-t";
1846  runtime.dbname = NULL;
1847 #ifndef WIN32
1848  runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
1849 #else
1850  {
1851  SYSTEM_INFO sysinfo;
1852  GetSystemInfo( &sysinfo );
1853  runtime.cpu_count = sysinfo.dwNumberOfProcessors;
1854  }
1855 #endif
1856 
1857  if (!runtime.cpu_count) runtime.cpu_count = 1;
1858 
1859  if (sqlite3_initialize() != SQLITE_OK) {
1860  *err = "FATAL ERROR! Could not initialize SQLite\n";
1861  return SWITCH_STATUS_MEMERR;
1862  }
1863 
1864  /* INIT APR and Create the pool context */
1865  if (apr_initialize() != SWITCH_STATUS_SUCCESS) {
1866  *err = "FATAL ERROR! Could not initialize APR\n";
1867  return SWITCH_STATUS_MEMERR;
1868  }
1869 
1871  *err = "FATAL ERROR! Could not allocate memory pool\n";
1872  return SWITCH_STATUS_MEMERR;
1873  }
1875 
1891 
1893 
1895 
1898 
1906  load_mime_types();
1907  runtime.flags |= flags;
1908  runtime.sps_total = 30;
1909 
1910  *err = NULL;
1911 
1912  if (console) {
1913  runtime.console = stdout;
1914  }
1915 
1916  SSL_library_init();
1918  switch_curl_init();
1919 
1921  switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
1922  switch_core_set_variable("local_ip_v4", guess_ip);
1923  in.s_addr = mask;
1924  switch_core_set_variable("local_mask_v4", inet_ntoa(in));
1925 
1926 
1927  switch_find_local_ip(guess_ip, sizeof(guess_ip), NULL, AF_INET6);
1928  switch_core_set_variable("local_ip_v6", guess_ip);
1949 #ifdef ENABLE_ZRTP
1950  switch_core_set_serial();
1951 #endif
1955 
1957  apr_terminate();
1958  return SWITCH_STATUS_MEMERR;
1959  }
1960 
1963  }
1964 
1966 
1967  runtime.tipping_point = 0;
1968  runtime.timer_affinity = -1;
1970 
1971  if (flags & SCF_MINIMAL) return SWITCH_STATUS_SUCCESS;
1972 
1973  switch_load_core_config("switch.conf");
1974 
1976 
1978  *err = "Error activating database";
1979  return SWITCH_STATUS_FALSE;
1980  }
1983 
1985 
1987 
1988  runtime.running = 1;
1990 
1991  switch_scheduler_add_task(switch_epoch_time_now(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL);
1992 
1993  switch_scheduler_add_task(switch_epoch_time_now(NULL), check_ip_callback, "check_ip", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL | SSHF_OWN_THREAD);
1994 
1995  switch_uuid_get(&uuid);
1998 
1999 
2000  return SWITCH_STATUS_SUCCESS;
2001 }
switch_memory_pool_t * switch_core_memory_init(void)
uint32_t min_dtmf_duration
switch_frame_t dummy_cng_frame
switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage)
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
switch_time_t initiated
void switch_ssl_init_ssl_locks(void)
int32_t timer_affinity
void switch_scheduler_task_thread_start(void)
Start the scheduler system.
void switch_core_set_globals(void)
Initiate Globals.
Definition: switch_core.c:620
void switch_core_session_init(switch_memory_pool_t *pool)
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
char hostname[256]
switch_mutex_t * throttle_mutex
#define SWITCH_DEFAULT_DTMF_DURATION
Definition: switch_types.h:115
static void switch_load_core_config(const char *file)
Definition: switch_core.c:2053
uint32_t microseconds_per_tick
struct switch_runtime runtime
Definition: switch_core.c:64
uint32_t switch_scheduler_add_task(time_t task_runtime, switch_scheduler_func_t func, const char *desc, const char *group, uint32_t cmd_id, void *cmd_arg, switch_scheduler_flag_t flags)
Schedule a task in the future.
void switch_rtp_init(switch_memory_pool_t *pool)
Initilize the RTP System.
Definition: switch_rtp.c:1442
switch_status_t switch_event_init(switch_memory_pool_t *pool)
Start the eventing system.
Definition: switch_event.c:664
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_hash_t * ptimes
void switch_channel_global_init(switch_memory_pool_t *pool)
switch_dbtype_t odbc_dbtype
void switch_nat_init(switch_memory_pool_t *pool, switch_bool_t mapping)
Initilize the NAT Traversal System.
Definition: switch_nat.c:399
uint32_t buflen
Definition: switch_frame.h:59
switch_bool_t colorize_console
uint32_t datalen
Definition: switch_frame.h:57
switch_byte_t in
#define SWITCH_MAX_DTMF_DURATION
Definition: switch_types.h:117
static void load_mime_types(void)
Definition: switch_core.c:1260
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
switch_status_t switch_console_init(switch_memory_pool_t *pool)
switch_hash_t * mime_type_exts
void switch_core_set_variable(const char *varname, const char *value)
Definition: switch_core.c:430
uint32_t db_handle_timeout
switch_mutex_t * session_hash_mutex
void switch_nat_late_init(void)
Initilize the rest of the NAT Traversal System.
Definition: switch_nat.c:708
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
Definition: switch_event.h:385
switch_mutex_t * global_mutex
switch_hash_t * mime_types
#define SWITCH_DEFAULT_DIR_PERMS
Definition: switch_types.h:118
uint32_t max_dtmf_duration
void switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
Definition: switch_apr.c:1055
#define SWITCH_MIN_DTMF_DURATION
Definition: switch_types.h:116
switch_status_t switch_dir_make_recursive(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
Definition: switch_apr.c:528
switch_status_t switch_core_hash_init_case(_Out_ switch_hash_t **hash, switch_bool_t case_sensitive)
Initialize a hash table.
switch_log_level_t hard_log_level
uint32_t default_dtmf_duration
uint32_t tipping_point
void switch_uuid_get(switch_uuid_t *uuid)
Definition: switch_apr.c:1067
uint32_t max_db_handles
switch_time_t switch_mono_micro_time_now(void)
Definition: switch_time.c:315
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
switch_mutex_t * uuid_mutex
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
Definition: switch_apr.c:212
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_memory_pool_t * memory_pool
switch_status_t switch_log_init(_In_ switch_memory_pool_t *pool, _In_ switch_bool_t colorize)
Initilize the logging engine.
switch_status_t switch_find_local_ip(_Out_opt_bytecapcount_(len) char *buf, _In_ int len, _In_opt_ int *mask, _In_ int family)
find local ip of the box
void switch_core_media_init(void)
void switch_curl_init(void)
Definition: switch_curl.c:51
#define switch_assert(expr)
void switch_core_state_machine_init(switch_memory_pool_t *pool)
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1]
memset(buf, 0, buflen)
switch_status_t switch_xml_init(_In_ switch_memory_pool_t *pool, _Out_ const char **err)
initilize the core XML backend
switch_status_t switch_core_init_and_modload ( switch_core_flag_t  flags,
switch_bool_t  console,
const char **  err 
)

Definition at line 2365 of file switch_core.c.

References cc, cc_s, switch_stream_handle::data, switch_runtime::events_use_dispatch, switch_runtime::runlevel, SCF_NO_NEW_SESSIONS, SCF_USE_SQL, SWITCH_CHANNEL_LOG, switch_clear_flag, switch_console_execute(), switch_core_banner(), switch_core_get_variable_dup(), switch_core_init(), switch_core_screen_size(), switch_core_session_limit(), switch_core_sessions_per_second(), switch_core_set_signal_handlers(), switch_event_add_header(), switch_event_create, switch_event_fire, SWITCH_EVENT_STARTUP, SWITCH_FALSE, switch_load_core_config(), switch_load_network_lists(), switch_loadable_module_init(), SWITCH_LOG_CONSOLE, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_SEQ_BBLUE, SWITCH_SEQ_DEFAULT_COLOR, SWITCH_SEQ_FYELLOW, SWITCH_STACK_BOTTOM, SWITCH_STANDARD_STREAM, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_test_flag, SWITCH_TRUE, switch_version_full(), and switch_version_revision_human().

2366 {
2367  switch_event_t *event;
2368  char *cmd;
2369  int x = 0;
2370  const char *use = NULL;
2371 #include "cc.h"
2372 
2373 
2374  if (switch_core_init(flags, console, err) != SWITCH_STATUS_SUCCESS) {
2375  return SWITCH_STATUS_GENERR;
2376  }
2377 
2378  if (runtime.runlevel > 1) {
2379  /* one per customer */
2380  return SWITCH_STATUS_SUCCESS;
2381  }
2382 
2383  runtime.runlevel++;
2385 
2388 
2389  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bringing up environment.\n");
2392  *err = "Cannot load modules";
2394  return SWITCH_STATUS_GENERR;
2395  }
2396 
2398 
2399  switch_load_core_config("post_load_switch.conf");
2400 
2402 
2404  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
2405  switch_event_fire(&event);
2406  }
2407 
2408  switch_core_screen_size(&x, NULL);
2409 
2410  use = (x > 100) ? cc : cc_s;
2411 
2412 #ifdef WIN32
2414 #else
2418  switch_core_banner(),
2420 
2421 #endif
2422 
2423 
2425  "\nFreeSWITCH Version %s (%s)\n\nFreeSWITCH Started\nMax Sessions [%u]\nSession Rate [%d]\nSQL [%s]\n",
2428  switch_core_sessions_per_second(0), switch_test_flag((&runtime), SCF_USE_SQL) ? "Enabled" : "Disabled");
2429 
2430 
2431  if (x < 160) {
2432  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\n[This app Best viewed at 160x60 or more..]\n");
2433  }
2434 
2436 
2437  if ((cmd = switch_core_get_variable_dup("api_on_startup"))) {
2438  switch_stream_handle_t stream = { 0 };
2439  SWITCH_STANDARD_STREAM(stream);
2440  switch_console_execute(cmd, 0, &stream);
2441  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Startup command [%s] executed. Output:\n%s\n", cmd, (char *)stream.data);
2442  free(stream.data);
2443  free(cmd);
2444  }
2445 
2446  return SWITCH_STATUS_SUCCESS;
2447 
2448 }
void switch_core_set_signal_handlers(void)
Definition: switch_core.c:2494
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
#define SWITCH_CHANNEL_LOG
uint32_t switch_core_sessions_per_second(_In_ uint32_t new_limit)
Set/Get Session Rate Limit.
const char * switch_version_full(void)
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
const char * cc
Definition: cc.h:2
const char * cc_s
Definition: cc.h:3
static void switch_load_core_config(const char *file)
Definition: switch_core.c:2053
struct switch_runtime runtime
Definition: switch_core.c:64
#define SWITCH_SEQ_FYELLOW
Definition: switch_types.h:94
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:655
#define SWITCH_STANDARD_STREAM(s)
uint32_t switch_core_session_limit(_In_ uint32_t new_limit)
Set/Get Session Limit.
#define SWITCH_SEQ_DEFAULT_COLOR
Definition: switch_types.h:69
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:383
const char * switch_core_banner(void)
Definition: switch_core.c:2342
switch_status_t switch_core_init(switch_core_flag_t flags, switch_bool_t console, const char **err)
Definition: switch_core.c:1806
#define SWITCH_SEQ_BBLUE
Definition: switch_types.h:103
switch_status_t switch_loadable_module_init(switch_bool_t autoload)
Initilize the module backend and load all the modules.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_console_execute(char *xcmd, int rec, switch_stream_handle_t *istream)
void switch_load_network_lists(switch_bool_t reload)
Definition: switch_core.c:1436
char * switch_core_get_variable_dup(const char *varname)
Definition: switch_core.c:392
const char * switch_version_revision_human(void)
void switch_core_screen_size(int *x, int *y)
Definition: switch_core.c:238
switch_thread_t* switch_core_launch_thread ( switch_thread_start_t  func,
void *  obj,
switch_memory_pool_t pool 
)

Definition at line 588 of file switch_core.c.

References switch_core_thread_session::objs, pool, switch_core_thread_session::pool, SWITCH_CHANNEL_LOG, switch_core_alloc, switch_core_new_memory_pool, SWITCH_LOG_CRIT, switch_log_printf(), SWITCH_PRI_REALTIME, SWITCH_STATUS_SUCCESS, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_priority_set(), switch_threadattr_stacksize_set(), and thread.

589 {
590  switch_thread_t *thread = NULL;
591  switch_threadattr_t *thd_attr = NULL;
593  int mypool;
594 
595  mypool = pool ? 0 : 1;
596 
598  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory pool\n");
599  return NULL;
600  }
601 
602  switch_threadattr_create(&thd_attr, pool);
603 
604  if ((ts = switch_core_alloc(pool, sizeof(*ts))) == 0) {
605  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory\n");
606  } else {
607  if (mypool) {
608  ts->pool = pool;
609  }
610  ts->objs[0] = obj;
611  ts->objs[1] = thread;
614  switch_thread_create(&thread, thd_attr, func, ts, pool);
615  }
616 
617  return thread;
618 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
#define SWITCH_CHANNEL_LOG
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
switch_memory_pool_t * pool
static switch_thread_t * thread
Definition: switch_log.c:279
switch_memory_pool_t * pool
Definition: switch_core.h:223
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:551
void * objs[SWITCH_MAX_CORE_THREAD_SESSION_OBJS]
Definition: switch_core.h:220
struct apr_thread_t switch_thread_t
Definition: switch_apr.h:941
A generic object to pass as a thread's session object to allow mutiple arguements and a pool...
Definition: switch_core.h:214
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:642
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:675
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:665
void switch_core_remove_state_handler ( const switch_state_handler_table_t state_handler)

Definition at line 281 of file switch_core.c.

References cur, switch_runtime::global_mutex, switch_runtime::state_handler_index, switch_runtime::state_handlers, SWITCH_MAX_STATE_HANDLERS, switch_mutex_lock(), and switch_mutex_unlock().

282 {
283  int index, tmp_index = 0;
285 
287 
288  for (index = 0; index < runtime.state_handler_index; index++) {
290  runtime.state_handlers[index] = NULL;
291  if (cur == state_handler) {
292  continue;
293  }
294  tmp[tmp_index++] = cur;
295  }
296 
298 
299  for (index = 0; index < tmp_index; index++) {
301  }
303 }
const switch_state_handler_table_t * state_handlers[SWITCH_MAX_STATE_HANDLERS]
pack cur
#define SWITCH_MAX_STATE_HANDLERS
Definition: switch_types.h:559
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * global_mutex
void switch_core_service_session_av ( switch_core_session_t session,
switch_bool_t  audio,
switch_bool_t  video 
)

Definition at line 560 of file switch_core.c.

References CF_SERVICE_AUDIO, CF_SERVICE_VIDEO, switch_assert, switch_channel_set_flag, switch_core_service_thread(), switch_core_session_get_channel(), and switch_core_session_launch_thread().

561 {
562  switch_channel_t *channel;
563  switch_assert(session);
564 
565  channel = switch_core_session_get_channel(session);
566  switch_assert(channel);
567 
568  if (audio) switch_channel_set_flag(channel, CF_SERVICE_AUDIO);
569  if (video) switch_channel_set_flag(channel, CF_SERVICE_VIDEO);
570 
571  switch_core_session_launch_thread(session, (void *(*)(switch_thread_t *,void *))switch_core_service_thread, session);
572 }
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
static void *SWITCH_THREAD_FUNC switch_core_service_thread(switch_thread_t *thread, void *obj)
Definition: switch_core.c:488
struct apr_thread_t switch_thread_t
Definition: switch_apr.h:941
#define switch_channel_set_flag(_c, _f)
#define switch_assert(expr)
void switch_core_session_launch_thread(_In_ switch_core_session_t *session, _In_ void *(*func)(switch_thread_t *, void *), _In_opt_ void *obj)
Launch a thread designed to exist within the scope of a given session.
static void* SWITCH_THREAD_FUNC switch_core_service_thread ( switch_thread_t thread,
void *  obj 
)
static

Definition at line 488 of file switch_core.c.

References CF_SERVICE, CF_SERVICE_AUDIO, CF_SERVICE_VIDEO, CF_VIDEO, switch_core_session::frame_read_mutex, switch_channel_clear_flag(), switch_channel_set_flag, switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_read_frame(), switch_core_session_read_lock(), switch_core_session_read_video_frame(), switch_core_session_rwunlock(), SWITCH_IO_FLAG_NONE, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_BREAK, SWITCH_STATUS_SUCCESS, and SWITCH_STATUS_TIMEOUT.

Referenced by switch_core_service_session_av().

489 {
490  switch_core_session_t *session = obj;
491  switch_channel_t *channel;
492  switch_frame_t *read_frame;
493 
494 // switch_assert(thread != NULL);
495 // switch_assert(session != NULL);
496 
498  return NULL;
499  }
500 
502 
503  channel = switch_core_session_get_channel(session);
504 
506  while (switch_channel_test_flag(channel, CF_SERVICE)) {
507 
509  switch (switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0)) {
512  case SWITCH_STATUS_BREAK:
513  break;
514  default:
516  break;
517  }
518  }
519 
521  switch (switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0)) {
524  case SWITCH_STATUS_BREAK:
525  break;
526  default:
528  break;
529  }
530  }
531  }
532 
534 
537 
539 
540  return NULL;
541 }
switch_status_t switch_core_session_read_video_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
Read a video frame from a session.
switch_status_t switch_core_session_read_lock(_In_ switch_core_session_t *session)
Acquire a read lock on the session.
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_status_t switch_core_session_read_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
Read a frame from a session.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_mutex_t * frame_read_mutex
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
An abstraction of a data frame.
Definition: switch_frame.h:43
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
#define switch_channel_set_flag(_c, _f)
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
void switch_core_set_signal_handlers ( void  )

Definition at line 2494 of file switch_core.c.

References handle_SIGHUP().

Referenced by switch_core_init_and_modload(), switch_loadable_module_load_file(), and switch_system_fork().

2495 {
2496  /* set signal handlers */
2497  signal(SIGINT, SIG_IGN);
2498 #ifdef SIGPIPE
2499  signal(SIGPIPE, SIG_IGN);
2500 #endif
2501 #ifdef SIGALRM
2502  signal(SIGALRM, SIG_IGN);
2503 #endif
2504 #ifdef SIGQUIT
2505  signal(SIGQUIT, SIG_IGN);
2506 #endif
2507 #ifdef SIGPOLL
2508  signal(SIGPOLL, SIG_IGN);
2509 #endif
2510 #ifdef SIGIO
2511  signal(SIGIO, SIG_IGN);
2512 #endif
2513 #ifdef TRAP_BUS
2514  signal(SIGBUS, handle_SIGBUS);
2515 #endif
2516 #ifdef SIGUSR1
2517  signal(SIGUSR1, handle_SIGHUP);
2518 #endif
2519  signal(SIGHUP, handle_SIGHUP);
2520 }
static void handle_SIGHUP(int sig)
Definition: switch_core.c:2012
switch_bool_t switch_core_set_var_conditional ( const char *  varname,
const char *  value,
const char *  val2 
)

Definition at line 451 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_event_add_header_string(), switch_event_del_header, switch_event_get_header, SWITCH_FALSE, SWITCH_STACK_BOTTOM, SWITCH_STACK_NODUP, switch_string_var_check(), switch_thread_rwlock_unlock(), switch_thread_rwlock_wrlock(), SWITCH_TRUE, and zstr.

452 {
453  char *val;
454 
455  if (varname) {
457  val = (char *) switch_event_get_header(runtime.global_vars, varname);
458 
459  if (val) {
460  if (!val2 || strcmp(val, val2) != 0) {
462  return SWITCH_FALSE;
463  }
465  } else if (!zstr(val2)) {
467  return SWITCH_FALSE;
468  }
469 
470  if (value) {
471  char *v = strdup(value);
474  } else {
476  }
478  }
479  return SWITCH_TRUE;
480 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
#define switch_event_del_header(_e, _h)
Definition: switch_event.h:211
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:237
static switch_bool_t switch_string_var_check(char *s, switch_bool_t disable)
Definition: switch_utils.h:691
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
void switch_core_set_variable ( const char *  varname,
const char *  value 
)

Definition at line 430 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_event_add_header_string(), switch_event_del_header, switch_event_get_header, SWITCH_STACK_BOTTOM, SWITCH_STACK_NODUP, switch_string_var_check(), switch_thread_rwlock_unlock(), switch_thread_rwlock_wrlock(), and SWITCH_TRUE.

Referenced by check_ip(), switch_core_init(), and switch_load_core_config().

431 {
432  char *val;
433 
434  if (varname) {
436  val = (char *) switch_event_get_header(runtime.global_vars, varname);
437  if (val) {
439  }
440  if (value) {
441  char *v = strdup(value);
444  } else {
446  }
448  }
449 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
#define switch_event_del_header(_e, _h)
Definition: switch_event.h:211
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:237
static switch_bool_t switch_string_var_check(char *s, switch_bool_t disable)
Definition: switch_utils.h:691
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
void switch_core_thread_session_end ( switch_core_session_t session)

Definition at line 544 of file switch_core.c.

References CF_SERVICE, CF_SERVICE_AUDIO, CF_SERVICE_VIDEO, switch_assert, switch_channel_clear_flag(), switch_core_session_get_channel(), switch_core_session_kill_channel, and SWITCH_SIG_BREAK.

545 {
546  switch_channel_t *channel;
547  switch_assert(session);
548 
549  channel = switch_core_session_get_channel(session);
550  switch_assert(channel);
551 
555 
557 
558 }
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
#define switch_assert(expr)
#define switch_core_session_kill_channel(session, sig)
Send a signal to a channel.
Definition: switch_core.h:1352
switch_status_t switch_core_thread_set_cpu_affinity ( int  cpu)

Definition at line 1723 of file switch_core.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_autobind_cpu(), and SWITCH_MODULE_RUNTIME_FUNCTION().

1724 {
1726 
1727  if (cpu > -1) {
1728 
1729 #ifdef HAVE_CPU_SET_MACROS
1730  cpu_set_t set;
1731 
1732  CPU_ZERO(&set);
1733  CPU_SET(cpu, &set);
1734 
1735  if (!sched_setaffinity(0, sizeof(set), &set)) {
1736  status = SWITCH_STATUS_SUCCESS;
1737  }
1738 
1739 #else
1740 #if WIN32
1741  if (SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) cpu)) {
1742  status = SWITCH_STATUS_SUCCESS;
1743  }
1744 #endif
1745 #endif
1746  }
1747 
1748  return status;
1749 }
switch_status_t
Common return values.
static void switch_core_unset_variables ( void  )
static

Definition at line 422 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, SWITCH_EVENT_CHANNEL_DATA, switch_event_create_plain(), switch_event_destroy(), switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

Referenced by switch_core_destroy().

423 {
428 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:237
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
Definition: switch_event.h:385
void switch_event_destroy(switch_event_t **event)
Destroy an event.
uint32_t switch_default_ptime ( const char *  name,
uint32_t  number 
)

Definition at line 2026 of file switch_core.c.

References switch_runtime::ptimes, and switch_core_hash_find().

Referenced by add_audio_codec(), switch_core_media_negotiate_sdp(), switch_loadable_module_get_codecs(), and switch_loadable_module_get_codecs_sorted().

2027 {
2028  uint32_t *p;
2029 
2030  if ((p = switch_core_hash_find(runtime.ptimes, name))) {
2031  return *p;
2032  }
2033 
2034  return 20;
2035 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
struct switch_runtime runtime
Definition: switch_core.c:64
switch_hash_t * ptimes
uint32_t switch_default_rate ( const char *  name,
uint32_t  number 
)

Definition at line 2037 of file switch_core.c.

Referenced by switch_loadable_module_get_codecs_sorted().

2038 {
2039 
2040  if (!strcasecmp(name, "opus")) {
2041  return 48000;
2042  } else if (!strncasecmp(name, "h26", 3)) { // h26x
2043  return 90000;
2044  } else if (!strncasecmp(name, "vp", 2)) { // vp8, vp9
2045  return 90000;
2046  }
2047 
2048  return 8000;
2049 }
pid_t switch_fork ( void  )

Definition at line 3134 of file switch_core.c.

References set_low_priority().

Referenced by daemonize(), preprocess_exec(), switch_stream_system_fork(), and switch_system_fork().

3135 {
3136  int i = fork();
3137 
3138  if (!i) {
3139  set_low_priority();
3140  }
3141 
3142  return i;
3143 }
int32_t set_low_priority(void)
Definition: switch_core.c:932
static void switch_load_core_config ( const char *  file)
static

Definition at line 2053 of file switch_core.c.

References switch_runtime::colorize_console, switch_runtime::core_db_inner_post_trans_execute, switch_runtime::core_db_inner_pre_trans_execute, switch_runtime::core_db_post_trans_execute, switch_runtime::core_db_pre_trans_execute, switch_runtime::cpu_count, switch_runtime::cpu_idle_smoothing_depth, switch_runtime::db_handle_timeout, switch_runtime::dbname, DBTYPE_DEFAULT, DBTYPE_MSSQL, switch_runtime::events_use_dispatch, switch_runtime::mailer_app, switch_runtime::mailer_app_args, switch_runtime::max_db_handles, switch_runtime::memory_pool, memset(), switch_runtime::microseconds_per_tick, switch_runtime::multiple_registrations, switch_xml::next, switch_runtime::odbc_dbtype, switch_runtime::odbc_dsn, switch_runtime::port_alloc_flags, switch_runtime::ptimes, SCF_API_EXPANSION, SCF_AUTO_SCHEMAS, SCF_CLEAR_SQL, SCF_CORE_NON_SQLITE_DB_REQ, SCF_DIALPLAN_TIMESTAMPS, SCF_EARLY_HANGUP, SCF_SESSION_THREAD_POOL, SCF_THREADED_SYSTEM_EXEC, SCF_VERBOSE_EVENTS, SCSC_DEBUG_LEVEL, SCSC_LOGLEVEL, SPF_ROBUST_UDP, switch_atoul(), SWITCH_CHANNEL_LOG, switch_clear_flag, switch_core_alloc, switch_core_default_dtmf_duration(), switch_core_hash_insert, switch_core_max_dtmf_duration(), switch_core_min_dtmf_duration(), switch_core_min_idle_cpu(), switch_core_session_ctl(), switch_core_session_limit(), switch_core_sessions_per_second(), switch_core_set_variable(), switch_core_strdup, switch_event_launch_dispatch_threads(), SWITCH_LOG_CRIT, SWITCH_LOG_ERROR, SWITCH_LOG_INVALID, SWITCH_LOG_NOTICE, switch_log_printf(), switch_log_str2level(), SWITCH_LOG_WARNING, switch_odbc_available(), switch_pgsql_available(), switch_rtp_set_end_port(), switch_rtp_set_start_port(), switch_set_flag, switch_time_set_cond_yield(), switch_time_set_matrix(), switch_time_set_monotonic(), switch_time_set_nanosleep(), switch_time_set_timerfd(), switch_time_set_use_system_time(), SWITCH_TRUE, switch_true(), switch_xml_attr_soft(), switch_xml_child(), switch_xml_free(), switch_xml_open_cfg(), switch_runtime::switchname, switch_runtime::timer_affinity, switch_runtime::tipping_point, and zstr.

Referenced by switch_core_init(), and switch_core_init_and_modload().

2054 {
2055  switch_xml_t xml = NULL, cfg = NULL;
2056 
2060 
2061 
2062  if ((xml = switch_xml_open_cfg(file, &cfg, NULL))) {
2063  switch_xml_t settings, param;
2064 
2065  if ((settings = switch_xml_child(cfg, "default-ptimes"))) {
2066  for (param = switch_xml_child(settings, "codec"); param; param = param->next) {
2067  const char *var = switch_xml_attr_soft(param, "name");
2068  const char *val = switch_xml_attr_soft(param, "ptime");
2069 
2070  if (!zstr(var) && !zstr(val)) {
2071  uint32_t *p;
2072  uint32_t v = switch_atoul(val);
2073 
2074  if (!strcasecmp(var, "G723") || !strcasecmp(var, "iLBC")) {
2075  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding %s, defaults cannot be changed\n", var);
2076  continue;
2077  }
2078 
2079  if (v == 0) {
2080  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding %s, invalid ptime\n", var);
2081  continue;
2082  }
2083 
2084  p = switch_core_alloc(runtime.memory_pool, sizeof(*p));
2085  *p = v;
2087  }
2088 
2089  }
2090  }
2091 
2092  if ((settings = switch_xml_child(cfg, "settings"))) {
2093  for (param = switch_xml_child(settings, "param"); param; param = param->next) {
2094  const char *var = switch_xml_attr_soft(param, "name");
2095  const char *val = switch_xml_attr_soft(param, "value");
2096 
2097  if (!strcasecmp(var, "loglevel")) {
2098  int level;
2099  if (*val > 47 && *val < 58) {
2100  level = atoi(val);
2101  } else {
2102  level = switch_log_str2level(val);
2103  }
2104 
2105  if (level != SWITCH_LOG_INVALID) {
2107  }
2108 #ifdef HAVE_SETRLIMIT
2109  } else if (!strcasecmp(var, "dump-cores") && switch_true(val)) {
2110  struct rlimit rlp;
2111  memset(&rlp, 0, sizeof(rlp));
2112  rlp.rlim_cur = RLIM_INFINITY;
2113  rlp.rlim_max = RLIM_INFINITY;
2114  setrlimit(RLIMIT_CORE, &rlp);
2115 #endif
2116  } else if (!strcasecmp(var, "debug-level")) {
2117  int tmp = atoi(val);
2118  if (tmp > -1 && tmp < 11) {
2120  }
2121  } else if (!strcasecmp(var, "max-db-handles")) {
2122  long tmp = atol(val);
2123 
2124  if (tmp > 4 && tmp < 5001) {
2125  runtime.max_db_handles = (uint32_t) tmp;
2126  } else {
2127  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-db-handles must be between 5 and 5000\n");
2128  }
2129  } else if (!strcasecmp(var, "db-handle-timeout")) {
2130  long tmp = atol(val);
2131 
2132  if (tmp > 0 && tmp < 5001) {
2133  runtime.db_handle_timeout = (uint32_t) tmp * 1000000;
2134  } else {
2135  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "db-handle-timeout must be between 1 and 5000\n");
2136  }
2137 
2138  } else if (!strcasecmp(var, "multiple-registrations")) {
2140  } else if (!strcasecmp(var, "auto-create-schemas")) {
2141  if (switch_true(val)) {
2143  } else {
2145  }
2146  } else if (!strcasecmp(var, "session-thread-pool")) {
2147  if (switch_true(val)) {
2149  } else {
2151  }
2152  } else if (!strcasecmp(var, "auto-clear-sql")) {
2153  if (switch_true(val)) {
2155  } else {
2157  }
2158  } else if (!strcasecmp(var, "api-expansion")) {
2159  if (switch_true(val)) {
2161  } else {
2163  }
2164  } else if (!strcasecmp(var, "enable-early-hangup") && switch_true(val)) {
2166  } else if (!strcasecmp(var, "colorize-console") && switch_true(val)) {
2168  } else if (!strcasecmp(var, "core-db-pre-trans-execute") && !zstr(val)) {
2170  } else if (!strcasecmp(var, "core-db-post-trans-execute") && !zstr(val)) {
2172  } else if (!strcasecmp(var, "core-db-inner-pre-trans-execute") && !zstr(val)) {
2174  } else if (!strcasecmp(var, "core-db-inner-post-trans-execute") && !zstr(val)) {
2176  } else if (!strcasecmp(var, "dialplan-timestamps")) {
2177  if (switch_true(val)) {
2179  } else {
2181  }
2182  } else if (!strcasecmp(var, "mailer-app") && !zstr(val)) {
2184  } else if (!strcasecmp(var, "mailer-app-args") && val) {
2186  } else if (!strcasecmp(var, "sessions-per-second") && !zstr(val)) {
2188  } else if (!strcasecmp(var, "max-dtmf-duration") && !zstr(val)) {
2189  int tmp = atoi(val);
2190  if (tmp > 0) {
2191  switch_core_max_dtmf_duration((uint32_t) tmp);
2192  }
2193  } else if (!strcasecmp(var, "min-dtmf-duration") && !zstr(val)) {
2194  int tmp = atoi(val);
2195  if (tmp > 0) {
2196  switch_core_min_dtmf_duration((uint32_t) tmp);
2197  }
2198  } else if (!strcasecmp(var, "default-dtmf-duration") && !zstr(val)) {
2199  int tmp = atoi(val);
2200  if (tmp > 0) {
2201  switch_core_default_dtmf_duration((uint32_t) tmp);
2202  }
2203  } else if (!strcasecmp(var, "enable-use-system-time")) {
2205  } else if (!strcasecmp(var, "enable-monotonic-timing")) {
2207  } else if (!strcasecmp(var, "enable-softtimer-timerfd")) {
2208  int ival = 0;
2209  if (val) {
2210  if (switch_true(val)) {
2211  ival = 2;
2212  } else {
2213  if (strcasecmp(val, "broadcast")) {
2214  ival = 1;
2215  } else if (strcasecmp(val, "fd-per-timer")) {
2216  ival = 2;
2217  }
2218  }
2219  }
2221  } else if (!strcasecmp(var, "enable-clock-nanosleep")) {
2223  } else if (!strcasecmp(var, "enable-cond-yield")) {
2225  } else if (!strcasecmp(var, "enable-timer-matrix")) {
2227  } else if (!strcasecmp(var, "max-sessions") && !zstr(val)) {
2228  switch_core_session_limit(atoi(val));
2229  } else if (!strcasecmp(var, "verbose-channel-events") && !zstr(val)) {
2230  int v = switch_true(val);
2231  if (v) {
2233  } else {
2235  }
2236  } else if (!strcasecmp(var, "threaded-system-exec") && !zstr(val)) {
2237 #ifdef WIN32
2238  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "threaded-system-exec is not implemented on this platform\n");
2239 #else
2240  int v = switch_true(val);
2241  if (v) {
2243  } else {
2245  }
2246 #endif
2247  } else if (!strcasecmp(var, "min-idle-cpu") && !zstr(val)) {
2248  switch_core_min_idle_cpu(atof(val));
2249  } else if (!strcasecmp(var, "tipping-point") && !zstr(val)) {
2250  runtime.tipping_point = atoi(val);
2251  } else if (!strcasecmp(var, "cpu-idle-smoothing-depth") && !zstr(val)) {
2252  runtime.cpu_idle_smoothing_depth = atoi(val);
2253  } else if (!strcasecmp(var, "events-use-dispatch") && !zstr(val)) {
2255  } else if (!strcasecmp(var, "initial-event-threads") && !zstr(val)) {
2256  int tmp;
2257 
2261  "Implicitly setting events-use-dispatch based on usage of this initial-event-threads parameter.\n");
2262  }
2263 
2264  tmp = atoi(val);
2265 
2266  if (tmp > runtime.cpu_count / 2) {
2267  tmp = runtime.cpu_count / 2;
2268  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "This value cannot be higher than %d so setting it to that value\n",
2269  runtime.cpu_count / 2);
2270  }
2271 
2272  if (tmp < 1) {
2273  tmp = 1;
2274  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "This value cannot be lower than 1 so setting it to that level\n");
2275  }
2276 
2278 
2279  } else if (!strcasecmp(var, "1ms-timer") && switch_true(val)) {
2281  } else if (!strcasecmp(var, "timer-affinity") && !zstr(val)) {
2282  if (!strcasecmp(val, "disabled")) {
2283  runtime.timer_affinity = -1;
2284  } else {
2285  runtime.timer_affinity = atoi(val);
2286  }
2287  } else if (!strcasecmp(var, "rtp-start-port") && !zstr(val)) {
2289  } else if (!strcasecmp(var, "rtp-end-port") && !zstr(val)) {
2291  } else if (!strcasecmp(var, "rtp-port-usage-robustness") && switch_true(val)) {
2293  } else if (!strcasecmp(var, "core-db-name") && !zstr(val)) {
2295  } else if (!strcasecmp(var, "core-db-dsn") && !zstr(val)) {
2298  } else {
2299  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC AND PGSQL ARE NOT AVAILABLE!\n");
2300  }
2301  } else if (!strcasecmp(var, "core-non-sqlite-db-required") && !zstr(val)) {
2303  } else if (!strcasecmp(var, "core-dbtype") && !zstr(val)) {
2304  if (!strcasecmp(val, "MSSQL")) {
2306  } else {
2308  }
2309 #ifdef ENABLE_ZRTP
2310  } else if (!strcasecmp(var, "rtp-enable-zrtp")) {
2311  switch_core_set_variable("zrtp_enabled", val);
2312 #endif
2313  } else if (!strcasecmp(var, "switchname") && !zstr(val)) {
2316  } else if (!strcasecmp(var, "rtp-retain-crypto-keys")) {
2317  if (switch_true(val)) {
2319  "rtp-retain-crypto-keys enabled. Could be used to decrypt secure media.\n");
2320  }
2321  switch_core_set_variable("rtp_retain_crypto_keys", val);
2322  }
2323  }
2324  }
2325 
2326  if ((settings = switch_xml_child(cfg, "variables"))) {
2327  for (param = switch_xml_child(settings, "variable"); param; param = param->next) {
2328  const char *var = switch_xml_attr_soft(param, "name");
2329  const char *val = switch_xml_attr_soft(param, "value");
2330  if (var && val) {
2331  switch_core_set_variable(var, val);
2332  }
2333  }
2334  }
2335 
2336  switch_xml_free(xml);
2337  }
2338 
2339 
2340 }
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
char * core_db_inner_post_trans_execute
const char * switch_xml_attr_soft(_In_ switch_xml_t xml, _In_z_ const char *attr)
returns the value of the requested tag attribute, or "" if not found
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
switch_bool_t switch_pgsql_available(void)
Definition: switch_pgsql.c:819
#define SWITCH_CHANNEL_LOG
uint32_t switch_core_sessions_per_second(_In_ uint32_t new_limit)
Set/Get Session Rate Limit.
void switch_time_set_nanosleep(switch_bool_t enable)
Definition: switch_time.c:365
int32_t timer_affinity
char * core_db_post_trans_execute
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
void switch_event_launch_dispatch_threads(uint32_t max)
Definition: switch_event.c:623
A representation of an XML tree.
Definition: switch_xml.h:76
void switch_time_set_timerfd(int enable)
Definition: switch_time.c:347
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
switch_port_t switch_rtp_set_start_port(switch_port_t port)
Set/Get RTP start port.
Definition: switch_rtp.c:2387
uint32_t microseconds_per_tick
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1664
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:655
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
switch_hash_t * ptimes
switch_dbtype_t odbc_dbtype
switch_xml_t next
Definition: switch_xml.h:88
switch_bool_t colorize_console
void switch_time_set_matrix(switch_bool_t enable)
Definition: switch_time.c:359
switch_log_level_t switch_log_str2level(_In_z_ const char *str)
Return the level number of the specified log level name.
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
static uint32_t d_30
Definition: switch_core.c:2051
switch_port_t switch_rtp_set_end_port(switch_port_t port)
Set/Get RTP end port.
Definition: switch_rtp.c:2401
unsigned long switch_atoul(const char *nptr)
switch_bool_t switch_odbc_available(void)
Definition: switch_odbc.c:738
void switch_core_set_variable(const char *varname, const char *value)
Definition: switch_core.c:430
uint32_t db_handle_timeout
uint16_t switch_port_t
double switch_core_min_idle_cpu(double new_limit)
uint32_t switch_core_default_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1681
uint32_t switch_core_session_limit(_In_ uint32_t new_limit)
Set/Get Session Limit.
void switch_time_set_monotonic(switch_bool_t enable)
Definition: switch_time.c:330
switch_xml_t switch_xml_open_cfg(_In_z_ const char *file_path, _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params)
open a config in the core registry
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1410
uint32_t tipping_point
uint32_t max_db_handles
switch_xml_t switch_xml_child(_In_ switch_xml_t xml, _In_z_ const char *name)
returns the first child tag (one level deeper) with the given name or NULL \ if not found ...
void switch_time_set_use_system_time(switch_bool_t enable)
Definition: switch_time.c:341
char * core_db_pre_trans_execute
uint32_t port_alloc_flags
void switch_time_set_cond_yield(switch_bool_t enable)
Definition: switch_time.c:372
switch_memory_pool_t * memory_pool
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
uint32_t cpu_idle_smoothing_depth
int32_t switch_core_session_ctl(switch_session_ctl_t cmd, void *val)
send a control message to the core
Definition: switch_core.c:2528
char * core_db_inner_pre_trans_execute
memset(buf, 0, buflen)
int switch_max_file_desc ( void  )

Definition at line 3080 of file switch_core.c.

Referenced by switch_close_extra_files().

3081 {
3082  int max = 0;
3083 
3084 #ifndef WIN32
3085 #if defined(HAVE_GETDTABLESIZE)
3086  max = getdtablesize();
3087 #else
3088  max = sysconf(_SC_OPEN_MAX);
3089 #endif
3090 #endif
3091 
3092  return max;
3093 
3094 }
SWITCH_STANDARD_SCHED_FUNC ( heartbeat_callback  )

Definition at line 202 of file switch_core.c.

References send_heartbeat(), and switch_epoch_time_now().

203 {
204  send_heartbeat();
205 
206  /* reschedule this task */
207  task->runtime = switch_epoch_time_now(NULL) + 20;
208 }
static void send_heartbeat(void)
Definition: switch_core.c:67
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
SWITCH_STANDARD_SCHED_FUNC ( check_ip_callback  )

Definition at line 211 of file switch_core.c.

References check_ip(), and switch_epoch_time_now().

212 {
213  check_ip();
214 
215  /* reschedule this task */
216  task->runtime = switch_epoch_time_now(NULL) + 60;
217 }
static void check_ip(void)
Definition: switch_core.c:109
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
int switch_stream_system_fork ( const char *  cmd,
switch_stream_handle_t stream 
)

Definition at line 3206 of file switch_core.c.

References switch_close_extra_files(), switch_fork(), switch_system(), and SWITCH_TRUE.

Referenced by preprocess_exec_set(), and switch_stream_system().

3207 {
3208 #ifdef WIN32
3209  return switch_system(cmd, SWITCH_TRUE);
3210 #else
3211  int fds[2], pid = 0;
3212 
3213  if (pipe(fds)) {
3214  goto end;
3215  } else { /* good to go */
3216  pid = switch_fork();
3217 
3218  if (pid < 0) { /* ok maybe not */
3219  close(fds[0]);
3220  close(fds[1]);
3221  goto end;
3222  } else if (pid) { /* parent */
3223  char buf[1024] = "";
3224  int bytes;
3225  close(fds[1]);
3226  while ((bytes = read(fds[0], buf, sizeof(buf))) > 0) {
3227  stream->raw_write_function(stream, (unsigned char *)buf, bytes);
3228  }
3229  close(fds[0]);
3230  waitpid(pid, NULL, 0);
3231  } else { /* child */
3232  switch_close_extra_files(fds, 2);
3233  close(fds[0]);
3234  dup2(fds[1], STDOUT_FILENO);
3235  switch_system(cmd, SWITCH_TRUE);
3236  close(fds[1]);
3237  exit(0);
3238  }
3239  }
3240 
3241  end:
3242 
3243  return 0;
3244 
3245 #endif
3246 
3247 }
switch_stream_handle_raw_write_function_t raw_write_function
void switch_close_extra_files(int *keep, int keep_ttl)
Definition: switch_core.c:3096
int switch_system(const char *cmd, switch_bool_t wait)
Definition: switch_core.c:3194
switch_byte_t switch_byte_t * buf
pid_t switch_fork(void)
Definition: switch_core.c:3134
static int switch_system_fork ( const char *  cmd,
switch_bool_t  wait 
)
static

Definition at line 3147 of file switch_core.c.

References memset(), SWITCH_CHANNEL_LOG, switch_close_extra_files(), switch_core_set_signal_handlers(), switch_fork(), SWITCH_LOG_ERROR, and switch_log_printf().

Referenced by switch_system().

3148 {
3149  int pid;
3150  char *dcmd = strdup(cmd);
3151 #if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
3152  struct rlimit rlim;
3153  struct rlimit rlim_save;
3154 #endif
3155 
3157 
3158  pid = switch_fork();
3159 
3160  if (pid) {
3161  if (wait) {
3162  waitpid(pid, NULL, 0);
3163  }
3164  free(dcmd);
3165  } else {
3166  switch_close_extra_files(NULL, 0);
3167 
3168 #if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
3169  memset(&rlim, 0, sizeof(rlim));
3170  getrlimit(RLIMIT_STACK, &rlim);
3171 
3172  memset(&rlim_save, 0, sizeof(rlim_save));
3173  getrlimit(RLIMIT_STACK, &rlim_save);
3174 
3175  rlim.rlim_cur = rlim.rlim_max;
3176  if (setrlimit(RLIMIT_STACK, &rlim) < 0) {
3177  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setting stack size failed! (%s)\n", strerror(errno));
3178  }
3179 #endif
3180 
3181  if (system(dcmd) == -1) {
3182  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute because of a command error : %s\n", dcmd);
3183  }
3184  free(dcmd);
3185  exit(0);
3186  }
3187 
3188  return 0;
3189 }
void switch_core_set_signal_handlers(void)
Definition: switch_core.c:2494
#define SWITCH_CHANNEL_LOG
void switch_close_extra_files(int *keep, int keep_ttl)
Definition: switch_core.c:3096
pid_t switch_fork(void)
Definition: switch_core.c:3134
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
memset(buf, 0, buflen)
static int switch_system_thread ( const char *  cmd,
switch_bool_t  wait 
)
static

Definition at line 3041 of file switch_core.c.

References system_thread_handle::cmd, system_thread_handle::cond, system_thread_handle::mutex, pool, system_thread_handle::pool, system_thread_handle::ret, SWITCH_CHANNEL_LOG, switch_core_alloc, switch_core_destroy_memory_pool, switch_core_new_memory_pool, switch_core_strdup, SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_init(), switch_mutex_lock(), SWITCH_MUTEX_NESTED, switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, SWITCH_SYSTEM_THREAD_STACKSIZE, switch_thread_cond_create(), switch_thread_cond_wait(), switch_thread_create(), switch_threadattr_create(), switch_threadattr_detach_set(), switch_threadattr_stacksize_set(), system_thread(), and thread.

Referenced by switch_system().

3042 {
3044  switch_threadattr_t *thd_attr;
3045  int ret = 0;
3046  struct system_thread_handle *sth;
3048 
3051  return 1;
3052  }
3053 
3054  if (!(sth = switch_core_alloc(pool, sizeof(struct system_thread_handle)))) {
3056  return 1;
3057  }
3058 
3059  sth->pool = pool;
3060  sth->cmd = switch_core_strdup(pool, cmd);
3061 
3062  switch_thread_cond_create(&sth->cond, sth->pool);
3064  switch_mutex_lock(sth->mutex);
3065 
3066  switch_threadattr_create(&thd_attr, sth->pool);
3068  switch_threadattr_detach_set(thd_attr, 1);
3069  switch_thread_create(&thread, thd_attr, system_thread, sth, sth->pool);
3070 
3071  if (wait) {
3072  switch_thread_cond_wait(sth->cond, sth->mutex);
3073  ret = sth->ret;
3074  }
3075  switch_mutex_unlock(sth->mutex);
3076 
3077  return ret;
3078 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
Definition: switch_apr.c:350
#define SWITCH_CHANNEL_LOG
switch_mutex_t * mutex
Definition: switch_core.c:2993
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_memory_pool_t * pool
switch_status_t switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
Definition: switch_apr.c:355
static switch_thread_t * thread
Definition: switch_log.c:279
switch_thread_cond_t * cond
Definition: switch_core.c:2992
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_status_t switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
Definition: switch_apr.c:655
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
#define SWITCH_SYSTEM_THREAD_STACKSIZE
Definition: switch_types.h:552
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
static void *SWITCH_THREAD_FUNC system_thread(switch_thread_t *thread, void *obj)
Definition: switch_core.c:2999
struct apr_thread_t switch_thread_t
Definition: switch_apr.h:941
struct apr_pool_t switch_memory_pool_t
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:642
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:675
switch_memory_pool_t * pool
Definition: switch_core.c:2994
static void* SWITCH_THREAD_FUNC system_thread ( switch_thread_t thread,
void *  obj 
)
static

Definition at line 2999 of file switch_core.c.

References system_thread_handle::cmd, system_thread_handle::cond, system_thread_handle::fds, memset(), system_thread_handle::mutex, system_thread_handle::pool, system_thread_handle::ret, SWITCH_CHANNEL_LOG, switch_core_destroy_memory_pool, SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), and switch_thread_cond_signal().

Referenced by switch_system_thread().

3000 {
3001  struct system_thread_handle *sth = (struct system_thread_handle *) obj;
3002 
3003 #if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
3004  struct rlimit rlim;
3005  struct rlimit rlim_save;
3006 
3007  memset(&rlim, 0, sizeof(rlim));
3008  getrlimit(RLIMIT_STACK, &rlim);
3009 
3010  memset(&rlim_save, 0, sizeof(rlim_save));
3011  getrlimit(RLIMIT_STACK, &rlim_save);
3012 
3013  rlim.rlim_cur = rlim.rlim_max;
3014  if (setrlimit(RLIMIT_STACK, &rlim) < 0) {
3015  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setting stack size failed! (%s)\n", strerror(errno));
3016  }
3017 #endif
3018 
3019  if (sth->fds) {
3020  dup2(sth->fds[1], STDOUT_FILENO);
3021  }
3022 
3023  sth->ret = system(sth->cmd);
3024 
3025 #if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
3026  if (setrlimit(RLIMIT_STACK, &rlim_save) < 0) {
3027  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setting stack size failed! (%s)\n", strerror(errno));
3028  }
3029 #endif
3030 
3031  switch_mutex_lock(sth->mutex);
3033  switch_mutex_unlock(sth->mutex);
3034 
3036 
3037  return NULL;
3038 }
#define SWITCH_CHANNEL_LOG
switch_mutex_t * mutex
Definition: switch_core.c:2993
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_thread_cond_t * cond
Definition: switch_core.c:2992
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_status_t switch_thread_cond_signal(switch_thread_cond_t *cond)
Definition: switch_apr.c:371
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
memset(buf, 0, buflen)
switch_memory_pool_t * pool
Definition: switch_core.c:2994

Variable Documentation

uint32_t d_30 = 30
static

Definition at line 2051 of file switch_core.c.

switch_ip_list_t IP_LIST = { 0 }
static

Definition at line 1364 of file switch_core.c.

char main_ip4[256] = ""
static

Definition at line 106 of file switch_core.c.

Referenced by check_ip().

char main_ip6[256] = ""
static

Definition at line 107 of file switch_core.c.

Referenced by check_ip().

struct switch_runtime runtime = { 0 }

Definition at line 64 of file switch_core.c.

Referenced by _switch_cache_db_get_db_handle(), _switch_core_db_handle(), switch_cache_db_create_schema(), switch_cache_db_test_reactive(), switch_cond_next(), switch_cond_yield(), switch_core_add_registration(), switch_core_db_test_reactive(), switch_core_del_registration(), switch_core_expire_registration(), switch_core_idle_cpu(), switch_core_min_idle_cpu(), switch_core_port_allocator_new(), switch_core_session_event_send(), switch_core_session_findall(), switch_core_session_findall_matching_var(), switch_core_session_hangup_state(), switch_core_session_hupall(), switch_core_session_hupall_endpoint(), switch_core_session_hupall_matching_var_ans(), switch_core_session_id_dec(), switch_core_session_message_send(), switch_core_session_perform_destroy(), switch_core_session_perform_force_locate(), switch_core_session_perform_locate(), switch_core_session_read_frame(), switch_core_session_read_video_frame(), switch_core_session_request_uuid(), switch_core_session_set_uuid(), switch_core_session_sync_clock(), switch_core_session_thread_launch(), switch_core_sessions_per_second(), switch_core_sql_db_thread(), switch_core_sql_exec(), switch_core_sqldb_start(), switch_core_sqldb_start_thread(), switch_event_fire_detailed(), switch_event_shutdown(), switch_log_vprintf(), switch_micro_time_now(), SWITCH_MODULE_LOAD_FUNCTION(), SWITCH_MODULE_RUNTIME_FUNCTION(), switch_new_profile_timer(), switch_simple_email(), switch_sql_concat(), switch_time_calibrate_clock(), switch_time_sync(), switch_user_sql_thread(), switch_uuid_get(), timer_destroy(), timer_init(), and timer_next().

switch_directories SWITCH_GLOBAL_dirs = { 0 }
switch_filenames SWITCH_GLOBAL_filenames = { 0 }