Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

main.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <sys/utsname.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 <sys/ioctl.h>
#include <net/if.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 "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 "nonsip_hooks.h"
#include "ut.h"
#include "signals.h"
#include "usr_avp.h"
#include "core_cmd.h"
#include "flags.h"
#include "lock_ops_init.h"
#include "atomic_ops_init.h"
#include "rand/fastrand.h"
#include "stats.h"
#include "cfg/cfg.h"
#include "cfg/cfg_struct.h"
#include "cfg_core.h"
#include "endianness.h"
#include "basex.h"
#include "version.h"

Go to the source code of this file.

Defines

#define SIG_DEBUG
#define MAX_FD   32
#define PROTO2UINT3(a, b, c)
#define PROTO2UINT4(a, b,c,d)

Functions

void print_ct_constants ()
int yyparse ()
void cleanup (show_status)
void kill_all_children (int signum)
void sig_alarm_kill (int signo)
void sig_alarm_abort (int signo)
void shutdown_children (int sig, int show_status)
void handle_sigs ()
void sig_usr (int signo)
int install_sigs ()
int parse_proto (unsigned char *s, long len, int *proto)
name_lstmk_name_lst_elem (char *name, int name_len, int flags)
void free_name_lst (struct name_lst *lst)
name_lstparse_name_lst (char *h, int h_len)
name_lstparse_phostport (char *s, char **host, int *hlen, int *port, int *proto)
int fix_cfg_file (void)
 Update cfg_file variable to contain full pathname.
int main_loop ()
int calc_proc_no (void)
int main (int argc, char **argv)

Variables

char id [] = "@(#) $Id: main.c,v 1.276 2009/09/03 09:56:17 tirpi Exp $"
char * version = SER_FULL_VERSION
char * flags = SER_COMPILE_FLAGS
char compiled [] = __TIME__ " " __DATE__
char help_msg []
int own_pgid = 0
char * mods_dir = MODS_DIR
char * cfg_file = 0
unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE
int children_no = 0
process_tablept = 0
intprocess_count = 0
gen_lock_t * process_lock
int process_no = 0
time_t up_since
int sig_flag = 0
int dont_fork = 0
int dont_daemonize = 0
int log_stderr = 0
pid_t creator_pid = (pid_t) -1
int config_check = 0
int check_via = 0
int phone2tel = 1
int syn_branch = 1
int memlog = L_DBG
int memdbg = L_DBG
int timerlog = L_WARN
int sip_warning = 1
int server_signature = 1
int mhomed = 0
int received_dns = 0
char * working_dir = 0
char * chroot_dir = 0
char * user = 0
char * group = 0
int uid = 0
int gid = 0
char * sock_user = 0
char * sock_group = 0
int sock_uid = -1
int sock_gid = -1
int sock_mode = S_IRUSR| S_IWUSR| S_IRGRP| S_IWGRP
int server_id = 0
int disable_core_dump = 0
int open_files_limit = -1
int shm_force_alloc = 0
int mlock_pages = 0
int real_time = 0
int rt_prio = 0
int rt_policy = 0
int rt_timer1_prio = 0
int rt_timer2_prio = 0
int rt_timer1_policy = 0
int rt_timer2_policy = 0
int reply_to_via = 0
int tos = IPTOS_LOWDELAY
int pmtu_discovery = 0
socket_infoudp_listen = 0
socket_infobind_address = 0
socket_infosendipv4
socket_infosendipv6
unsigned short port_no = 0
host_aliasaliases = 0
int child_rank = 0
int ser_kill_timeout = DEFAULT_SER_KILL_TIMEOUT
int cfg_errors = 0
int cfg_warnings = 0
unsigned long shm_mem_size = SHM_MEM_SIZE * 1024 * 1024
int my_argc
char ** my_argv
FILE * yyin
int is_main = 1
int fixup_complete = 0
char * pid_file = 0
char * pgid_file = 0


Define Documentation

#define MAX_FD   32
 

