Skip to content

Commit 7ee40b3

Browse files
committed
Migrate to counted_max_processes
Drop counted_processes and it becamed irrelevant.
1 parent bf2e51c commit 7ee40b3

File tree

8 files changed

+35
-38
lines changed

8 files changed

+35
-38
lines changed

db/db_insertq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ query_list_t *ql_init(db_con_t *con,db_key_t *cols,int col_no)
338338

339339
row_q_size = sizeof(db_val_t *) * query_buffer_size;
340340
size = sizeof(query_list_t) +
341-
counted_processes * sizeof(db_con_t *) +
341+
counted_max_processes * sizeof(db_con_t *) +
342342
con->table->len + key_size + row_q_size + con->url.len;
343343

344344
entry = shm_malloc(size);

dprint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void set_global_log_level(int level)
138138
{
139139
int i;
140140

141-
for (i = 0; i < counted_processes; i++) {
141+
for (i = 0; i < counted_max_processes; i++) {
142142
__set_proc_default_log_level(i, level);
143143
__set_proc_log_level(i, level);
144144
}

main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static void kill_all_children(int signum)
379379
if (!pt)
380380
return;
381381

382-
for (r = 1; r < counted_processes; r++) {
382+
for (r = 1; r < counted_max_processes; r++) {
383383
if (pt[r].pid == -1 || (pt[r].flags & OSS_PROC_DOING_DUMP))
384384
continue;
385385

@@ -439,7 +439,7 @@ static void shutdown_opensips( int status )
439439
/* terminate all processes */
440440

441441
/* first we try to terminate the processes via the IPC channel */
442-
for( i=1,n=0 ; i<counted_processes; i++) {
442+
for( i=1,n=0 ; i<counted_max_processes; i++) {
443443
/* Depending on the processes status, its PID may be:
444444
* -1 - process not forked yet
445445
* 0 - process forked but not fully configured by core
@@ -1390,7 +1390,7 @@ int main(int argc, char** argv)
13901390

13911391
#ifdef PKG_MALLOC
13921392
/* init stats support for pkg mem */
1393-
if (init_pkg_stats(counted_processes)!=0) {
1393+
if (init_pkg_stats(counted_max_processes)!=0) {
13941394
LM_ERR("failed to init stats for pkg\n");
13951395
goto error;
13961396
}

mi/mi_core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ static mi_response_t *mi_ps(const mi_params_t *params,
255255
return 0;
256256
}
257257

258-
for ( i=0 ; i<counted_processes ; i++ ) {
258+
for ( i=0 ; i<counted_max_processes ; i++ ) {
259+
if (!is_process_running(i))
260+
continue;
259261
proc_item = add_mi_object(procs_arr, 0, 0);
260262
if (!proc_item)
261263
goto error;
@@ -350,7 +352,9 @@ static mi_response_t *w_log_level(const mi_params_t *params,
350352
return 0;
351353
}
352354

353-
for (i = 0; i < counted_processes; i++) {
355+
for (i = 0; i < counted_max_processes; i++) {
356+
if (!is_process_running(i))
357+
continue;
354358
proc_item = add_mi_object(procs_arr, NULL, 0);
355359
if (!proc_item)
356360
goto error;

net/net_tcp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ static void tcp_main_server(void)
16001600
if (init_worker_reactor("TCP_main", RCT_PRIO_MAX)<0)
16011601
goto error;
16021602

1603-
/* now start watching all the fds*/
1603+
/* now start watching all the fds */
16041604

16051605
/* add all the sockets we listens on for connections */
16061606
for( n=PROTO_FIRST ; n<PROTO_LAST ; n++ )
@@ -1615,7 +1615,7 @@ static void tcp_main_server(void)
16151615
}
16161616
/* add all the unix sockets used for communcation with other opensips
16171617
* processes (get fd, new connection a.s.o) */
1618-
for (n=1; n<counted_processes; n++) {
1618+
for (n=1; n<counted_max_processes; n++) {
16191619
/* skip myslef (as process) and -1 socks (disabled)
16201620
(we can't have 0, we never close it!) */
16211621
if (n!=process_no && pt[n].unix_sock>0)

pt.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
* alloc'ed in shared mem if possible */
4242
struct process_table *pt=0;
4343

44-
/* variable keeping the number of created processes READONLY!! */
45-
unsigned int *counted_processes_p = NULL;
46-
44+
/* The maximum number of processes that will ever exist in OpenSIPS. This is
45+
* actually the size of the process table
46+
* This is READONLY!! */
4747
unsigned int counted_max_processes = 0;
4848

4949

@@ -55,13 +55,6 @@ int init_multi_proc_support(void)
5555
unsigned int extra;
5656
unsigned int i;
5757

58-
/* allocate the number of proc variable in shm */
59-
counted_processes_p = shm_malloc(sizeof(unsigned int));
60-
if (counted_processes_p==NULL){
61-
LM_ERR("out of memory\n");
62-
return -1;
63-
}
64-
6558
proc_no = 0;
6659
proc_extra_no = 0;
6760

@@ -83,9 +76,6 @@ int init_multi_proc_support(void)
8376
/* count the processes requested by modules */
8477
proc_no += count_module_procs(0);
8578

86-
/* for the beginning, count only the processes we are starting with */
87-
*counted_processes_p = proc_no;
88-
8979
counted_max_processes = proc_no + proc_extra_no;
9080

9181

@@ -417,7 +407,7 @@ void check_and_adjust_number_of_workers(void)
417407
procs_no = 0;
418408

419409
/* find the processes belonging to this group */
420-
for ( i=0 ; i<counted_processes ; i++) {
410+
for ( i=0 ; i<counted_max_processes ; i++) {
421411

422412
if (pt[i].type != pg->type || pg->si_filter!=pt[i].pg_filter)
423413
continue;

pt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ typedef int (*forked_proc_func)(int i);
7979

8080
extern struct process_table *pt;
8181
extern int process_no;
82-
extern unsigned int *counted_processes_p;
8382
extern unsigned int counted_max_processes;
8483

8584
int init_multi_proc_support();
@@ -93,7 +92,8 @@ int count_init_child_processes(void);
9392
#define OSS_PROC_DYNAMIC (1<<4) /* proc was created at runtime */
9493
#define OSS_PROC_IS_RUNNING (1<<5) /* proc is running */
9594

96-
#define counted_processes (counted_processes_p?*counted_processes_p:0)
95+
#define is_process_running(_idx) \
96+
( (pt[_idx].flags&OSS_PROC_IS_RUNNING)?1:0 )
9797

9898
pid_t internal_fork(char *proc_desc, unsigned int flags,
9999
enum process_type type);
@@ -110,7 +110,7 @@ inline static int get_process_ID_by_PID(pid_t pid)
110110
{
111111
int i;
112112

113-
for( i=0 ; i<counted_processes ; i++ )
113+
for( i=0 ; i<counted_max_processes ; i++ )
114114
if (pt[i].pid==pid)
115115
return i;
116116

pt_load.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ unsigned int pt_get_rt_load(int _)
245245
gettimeofday( &tv, NULL);
246246
usec_now = ((utime_t)(tv.tv_sec)) * 1000000 + tv.tv_usec;
247247

248-
for( n=0 ; n<counted_processes; n++)
249-
if ( (pt[n].flags&(OSS_PROC_NO_LOAD|OSS_PROC_IS_EXTRA))==0 ) {
248+
for( n=0 ; n<counted_max_processes; n++)
249+
if ( is_process_running(n) &&
250+
(pt[n].flags&(OSS_PROC_NO_LOAD|OSS_PROC_IS_EXTRA))==0 ) {
250251
SUM_UP_LOAD( usec_now, n, ST, 1);
251252
summed_procs++;
252253
}
@@ -266,8 +267,9 @@ unsigned int pt_get_1m_load(int _)
266267
gettimeofday( &tv, NULL);
267268
usec_now = ((utime_t)(tv.tv_sec)) * 1000000 + tv.tv_usec;
268269

269-
for( n=0 ; n<counted_processes; n++)
270-
if ( (pt[n].flags&(OSS_PROC_NO_LOAD|OSS_PROC_IS_EXTRA))==0 ) {
270+
for( n=0 ; n<counted_max_processes; n++)
271+
if ( is_process_running(n) &&
272+
(pt[n].flags&(OSS_PROC_NO_LOAD|OSS_PROC_IS_EXTRA))==0 ) {
271273
SUM_UP_LOAD( usec_now, n, LT, LT_1m_RATIO);
272274
summed_procs++;
273275
}
@@ -287,8 +289,9 @@ unsigned int pt_get_10m_load(int _)
287289
gettimeofday( &tv, NULL);
288290
usec_now = ((utime_t)(tv.tv_sec)) * 1000000 + tv.tv_usec;
289291

290-
for( n=0 ; n<counted_processes; n++)
291-
if ( (pt[n].flags&(OSS_PROC_NO_LOAD|OSS_PROC_IS_EXTRA))==0 ) {
292+
for( n=0 ; n<counted_max_processes; n++)
293+
if ( is_process_running(n) &&
294+
(pt[n].flags&(OSS_PROC_NO_LOAD|OSS_PROC_IS_EXTRA))==0 ) {
292295
SUM_UP_LOAD( usec_now, n, LT, 1);
293296
summed_procs++;
294297
}
@@ -308,8 +311,8 @@ unsigned int pt_get_rt_loadall(int _)
308311
gettimeofday( &tv, NULL);
309312
usec_now = ((utime_t)(tv.tv_sec)) * 1000000 + tv.tv_usec;
310313

311-
for( n=0 ; n<counted_processes; n++) {
312-
if ( (pt[n].flags&OSS_PROC_NO_LOAD)==0 )
314+
for( n=0 ; n<counted_max_processes; n++) {
315+
if ( is_process_running(n) && (pt[n].flags&OSS_PROC_NO_LOAD)==0 )
313316
SUM_UP_LOAD( usec_now, n, ST, 1);
314317
summed_procs++;
315318
}
@@ -329,8 +332,8 @@ unsigned int pt_get_1m_loadall(int _)
329332
gettimeofday( &tv, NULL);
330333
usec_now = ((utime_t)(tv.tv_sec)) * 1000000 + tv.tv_usec;
331334

332-
for( n=0 ; n<counted_processes; n++)
333-
if ( (pt[n].flags&OSS_PROC_NO_LOAD)==0 ) {
335+
for( n=0 ; n<counted_max_processes; n++)
336+
if ( is_process_running(n) && (pt[n].flags&OSS_PROC_NO_LOAD)==0 ) {
334337
SUM_UP_LOAD( usec_now, n, LT, LT_1m_RATIO);
335338
summed_procs++;
336339
}
@@ -350,8 +353,8 @@ unsigned int pt_get_10m_loadall(int _)
350353
gettimeofday( &tv, NULL);
351354
usec_now = ((utime_t)(tv.tv_sec)) * 1000000 + tv.tv_usec;
352355

353-
for( n=0 ; n<counted_processes; n++)
354-
if ( (pt[n].flags&OSS_PROC_NO_LOAD)==0 ) {
356+
for( n=0 ; n<counted_max_processes; n++)
357+
if ( is_process_running(n) && (pt[n].flags&OSS_PROC_NO_LOAD)==0 ) {
355358
SUM_UP_LOAD( usec_now, n, LT, 1);
356359
summed_procs++;
357360
}

0 commit comments

Comments
 (0)