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

Function create_process_group

pt_scaling.c:170–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168
169
170int create_process_group(enum process_type type,
171 struct socket_info *si_filter, struct scaling_profile *prof,
172 fork_new_process_f *f1, terminate_process_f *f2)
173{
174 struct process_group *pg, *it;
175 int h_size;
176 str type_s;
177
178 /* how much of a history do we need in order to cover both up and down
179 * tranzitions ? */
180 h_size = (prof->up_cycles_tocheck > prof->down_cycles_tocheck) ?
181 prof->up_cycles_tocheck : prof->down_cycles_tocheck;
182
183 get_sr_type_name( type, type_s);
184
185 pg = (struct process_group*)shm_malloc( sizeof(struct process_group) +
186 sizeof(char)*h_size +
187 type_s.len+(si_filter?1+(si_filter->sock_str.len):0)
188 );
189 if (pg==NULL) {
190 LM_ERR("failed to allocate memory for a new process group\n");
191 return -1;
192 }
193 memset( pg, 0, sizeof(struct process_group) + sizeof(char)*h_size );
194
195 pg->type = type;
196 pg->si_filter = si_filter;
197 pg->prof = prof;
198 pg->fork_func = f1;
199 pg->term_func = f2;
200 pg->next = NULL;
201
202 pg->history_size = h_size;
203 pg->history_map = (unsigned char*)(pg+1);
204 pg->history_idx = 0;
205 pg->no_downscale_cycles = pg->prof->down_cycles_delay;
206
207 pg->sr_identifier_name.s = (char*)(pg->history_map + h_size);
208 memcpy( pg->sr_identifier_name.s, type_s.s, type_s.len);
209 pg->sr_identifier_name.len = type_s.len;
210 if (si_filter) {
211 pg->sr_identifier_name.s[pg->sr_identifier_name.len++] = '/';
212 memcpy( pg->sr_identifier_name.s + pg->sr_identifier_name.len,
213 si_filter->sock_str.s, si_filter->sock_str.len);
214 pg->sr_identifier_name.len += si_filter->sock_str.len;
215 }
216
217 LM_DBG("registering group of processes type %d, socket filter %p, "
218 "name <%.*s> scaling profile <%s>\n", type, si_filter,
219 pg->sr_identifier_name.len, pg->sr_identifier_name.s, prof->name);
220
221 if (sr_register_identifier( pts_sr_group,
222 pg->sr_identifier_name.s, pg->sr_identifier_name.len,
223 SR_STATUS_READY, CHAR_INT("active"), 100)<0
224 ) {
225 LM_ERR("failed to register auto-scaling identifier for group"
226 "name <%.*s>, disabling\n",
227 pg->sr_identifier_name.len, pg->sr_identifier_name.s);

Callers 3

udp_start_processesFunction · 0.85
tcp_start_processesFunction · 0.85

Calls 2

shm_mallocFunction · 0.85
sr_register_identifierFunction · 0.85

Tested by

no test coverage detected