MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / init_multi_proc_support

Function init_multi_proc_support

pt.c:97–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95
96
97int init_multi_proc_support(void)
98{
99 int i;
100 /* at this point we know exactly the possible number of processes, since
101 * all the other modules already adjusted their extra numbers */
102 counted_max_processes = count_child_processes();
103
104#ifdef UNIT_TESTS
105#include "mem/test/test_malloc.h"
106 counted_max_processes += TEST_MALLOC_PROCS - 1;
107#endif
108
109 /* allocate the PID table to accomodate the maximum possible number of
110 * process we may have during runtime (covering extra procs created
111 * due auto-scaling) */
112 pt = shm_malloc(sizeof(struct process_table)*counted_max_processes);
113 if (pt==0){
114 LM_ERR("out of memory\n");
115 return -1;
116 }
117 memset(pt, 0, sizeof(struct process_table)*counted_max_processes);
118
119 for( i=0 ; i<counted_max_processes ; i++ ) {
120 /* reset fds to prevent bogus ops */
121 pt[i].pid = -1;
122 pt[i].ipc_pipe[0] = pt[i].ipc_pipe[1] = -1;
123 pt[i].ipc_sync_pipe[0] = pt[i].ipc_sync_pipe[1] = -1;
124 }
125
126 /* create the load-related stats (initially marked as hidden */
127 /* until the proc starts) */
128 if (register_processes_load_stats( counted_max_processes ) != 0) {
129 LM_ERR("failed to create load stats\n");
130 return -1;
131 }
132
133 /* create the IPC pipes for all possible procs */
134 if (create_ipc_pipes( counted_max_processes )<0) {
135 LM_ERR("failed to create IPC pipes, aborting\n");
136 return -1;
137 }
138
139 /* create the pkg_mem stats */
140 #ifdef PKG_MALLOC
141 if (init_pkg_stats(counted_max_processes)!=0) {
142 LM_ERR("failed to init stats for pkg\n");
143 return -1;
144 }
145 #endif
146
147 /* set the pid for the starter process */
148 set_proc_attrs("starter");
149
150 /* register the stats for the global load */
151 if ( register_stat2( "load", "load", (stat_var**)pt_get_rt_load,
152 STAT_IS_FUNC, NULL, 0) != 0) {
153 LM_ERR("failed to add RT global load stat\n");
154 return -1;

Callers

nothing calls this directly

Calls 7

count_child_processesFunction · 0.85
shm_mallocFunction · 0.85
create_ipc_pipesFunction · 0.85
init_pkg_statsFunction · 0.85
set_proc_attrsFunction · 0.85
register_stat2Function · 0.85

Tested by

no test coverage detected