main.c File Reference

Command line parsing, initializiation and server startup. More...

#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_aliasaliases = 0
int auto_aliases = 1
struct socket_infobind_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_infosendipv4
struct socket_infosendipv6
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_infoudp_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


Detailed Description

Command line parsing, initializiation and server startup.

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.


Function Documentation

void cleanup ( int  show_status  ) 

Clean up on exit. This should be called before exiting.

Parameters:
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   ) 

Install the signal handlers.

Returns:
0 on success, -1 on error

Definition at line 591 of file main.c.

References LM_ERR, and sig_usr().

Referenced by main().

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.

Parameters:
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 
)

static int main_loop ( void   )  [static]

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

Parameters:
signo signal for killing the children
See also:
sig_alarm_kill

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

Parameters:
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

Parameters:
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().


Variable Documentation

struct host_alias* aliases = 0

name aliases list

Definition at line 295 of file main.c.

Referenced by print_aliases().

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().

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

cfg parsing

Definition at line 301 of file main.c.

char* cfg_file = 0

Definition at line 177 of file main.c.

Referenced by get_pathname(), and main().

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

Definition at line 236 of file main.c.

Referenced by daemonize().

char compiled[] = __TIME__ " " __DATE__

Definition at line 147 of file main.c.

Referenced by main().

int config_check = 0

Definition at line 209 of file main.c.

Referenced by main().

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().

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* flags = KAMAILIO_COMPILE_FLAGS [static]

Definition at line 146 of file main.c.

int gid = 0

Definition at line 240 of file main.c.

char* group = 0

char id[] = "@(#) $Id: main.c 5722 2009-03-19 09:13:44Z miconda $" [static]

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

log facility (see syslog(3))

Definition at line 206 of file main.c.

char* log_name = 0

the id to be printed in syslog

Definition at line 208 of file main.c.

Referenced by main().

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

export command-line to anywhere else

Definition at line 307 of file main.c.

Referenced by mi_arg().

char** my_argv

Definition at line 308 of file main.c.

Referenced by mi_arg().

int no_daemon = 0

Definition at line 202 of file main.c.

Referenced by main().

int open_files_limit = -1

don't touch it by default

Definition at line 244 of file main.c.

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

Definition at line 317 of file main.c.

Referenced by daemonize().

char* pid_file = 0

filename as asked by user

Definition at line 316 of file main.c.

Referenced by daemonize().

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().

ipv4 socket to use when msg. comes from ipv6

Definition at line 270 of file main.c.

Referenced by get_send_socket().

same as above for ipv6

Definition at line 271 of file main.c.

Referenced by get_send_socket().

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().

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

Definition at line 255 of file main.c.

Referenced by udp_init().

struct socket_info* udp_listen = 0

int uid = 0

Definition at line 239 of file main.c.

char* user = 0

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]

char* working_dir = 0

Definition at line 235 of file main.c.

Referenced by daemonize().

FILE* yyin


Generated on Thu Feb 9 08:01:10 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6