#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <pwd.h>
#include <grp.h>
#include <signal.h>
#include <time.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include "help_msg.h"
#include "config.h"
#include "dprint.h"
#include "daemonize.h"
#include "route.h"
#include "udp_server.h"
#include "globals.h"
#include "mem/mem.h"
#include "mem/shm_mem.h"
#include "sr_module.h"
#include "timer.h"
#include "parser/msg_parser.h"
#include "ip_addr.h"
#include "resolve.h"
#include "parser/parse_hname2.h"
#include "parser/digest/digest_parser.h"
#include "name_alias.h"
#include "hash_func.h"
#include "pt.h"
#include "script_cb.h"
#include "blacklists.h"
#include "ut.h"
#include "statistics.h"
#include "pvar.h"
#include "version.h"
#include "mi/mi_core.h"
Go to the source code of this file.
Functions | |
| void | cleanup (int show_status) |
| void | handle_sigs (void) |
| int | install_sigs (void) |
| static void | kill_all_children (int signum) |
| int | main (int argc, char **argv) |
| static int | main_loop (void) |
| void | print_ct_constants (void) |
| static void | sig_alarm_abort (int signo) |
| static void | sig_alarm_kill (int signo) |
| static void | sig_usr (int signo) |
| int | yyparse () |
Variables | |
| struct host_alias * | aliases = 0 |
| int | auto_aliases = 1 |
| struct socket_info * | bind_address = 0 |
| int | cfg_errors = 0 |
| char * | cfg_file = 0 |
| int | check_via = 0 |
| int | children_no = 0 |
| char * | chroot_dir = 0 |
| char | compiled [] = __TIME__ " " __DATE__ |
| int | config_check = 0 |
| int | debug = L_NOTICE |
| int | disable_core_dump = 0 |
| int | dont_fork = 0 |
| static char * | flags = KAMAILIO_COMPILE_FLAGS |
| int | gid = 0 |
| char * | group = 0 |
| static char | id [] = "@(#) $Id: main.c 5722 2009-03-19 09:13:44Z miconda $" |
| int | is_main = 1 |
| int | log_facility = LOG_DAEMON |
| char * | log_name = 0 |
| int | log_stderr = 1 |
| unsigned int | maxbuffer = MAX_RECV_BUFFER_SIZE |
| int | memlog = L_DBG |
| int | mhomed = 0 |
| int | my_argc |
| char ** | my_argv |
| int | no_daemon = 0 |
| int | open_files_limit = -1 |
| int | own_pgid = 0 |
| char * | pgid_file = 0 |
| char * | pid_file = 0 |
| unsigned short | port_no = 0 |
| int | process_no = 0 |
| int | received_dns = 0 |
| int | reply_to_via = 0 |
| struct socket_info * | sendipv4 |
| struct socket_info * | sendipv6 |
| str | server_header = {SERVER_HDR,sizeof(SERVER_HDR)-1} |
| int | server_signature = 1 |
| unsigned long | shm_mem_size = SHM_MEM_SIZE * 1024 * 1024 |
| int | sig_flag = 0 |
| int | sip_warning = 0 |
| int | tos = IPTOS_LOWDELAY |
| struct socket_info * | udp_listen = 0 |
| int | uid = 0 |
| char * | user = 0 |
| str | user_agent_header = {USER_AGENT,sizeof(USER_AGENT)-1} |
| static char * | version = KAMAILIO_FULL_VERSION |
| char * | working_dir = 0 |
| FILE * | yyin |
Contains methods for parsing the command line, the initialization of the execution environment (signals, config file parsing) and forking the TCP, UDP, timer and fifo children.
Definition in file main.c.
| void cleanup | ( | int | show_status | ) |
Clean up on exit. This should be called before exiting.
| show_status | set to one to display the mem status |
Definition at line 324 of file main.c.
References debug, destroy_black_lists(), destroy_modules(), destroy_script_cb(), destroy_stats_collector, destroy_tcp(), destroy_timer(), destroy_tls(), LM_GEN1, mem_lock, memlog, pkg_status, pt, pv_api_destroy(), shm_free, shm_mem_destroy(), shm_status, and shm_unlock.
Referenced by bdb_update(), handle_sigs(), main(), and xmlrpc_process().
| void handle_sigs | ( | void | ) |
Signal handler for the server.
Definition at line 425 of file main.c.
References cleanup(), counted_processes, dprint(), kill_all_children(), LM_CRIT, LM_DBG, LM_ERR, LM_GEN1, LM_INFO, LM_WARN, memlog, pid, pkg_status, pt, shm_status, sig_alarm_abort(), sig_alarm_kill(), and sig_flag.
Referenced by main_loop(), and sig_usr().
| int install_sigs | ( | void | ) |
| static void kill_all_children | ( | int | signum | ) | [static] |
Tries to send a signal to all our processes If daemonized is ok to send the signal to all the process group, however if not daemonized we might end up sending the signal also to the shell which launched us => most signals will kill it if it's not in interactive mode and we don't want this. The non-daemonized case can occur when an error is encountered before daemonize is called (e.g. when parsing the config file) or when Kamailio is started in "dont-fork" mode.
| signum | signal for killing the children |
Definition at line 380 of file main.c.
References counted_processes, own_pgid, pid, and pt.
Referenced by handle_sigs(), main(), and sig_alarm_kill().
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Main routine, start of the program execution.
| argc | the number of arguments | |
| argv | pointer to the arguments array |
Definition at line 881 of file main.c.
References add_listen_iface(), CFG_FILE, cfg_file, check_rls(), check_via, CHILD_NO, children_no, cleanup(), compiled, config_check, daemonize(), debug, DO_DNS, DO_REV_DNS, dont_fork, fix_all_socket_lists(), fix_rls(), get_poll_type(), group2gid(), help_msg, increase_open_fds(), init_black_lists(), init_mi_core(), init_modules(), init_multi_proc_support(), init_pkg_mallocs(), init_route_lists(), init_shm_mallocs(), init_stats_collector, init_tcp(), init_timer(), init_tls(), install_sigs(), kill_all_children(), LM_CRIT, LM_DBG, LM_ERR, LM_INFO, LM_NOTICE, LM_WARN, log_facility, log_name, log_stderr, main_loop, maxbuffer, socket_info::next, no_daemon, own_pgid, parse_phostport(), PKG_MEM_POOL_SIZE, POLL_NONE, poll_support, port, pre_init_tls(), preinit_black_lists(), print_aliases(), print_all_socket_lists(), print_ct_constants(), print_rl(), socket_info::proto, resolv_blacklist_init(), resolv_init(), set_core_dump(), shm_malloc(), SIP_PORT, SIPS_PORT, SVNREVISION, user2uid(), version, and yyparse().
| static int main_loop | ( | void | ) | [static] |
Main loop, forks the children, bind to addresses, handle signals.
Definition at line 635 of file main.c.
References socket_info::address, ip_addr::af, children_no, do_suid(), dont_fork, socket_info::flags, handle_sigs(), init_child(), internal_fork(), _str::len, LM_CRIT, LM_ERR, LM_WARN, socket_info::next, pid, PROC_MAIN, PROC_TCP_MAIN, pt, _str::s, set_proc_attrs(), SI_IS_LO, socket_info::sock_str, start_module_procs(), start_timer_processes(), tcp_init(), tcp_init_children(), tcp_main_loop(), tls_init(), udp_init(), and udp_rcv_loop().
| void print_ct_constants | ( | void | ) |
Print compile-time constants
Definition at line 152 of file main.c.
References BUF_SIZE, MAX_LISTEN, MAX_RECV_BUFFER_SIZE, MAX_URI_SIZE, PKG_MEM_POOL_SIZE, poll_support, and SVNREVISION.
Referenced by main().
| static void sig_alarm_abort | ( | int | signo | ) | [static] |
Timeout handler during wait for children exit. like sig_alarm_kill, but the timeout has occured when cleaning up, try to leave a core for future diagnostics
| signo | signal for killing the children |
Definition at line 414 of file main.c.
References LM_CRIT.
Referenced by handle_sigs().
| static void sig_alarm_kill | ( | int | signo | ) | [static] |
Timeout handler during wait for children exit. If this handler is called, a critical timeout has occured while waiting for the children to finish => we should kill everything and exit
| signo | signal for killing the children |
Definition at line 397 of file main.c.
References kill_all_children().
Referenced by handle_sigs().
| static void sig_usr | ( | int | signo | ) | [static] |
Exit regulary on a specific signal. This is good for profiling which only works if exited regularly and not by default signal handlers
| signo | The signal that should be handled |
Definition at line 541 of file main.c.
References dont_fork, handle_sigs(), LM_DBG, LM_GEN1, LM_INFO, memlog, pkg_status, and sig_flag.
Referenced by install_sigs().
| int yyparse | ( | ) |
Referenced by main().
| struct host_alias* aliases = 0 |
| int auto_aliases = 1 |
if aliases should be automatically discovered and added during fixing listening sockets
Definition at line 288 of file main.c.
Referenced by fix_socket_list().
| struct socket_info* bind_address = 0 |
pointer to the crt. proc. listening address
Definition at line 268 of file main.c.
Referenced by child_init_callid(), faked_env(), get_send_socket(), uac_init(), and udp_rcv_loop().
| int cfg_errors = 0 |
| char* cfg_file = 0 |
| int check_via = 0 |
check if reply first via host==us
Definition at line 211 of file main.c.
Referenced by forward_reply(), and main().
| int children_no = 0 |
number of children processing requests
Definition at line 182 of file main.c.
Referenced by init_multi_proc_support(), main(), and main_loop().
| char* chroot_dir = 0 |
| char compiled[] = __TIME__ " " __DATE__ |
| int config_check = 0 |
| int debug = L_NOTICE |
server log level
Definition at line 199 of file main.c.
Referenced by cleanup(), main(), mi_debug(), reset_proc_debug_level(), and set_proc_debug_level().
| int disable_core_dump = 0 |
disable coredumps, by default enabled
Definition at line 243 of file main.c.
Referenced by daemonize(), and do_suid().
| int dont_fork = 0 |
Definition at line 201 of file main.c.
Referenced by init_multi_proc_support(), main(), main_loop(), and sig_usr().
| char* group = 0 |
Definition at line 238 of file main.c.
Referenced by allow_source_address_group(), ds_mark_dst(), ds_mi_set(), ds_options_callback(), and radius_is_user_in().
char id[] = "@(#) $Id: main.c 5722 2009-03-19 09:13:44Z miconda $" [static] |
Definition at line 144 of file main.c.
Referenced by carrier_fixup(), carrier_name_2_id(), compute_ID(), conf_destroy(), conf_show(), cr_gp2id(), db_do_init(), domain_fixup(), domain_name_2_id(), ds_load_db(), ds_load_list(), fetch_sms_id(), flat_get_connection(), forward_reply(), get_record_id(), load_user_carrier(), lookup_mi_cmd(), mi_bm_enable_timer(), mi_show_rtpproxies(), Notify2Xmpp(), parse_avp_name(), register_mi_cmd(), retransmission_handler(), stream_node_callback(), timer_routine(), utimer_routine(), and xj_jkey_free_p().
| int is_main = 1 |
flag = is this the "main" process?
Definition at line 314 of file main.c.
Referenced by internal_fork().
| int log_facility = LOG_DAEMON |
| char* log_name = 0 |
| int log_stderr = 1 |
start by logging to stderr
Definition at line 204 of file main.c.
Referenced by daemonize(), main(), pv_get_color(), and xdbg_fixup().
| unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE |
maximum buffer size we do not want to exceed during the auto-probing procedure; may be re-configured
Definition at line 178 of file main.c.
Referenced by main(), and probe_max_receive_buffer().
| int memlog = L_DBG |
debugging level for memory stats
Definition at line 213 of file main.c.
Referenced by cleanup(), handle_sigs(), qm_free(), qm_malloc(), qm_realloc(), qm_status(), and sig_usr().
| int mhomed = 0 |
should Kamailio try to locate outbound interface on multihomed host? by default not -- too expensive
Definition at line 231 of file main.c.
Referenced by get_send_socket(), and sl_send_reply_helper().
| int my_argc |
| int open_files_limit = -1 |
| int own_pgid = 0 |
whether or not we have our own pgid (and it's ok to use kill(0, sig)
Definition at line 175 of file main.c.
Referenced by kill_all_children(), and main().
| char* pgid_file = 0 |
| char* pid_file = 0 |
| unsigned short port_no = 0 |
default port
Definition at line 290 of file main.c.
Referenced by add_listen_iface(), fix_socket_list(), get_sock_hdr(), mi_mod_init(), and parse_uri().
| int process_no = 0 |
process number - 0 is the main process
Definition at line 298 of file main.c.
Referenced by dispatcher_main_loop(), internal_fork(), my_pid(), and set_proc_attrs().
| int received_dns = 0 |
use dns and/or rdns or to see if we need to add a ;received=x.x.x.x to via:
Definition at line 234 of file main.c.
Referenced by comp_ip(), and received_test().
| int reply_to_via = 0 |
a hint to reply modules whether they should send reply to IP advertised in Via or IP from which a request came
Definition at line 248 of file main.c.
Referenced by init_rb(), sl_send_reply_helper(), t_relay_to(), and w_as_relay_t().
| struct socket_info* sendipv4 |
ipv4 socket to use when msg. comes from ipv6
Definition at line 270 of file main.c.
Referenced by get_send_socket().
| struct socket_info* sendipv6 |
| str server_header = {SERVER_HDR,sizeof(SERVER_HDR)-1} |
Server header to be used when proxy generates request as UAS. Default is to use SERVER_HDR CRLF (assigned later).
Definition at line 223 of file main.c.
Referenced by build_res_buf_from_sip_req().
| int server_signature = 1 |
should localy-generated messages include server's signature?
Definition at line 219 of file main.c.
Referenced by ac_uac_req(), build_dlg_ack(), build_local(), build_res_buf_from_sip_req(), build_uac_cancel(), and build_uac_req().
| unsigned long shm_mem_size = SHM_MEM_SIZE * 1024 * 1024 |
shared memory (in MB)
Definition at line 304 of file main.c.
Referenced by init_shm_mallocs(), shm_getmem(), shm_mem_destroy(), and shm_mem_init().
| int sig_flag = 0 |
last signal received
Definition at line 194 of file main.c.
Referenced by dispatcher_main_loop(), handle_sigs(), seas_sighandler(), and sig_usr().
| int sip_warning = 0 |
should replies include extensive warnings? by default yes, good for trouble-shooting
Definition at line 217 of file main.c.
Referenced by build_res_buf_from_sip_req().
| int tos = IPTOS_LOWDELAY |
| struct socket_info* udp_listen = 0 |
Definition at line 257 of file main.c.
Referenced by find_si(), fix_all_socket_lists(), grep_sock_info(), init_multi_proc_support(), process_bind_action(), and send_sockinfo().
| char* user = 0 |
Definition at line 237 of file main.c.
Referenced by add_path(), add_path_received(), authorize(), check_user_blacklist(), cr_load_user_carrier(), diameter_is_user_in(), do_action(), mi_cpl_get(), mi_cpl_remove(), msg_presentity_clean(), parse_uri(), preload_udomain(), pres_htable_restore(), query_xcap_update(), radius_authorize_sterman(), radius_is_user_in(), radius_load_callee_avps(), radius_load_caller_avps(), record_route(), record_route_preset(), refresh_watcher(), run_log(), SessionLog(), and subst_user_f().
| str user_agent_header = {USER_AGENT,sizeof(USER_AGENT)-1} |
User-Agent header to be used when proxy generates request as UAC. Default is to use USER_AGENT CRLF (assigned later).
Definition at line 227 of file main.c.
Referenced by build_dlg_ack(), build_local(), and build_uac_req().
char* version = KAMAILIO_FULL_VERSION [static] |
Definition at line 145 of file main.c.
Referenced by AAATranslateMessage(), bla_process_body(), db_table_version(), ldap_get_vendor_version(), main(), tlsops_cert_version(), and tlsops_version().
| char* working_dir = 0 |
| FILE* yyin |
1.5.6