|
151 | 151 |
|
152 | 152 | #include "ssl_tweaks.h"
|
153 | 153 |
|
| 154 | +#include "main_script.h" |
| 155 | + |
154 | 156 | /* global vars */
|
155 | 157 |
|
156 | 158 | #ifdef VERSION_NODATE
|
@@ -195,6 +197,49 @@ static void print_ct_constants(void)
|
195 | 197 | #endif
|
196 | 198 | }
|
197 | 199 |
|
| 200 | +static int |
| 201 | +init_suid(void) |
| 202 | +{ |
| 203 | + /* all processes should have access to all the sockets (for sending) |
| 204 | + * so we open all first*/ |
| 205 | + return do_suid(user_id, group_id); |
| 206 | +} |
| 207 | + |
| 208 | +static int |
| 209 | +init_shm_mem_dbg(void) |
| 210 | +{ |
| 211 | + if (shm_memlog_size) |
| 212 | + shm_mem_enable_dbg(); |
| 213 | + return 0; |
| 214 | +} |
| 215 | + |
| 216 | +static const struct main_script main_script[] = { |
| 217 | + FN_HNDLR(init_reactor_size, <, 0, "internal reactor"), |
| 218 | + FN_HNDLR(init_timer, <, 0, "timer"), |
| 219 | + FN_HNDLR(init_shm_mem_dbg, <, 0, "shm_mem_enable_dbg"), |
| 220 | + FN_HNDLR(init_ipc, <, 0, "IPC support"), |
| 221 | + FN_HNDLR(init_serialization, !=, 0, "serialization"), |
| 222 | + FN_HNDLR(init_mi_core, <, 0, "MI core"), |
| 223 | + FN_HNDLR(evi_register_core, !=, 0, "register core events"), |
| 224 | + FN_HNDLR(init_black_lists, !=, 0, "black list engine"), |
| 225 | + FN_HNDLR(resolv_blacklist_init, !=, 0, "resolver's blacklist"), |
| 226 | + FN_HNDLR(init_dset, !=, 0, "SIP forking logic"), |
| 227 | + FN_HNDLR(init_db_support, !=, 0, "SQL database support"), |
| 228 | + FN_HNDLR(init_cdb_support, !=, 0, "CacheDB support"), |
| 229 | + FN_HNDLR(init_modules, !=, 0, "modules"), |
| 230 | + FN_HNDLR(init_xlog, <, 0, "xlog"), |
| 231 | + FN_HNDLR(register_route_timers, <, 0, "route_timers"), |
| 232 | + FN_HNDLR(init_pvar_support, !=, 0, "pseudo-variable support"), |
| 233 | + FN_HNDLR(init_multi_proc_support, !=, 0, "multi processes support"), |
| 234 | + FN_HNDLR(init_extra_avps, !=, 0, "avps"), |
| 235 | + FN_HNDLR(fix_rls, !=, 0, "routing lists"), |
| 236 | + FN_HNDLR(init_log_level, !=, 0, "logging levels"), |
| 237 | + FN_HNDLR(init_log_event_cons, <, 0, "log event consumer"), |
| 238 | + FN_HNDLR(trans_init_all_listeners, <, 0, "all SIP listeners"), |
| 239 | + FN_HNDLR(init_script_reload, <, 0, "cfg reload ctx"), |
| 240 | + FN_HNDLR(init_suid, ==, -1, "do_suid"), |
| 241 | + FN_HNDLR(run_post_fork_handlers, <, 0, "post-fork handlers"), |
| 242 | +}; |
198 | 243 |
|
199 | 244 | /**
|
200 | 245 | * Main loop, forks the children, bind to addresses,
|
@@ -344,7 +389,7 @@ static int main_loop(void)
|
344 | 389 | */
|
345 | 390 | int main(int argc, char** argv)
|
346 | 391 | {
|
347 |
| - int c,r; |
| 392 | + int c; |
348 | 393 | char *tmp;
|
349 | 394 | int tmp_len;
|
350 | 395 | int port;
|
@@ -828,142 +873,13 @@ int main(int argc, char** argv)
|
828 | 873 | LM_NOTICE("using system memory for private process memory\n");
|
829 | 874 | #endif
|
830 | 875 |
|
831 |
| - /* init async reactor */ |
832 |
| - if (init_reactor_size()<0) { |
833 |
| - LM_CRIT("failed to init internal reactor, exiting...\n"); |
834 |
| - goto error; |
835 |
| - } |
836 |
| - |
837 |
| - /* init timer */ |
838 |
| - if (init_timer()<0){ |
839 |
| - LM_CRIT("could not initialize timer, exiting...\n"); |
840 |
| - goto error; |
841 |
| - } |
842 |
| - |
843 |
| - if (shm_memlog_size) |
844 |
| - shm_mem_enable_dbg(); |
845 |
| - |
846 |
| - /* init IPC */ |
847 |
| - if (init_ipc()<0){ |
848 |
| - LM_CRIT("could not initialize IPC support, exiting...\n"); |
849 |
| - goto error; |
850 |
| - } |
851 |
| - |
852 |
| - /* init serial forking engine */ |
853 |
| - if (init_serialization()!=0) { |
854 |
| - LM_ERR("failed to initialize serialization\n"); |
855 |
| - goto error; |
856 |
| - } |
857 |
| - /* Init MI */ |
858 |
| - if (init_mi_core()<0) { |
859 |
| - LM_ERR("failed to initialize MI core\n"); |
860 |
| - goto error; |
861 |
| - } |
862 |
| - |
863 |
| - /* Register core events */ |
864 |
| - if (evi_register_core() != 0) { |
865 |
| - LM_ERR("failed register core events\n"); |
866 |
| - goto error; |
867 |
| - } |
868 |
| - |
869 |
| - /* init black list engine */ |
870 |
| - if (init_black_lists()!=0) { |
871 |
| - LM_CRIT("failed to init blacklists\n"); |
872 |
| - goto error; |
873 |
| - } |
874 |
| - /* init resolver's blacklist */ |
875 |
| - if (resolv_blacklist_init()!=0) { |
876 |
| - LM_CRIT("failed to create DNS blacklist\n"); |
877 |
| - goto error; |
878 |
| - } |
879 |
| - |
880 |
| - if (init_dset() != 0) { |
881 |
| - LM_ERR("failed to initialize SIP forking logic!\n"); |
882 |
| - goto error; |
883 |
| - } |
884 |
| - |
885 |
| - /* init SQL DB support */ |
886 |
| - if (init_db_support() != 0) { |
887 |
| - LM_ERR("failed to initialize SQL database support\n"); |
888 |
| - goto error; |
889 |
| - } |
890 |
| - |
891 |
| - /* init CacheDB support */ |
892 |
| - if (init_cdb_support() != 0) { |
893 |
| - LM_ERR("failed to initialize CacheDB support\n"); |
894 |
| - goto error; |
895 |
| - } |
896 |
| - |
897 |
| - /* init modules */ |
898 |
| - if (init_modules() != 0) { |
899 |
| - LM_ERR("error while initializing modules\n"); |
900 |
| - goto error; |
901 |
| - } |
902 |
| - |
903 |
| - /* init xlog */ |
904 |
| - if (init_xlog() < 0) { |
905 |
| - LM_ERR("error while initializing xlog!\n"); |
906 |
| - goto error; |
907 |
| - } |
908 |
| - |
909 |
| - /* register route timers */ |
910 |
| - if(register_route_timers() < 0) { |
911 |
| - LM_ERR("Failed to register timer\n"); |
912 |
| - goto error; |
913 |
| - } |
914 |
| - |
915 |
| - /* init pseudo-variable support */ |
916 |
| - if (init_pvar_support() != 0) { |
917 |
| - LM_ERR("failed to init pvar support\n"); |
918 |
| - goto error; |
919 |
| - } |
920 |
| - |
921 |
| - /* init multi processes support */ |
922 |
| - if (init_multi_proc_support()!=0) { |
923 |
| - LM_ERR("failed to init multi-proc support\n"); |
924 |
| - goto error; |
925 |
| - } |
926 |
| - |
927 |
| - /* init avps */ |
928 |
| - if (init_extra_avps() != 0) { |
929 |
| - LM_ERR("error while initializing avps\n"); |
930 |
| - goto error; |
931 |
| - } |
932 |
| - |
933 |
| - /* fix routing lists */ |
934 |
| - if ( (r=fix_rls())!=0){ |
935 |
| - LM_ERR("failed to fix configuration with err code %d\n", r); |
936 |
| - goto error; |
937 |
| - } |
938 |
| - |
939 |
| - if (init_log_level() != 0) { |
940 |
| - LM_ERR("failed to init logging levels\n"); |
941 |
| - goto error; |
942 |
| - } |
943 |
| - |
944 |
| - if (init_log_event_cons() < 0) { |
945 |
| - LM_ERR("Failed to initialize log event consumer\n"); |
946 |
| - goto error; |
947 |
| - } |
948 |
| - |
949 |
| - if (trans_init_all_listeners()<0) { |
950 |
| - LM_ERR("failed to init all SIP listeners, aborting\n"); |
951 |
| - goto error; |
952 |
| - } |
953 |
| - |
954 |
| - if (init_script_reload()<0) { |
955 |
| - LM_ERR("failed to init cfg reload ctx, aborting\n"); |
956 |
| - goto error; |
957 |
| - } |
958 |
| - |
959 |
| - /* all processes should have access to all the sockets (for sending) |
960 |
| - * so we open all first*/ |
961 |
| - if (do_suid(user_id, group_id)==-1) |
962 |
| - goto error; |
963 |
| - |
964 |
| - if (run_post_fork_handlers()<0) { |
965 |
| - LM_ERR("failed to init post-fork handlers\n"); |
966 |
| - goto error; |
| 876 | + for (int n = 0; n < howmany(main_script, main_script[0]); n++) { |
| 877 | + int result = main_script[n].hndlr(); |
| 878 | + pred_cmp_f pred_cmp = cmps_ops[main_script[n].pval]; |
| 879 | + if (pred_cmp(result, main_script[n].pred)) { |
| 880 | + LM_ERR("failed to initialize %s!\n", main_script[n].desc); |
| 881 | + goto error; |
| 882 | + } |
967 | 883 | }
|
968 | 884 |
|
969 | 885 | ret = main_loop();
|
|
0 commit comments