Definition at line 470 of file main.c.

#define PROTO2UINT3 a,
b,
 ) 
 

Value:

((      (((unsigned int)(a))<<16)+ \
                                                                (((unsigned int)(b))<<8)+  \
                                                                ((unsigned int)(c)) ) | 0x20202020)

Referenced by parse_proto().

#define PROTO2UINT4 a,
b,
c,
 ) 
 

Value:

((      (((unsigned int)(a))<<24)+ \
                                                                        (((unsigned int)(b))<<16)+ \
                                                                        (((unsigned int)(c))<< 8)+ \
                                                                        (((unsigned int)(d))) \
                                                                  )| 0x20202020 )

Referenced by parse_proto().

#define SIG_DEBUG
 

Definition at line 184 of file main.c.


Function Documentation

int calc_proc_no void   )  [static]
 

Definition at line 1467 of file main.c.

References children_no, dont_fork, switchboard_item::next, and si.

Referenced by main().

void cleanup show_status   ) 
 

Definition at line 486 of file main.c.

References cfg_destroy(), core_cfg, destroy_atomic_ops(), destroy_dns_cache(), destroy_dst_blacklist(), destroy_lock_ops(), destroy_modules(), destroy_nonsip_hooks(), destroy_routes(), destroy_script_cb(), destroy_sctp(), destroy_tcp(), destroy_timer(), LOG, memlog, pgid_file, pid_file, pkg_status, and pt.

Referenced by dbops_func().

int fix_cfg_file void   ) 
 

Update cfg_file variable to contain full pathname.

The function updates the value of cfg_file global variable to contain full absolute pathname to the main configuration file of SER. The function uses CFG_FILE macro to determine the default path to the configuration file if the user did not specify one using the command line option. If cfg_file contains an absolute pathname then it is used unmodified, if it contains a relative pathanme than the value returned by getcwd function will be added at the beginning. This function must be run before SER changes its current working directory to / (in daemon mode).

Returns:
Zero on success, negative number on error.

Definition at line 1055 of file main.c.

References cfg_file, and pathmax().

Referenced by main().

void free_name_lst struct name_lst lst  )  [static]
 

Definition at line 871 of file main.c.

References name_lst::next, and pkg_free.

Referenced by main(), and parse_name_lst().

void handle_sigs  ) 
 

Definition at line 622 of file main.c.

References DBG, exit, L_ALERT, L_CRIT, L_INFO, L_NOTICE, L_WARN, LOG, memlog, NAME, pkg_status, shutdown_children(), and sig_flag.

Referenced by main_loop(), and sig_usr().

int install_sigs  ) 
 

Definition at line 766 of file main.c.

References ERR, set_sig_h, and sig_usr().

Referenced by main().

void kill_all_children int  signum  )  [static]
 

Definition at line 555 of file main.c.

References L_CRIT, LOG, process_table::pid, process_lock, and pt.

Referenced by shutdown_children(), and sig_alarm_kill().

int main int  argc,
char **  argv
 

Definition at line 1497 of file main.c.

References add_listen_iface(), calc_proc_no(), cfg_declare(), cfg_errors, cfg_file, cfg_init(), cfg_shmize(), cfg_sizeof, cfg_warnings, check_via, children_no, chroot_dir, compiled, config_check, core_cfg, core_cfg_def, creator_pid, daemonize(), DBG, cfg_group_core::debug, default_core_cfg, cfg_group_core::dns_try_ipv6, dont_daemonize, dont_fork, endianness_sanity_check(), exit, fastrand(), fastrand_seed(), fix_all_socket_lists(), fix_cfg_file(), fix_rls(), fixup_complete, name_lst::flags, flags, free_name_lst(), get_max_procs(), get_poll_type(), gid, group, group2gid(), help_msg, increase_open_fds(), init_atomic_ops(), init_avps(), init_basex(), init_dns_cache(), init_dst_blacklist(), init_lock_ops(), init_modules(), init_named_flags(), init_nonsip_hooks(), init_pkg_mallocs(), init_proto_order(), init_pt(), init_routes(), init_sctp(), init_sctp_options(), init_shm_mallocs(), init_tcp(), init_tcp_options(), init_timer(), install_sigs(), L_CRIT, L_INFO, L_WARN, LOG, log_stderr, main_loop(), maxbuffer, mem_lock_pages(), mods_dir, my_argc, my_argv, name_lst::name, socket_info::next, name_lst::next, open, open_files_limit, parse_phostport(), pgid_file, pid_file, PKG_MEM_POOL_SIZE, poll_support, port_no, print_aliases(), print_all_socket_lists(), print_ct_constants(), print_rls(), rand, real_time, received_dns, register_builtin_modules(), resolv_init(), rpc_init_time(), rt_policy, rt_prio, sctp_check_compiled_sockopts(), sctp_check_support(), sctp_register_cfg(), set_core_dump(), set_rt_prio(), shm_force_alloc, shm_mem_size, shutdown_children(), socket_types, stat_file, tcp_register_cfg(), udp_listen, uid, up_since, user, user2uid(), version, working_dir, yyin, and yyparse().

int main_loop  ) 
 

Definition at line 1092 of file main.c.

References socket_info::address, ip_addr::af, arm_slow_timer(), arm_timer(), bind_address, cfg_register_child(), child_rank, children_no, close_extra_socks(), DBG, do_suid(), fork_process(), get_max_open_fds(), get_proc_no, handle_sigs(), init_child(), L_CRIT, L_ERR, L_WARN, LOG, MAX_PT_DESC, switchboard_item::name, socket_info::name, switchboard_item::next, socket_info::next, process_table::pid, socket_info::port_no_str, PROC_ATTENDANT, PROC_INIT, PROC_MAIN, PROC_TCP_MAIN, PROC_TIMER, process_no, pt, real_time, rt_timer1_policy, rt_timer1_prio, rt_timer2_policy, rt_timer2_prio, _str::s, sctp_init_sock(), sctp_rcv_loop(), sendipv4, sendipv6, set_rt_prio(), si, SI_IS_LO, slow_timer_main(), slow_timer_pid, snprintf, tcp_init(), tcp_init_children(), tcp_main_loop(), timer_main(), udp_init(), udp_listen, udp_rcv_loop(), and USE_SLOW_TIMER.

Referenced by main().

struct name_lst* mk_name_lst_elem char *  name,
int  name_len,
int  flags
[static]
 

Definition at line 852 of file main.c.

References name_lst::flags, name_lst::name, name_lst::next, and pkg_malloc.

Referenced by parse_name_lst().

struct name_lst* parse_name_lst char *  h,
int  h_len
[static]
 

Definition at line 891 of file main.c.

References flags, free_name_lst(), mk_name_lst_elem(), and name_lst::next.

Referenced by parse_phostport().

struct name_lst* parse_phostport char *  s,
char **  host,
int hlen,
int port,
int proto
[static]
 

Definition at line 960 of file main.c.

References L_ERR, LOG, parse_name_lst(), parse_proto(), and s.

Referenced by main().

int parse_proto unsigned char *  s,
long  len,
int proto
[static]
 

Definition at line 805 of file main.c.

References len, likely, PROTO2UINT3, PROTO2UINT4, and s.

Referenced by parse_phostport().

void print_ct_constants  ) 
 

Definition at line 244 of file main.c.

References BUF_SIZE, MAX_LISTEN, MAX_RECV_BUFFER_SIZE, MAX_URI_SIZE, and poll_support.

Referenced by main().

void shutdown_children int  sig,
int  show_status
[static]
 

Definition at line 603 of file main.c.

References cleanup(), kill_all_children(), L_ERR, LOG, ser_kill_timeout, set_sig_h, sig_alarm_abort(), and sig_alarm_kill().

Referenced by handle_sigs(), and main().

void sig_alarm_abort int  signo  )  [static]
 

Definition at line 594 of file main.c.

References L_CRIT, and LOG.

Referenced by shutdown_children().

void sig_alarm_kill int  signo  )  [static]
 

Definition at line 582 of file main.c.

References kill_all_children().

Referenced by shutdown_children().

void sig_usr int  signo  ) 
 

Definition at line 710 of file main.c.

References DBG, handle_sigs(), L_INFO, LOG, memlog, pkg_status, and sig_flag.

Referenced by install_sigs(), and slow_timer_main().

int yyparse  ) 
 


Variable Documentation

struct host_alias* aliases = 0
 

Definition at line 446 of file main.c.

Referenced by add_alias().

struct socket_info* bind_address = 0
 

Definition at line 415 of file main.c.

Referenced by child_init_callid(), faked_env(), get_send_socket(), main_loop(), uac_init(), and udp_rcv_loop().

int cfg_errors = 0
 

Definition at line 459 of file main.c.

Referenced by main(), and yyerror().

char* cfg_file = 0
 

Definition at line 287 of file main.c.

Referenced by fix_cfg_file(), get_abs_pathname(), get_pathname(), and main().

int cfg_warnings = 0
 

Definition at line 460 of file main.c.

Referenced by main(), and warn().

int check_via = 0
 

Definition at line 324 of file main.c.

Referenced by main(), and yyparse().

int child_rank = 0
 

Definition at line 449 of file main.c.

Referenced by main_loop().

int children_no = 0
 

Definition at line 292 of file main.c.

Referenced by calc_proc_no(), main(), main_loop(), and yyparse().

char* chroot_dir = 0
 

Definition at line 351 of file main.c.

Referenced by daemonize(), main(), and yyparse().

char compiled[] = __TIME__ " " __DATE__
 

Definition at line 190 of file main.c.

Referenced by main(), and sercmd_ver().

int config_check = 0
 

Definition at line 322 of file main.c.

Referenced by main().

pid_t creator_pid = (pid_t) -1
 

Definition at line 321 of file main.c.

Referenced by main().

int disable_core_dump = 0
 

Definition at line 365 of file main.c.

Referenced by yyparse().

int dont_daemonize = 0
 

Definition at line 319 of file main.c.

Referenced by main().

int dont_fork = 0
 

Definition at line 318 of file main.c.

Referenced by calc_proc_no(), main(), and yyparse().

int fixup_complete = 0
 

Definition at line 479 of file main.c.

Referenced by main().

char* flags = SER_COMPILE_FLAGS [static]
 

Definition at line 189 of file main.c.

Referenced by main(), and parse_name_lst().

int gid = 0
 

Definition at line 355 of file main.c.

Referenced by group2gid(), init_ctrl_sockets(), init_unix_sock(), main(), and user2uid().

char* group = 0
 

Definition at line 353 of file main.c.

Referenced by cfg_destory_groups(), cfg_fixup_selects(), cfg_get_by_name(), cfg_get_group_next(), cfg_get_handle(), cfg_lookup_var(), cfg_new_group(), cfg_register_ctx(), cfg_script_destroy(), cfg_script_fixup(), cfg_set_delayed(), cfg_set_now(), cfg_shmize(), cfg_shmize_strings(), cfg_update_local(), group2gid(), main(), new_cfg_script_var(), rpc_get(), rpc_help(), rpc_set_delayed_int(), rpc_set_delayed_string(), rpc_set_now_int(), rpc_set_now_string(), select_cfg_var(), and yyparse().

char help_msg[] [static]
 

Definition at line 193 of file main.c.

Referenced by main().

char id[] = "@(#) $Id: main.c,v 1.276 2009/09/03 09:56:17 tirpi Exp $" [static]
 

Definition at line 187 of file main.c.

int is_main = 1
 

Definition at line 478 of file main.c.

Referenced by fork_process(), mod_child(), and start_fifo_server().

int log_stderr = 0
 

Definition at line 320 of file main.c.

unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE
 

Definition at line 288 of file main.c.

Referenced by main(), and yyparse().

int memdbg = L_DBG
 

Definition at line 332 of file main.c.

int memlog = L_DBG
 

Definition at line 330 of file main.c.

int mhomed = 0
 

Definition at line 346 of file main.c.

Referenced by get_send_socket(), init_rb(), sl_send_reply(), and yyparse().

int mlock_pages = 0
 

Definition at line 372 of file main.c.

Referenced by yyparse().

char* mods_dir = MODS_DIR
 

Definition at line 285 of file main.c.

Referenced by load_module(), main(), and yyparse().

int my_argc
 

Definition at line 467 of file main.c.

Referenced by main().

char** my_argv
 

Definition at line 468 of file main.c.

Referenced by core_arg(), and main().

int open_files_limit = -1
 

Definition at line 366 of file main.c.

Referenced by main(), and yyparse().

int own_pgid = 0
 

Definition at line 282 of file main.c.

Referenced by daemonize().

char* pgid_file = 0
 

Definition at line 482 of file main.c.

Referenced by cleanup(), daemonize(), and main().

int phone2tel = 1
 

Definition at line 326 of file main.c.

char* pid_file = 0
 

Definition at line 481 of file main.c.

Referenced by cleanup(), daemonize(), and main().

int pmtu_discovery = 0
 

Definition at line 396 of file main.c.

Referenced by yyparse().

unsigned short port_no = 0
 

Definition at line 432 of file main.c.

Referenced by main(), parse_uri(), and yyparse().

int* process_count = 0
 

Definition at line 311 of file main.c.

Referenced by fork_process(), and init_pt().

gen_lock_t* process_lock
 

Definition at line 313 of file main.c.

Referenced by fork_process(), init_pt(), and kill_all_children().

int process_no = 0
 

Definition at line 314 of file main.c.

struct process_table* pt = 0
 

Definition at line 309 of file main.c.

Referenced by cleanup(), close_extra_socks(), core_ps(), fork_process(), get_max_open_fds(), get_max_procs(), init_pt(), kill_all_children(), main_loop(), my_pid(), pdt_add_to_tree(), pdt_free_tree(), pdt_get_domain(), pdt_init_tree(), pdt_print_tree(), pdt_remove_from_tree(), and start_fifo_server().

int real_time = 0
 

Definition at line 375 of file main.c.

Referenced by main(), main_loop(), and yyparse().

int received_dns = 0
 

Definition at line 349 of file main.c.

Referenced by comp_ip(), main(), received_test(), and yyparse().

int reply_to_via = 0
 

Definition at line 388 of file main.c.

Referenced by yyparse().

int rt_policy = 0
 

Definition at line 378 of file main.c.

Referenced by main(), and yyparse().

int rt_prio = 0
 

Definition at line 377 of file main.c.

Referenced by main(), and yyparse().

int rt_timer1_policy = 0
 

Definition at line 381 of file main.c.

Referenced by main_loop(), and yyparse().

int rt_timer1_prio = 0
 

Definition at line 379 of file main.c.

Referenced by main_loop(), and yyparse().

int rt_timer2_policy = 0
 

Definition at line 382 of file main.c.

Referenced by main_loop(), and yyparse().

int rt_timer2_prio = 0
 

Definition at line 380 of file main.c.

Referenced by main_loop(), and yyparse().

struct socket_info* sendipv4
 

Definition at line 417 of file main.c.

Referenced by main_loop().

struct socket_info* sendipv6
 

Definition at line 418 of file main.c.

Referenced by main_loop().

int ser_kill_timeout = DEFAULT_SER_KILL_TIMEOUT
 

Definition at line 452 of file main.c.

Referenced by shutdown_children(), and yyparse().

int server_id = 0
 

Definition at line 362 of file main.c.

Referenced by add_contact(), fmt2strar(), select_sys_server_id(), and yyparse().

int server_signature = 1
 

Definition at line 342 of file main.c.

Referenced by build_uac_req(), and yyparse().

int shm_force_alloc = 0
 

Definition at line 369 of file main.c.

Referenced by main(), and yyparse().

unsigned long shm_mem_size = SHM_MEM_SIZE * 1024 * 1024
 

Definition at line 464 of file main.c.

int sig_flag = 0
 

Definition at line 317 of file main.c.

Referenced by handle_sigs(), and sig_usr().

int sip_warning = 1
 

Definition at line 338 of file main.c.

Referenced by yyparse().

int sock_gid = -1
 

Definition at line 359 of file main.c.

Referenced by init_unixsock_socket().

char* sock_group = 0
 

Definition at line 357 of file main.c.

int sock_mode = S_IRUSR| S_IWUSR| S_IRGRP| S_IWGRP
 

Definition at line 360 of file main.c.

Referenced by init_unixsock_socket().

int sock_uid = -1
 

Definition at line 358 of file main.c.

Referenced by init_unixsock_socket().

char* sock_user = 0
 

Definition at line 356 of file main.c.

int syn_branch = 1
 

Definition at line 328 of file main.c.

Referenced by build_cell(), t_calc_branch(), t_reply_matching(), and yyparse().

int timerlog = L_WARN
 

Definition at line 334 of file main.c.

Referenced by timer_add_safe(), and timer_del_safe().

int tos = IPTOS_LOWDELAY
 

Definition at line 395 of file main.c.

Referenced by yyparse().

struct socket_info* udp_listen = 0
 

Definition at line 404 of file main.c.

Referenced by fix_all_socket_lists(), main(), and main_loop().

int uid = 0
 

Definition at line 354 of file main.c.

Referenced by authorize_message(), create_winfo(), db_delete_avp(), db_load_avp(), db_load_winfo(), dump_offline_winfo(), find_presentity_uid(), get_from_uid(), get_presentity(), get_to_uid(), handle_publish(), handle_renewal_subscription(), init_ctrl_sockets(), init_unix_sock(), load_user_attrs(), lookup(), lookup2(), lookup_uid(), lookup_user_2(), m_dump(), m_store(), main(), new_presentity(), new_presentity_no_wb(), pa_subscribe(), pa_unsubscribe(), pdomain_load_presentities(), query_resource_list(), read_reg_avps(), registered(), registered2(), rpc_add_contact(), rpc_authorize(), rpc_delete_contact(), rpc_delete_uid(), rpc_show_contacts(), save_real(), sd_lookup(), store_offline_winfo(), target_online(), user2uid(), xcap_get_msg_rules(), xcap_get_pres_rules(), xj_pres_cell_init(), xj_pres_list_check(), and xj_pres_list_del().

time_t up_since
 

Definition at line 316 of file main.c.

Referenced by check_nonce(), core_uptime(), main(), and rpc_init_time().

char* user = 0
 

Definition at line 352 of file main.c.

Referenced by add_user_name(), authenticate(), build_rr(), cpl_get(), cpl_invoke_script(), cpl_load(), cpl_remove(), do_action(), do_script_action(), do_script_download(), get_resource_list_from_full_doc(), get_user_script(), get_username(), insert_RR(), is_e164(), is_rule_for_uri(), main(), parse_uri(), prefix_route(), radius_authorize_sterman(), record_route_preset(), run_log(), set_new_uri_with_user(), store_user_in_avps(), subst_user_f(), test_e164(), tree_item_get(), tree_route_get(), un_escape(), user2uid(), and yyparse().

char* version = SER_FULL_VERSION [static]
 

Definition at line 188 of file main.c.

Referenced by main().

char* working_dir = 0
 

Definition at line 350 of file main.c.

Referenced by daemonize(), main(), and yyparse().

FILE* yyin
 


Generated on Thu Jul 29 04:15:55 2010 for SIPExpressRouter by  doxygen 1.3.9.1