Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,574 +0,0 @@
1
-/*
2
- * Process Table
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- *
6
- * Permission to use, copy, modify, and distribute this software for any
7
- * purpose with or without fee is hereby granted, provided that the above
8
- * copyright notice and this permission notice appear in all copies.
9
- *
10
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
- */
18
-/** Kamailio Core :: internal fork functions and process table.
19
- * @file: pt.c
20
- * @ingroup core
21
- */
22
-
23
-
24
-#include "pt.h"
25
-#include "tcp_init.h"
26
-#include "sr_module.h"
27
-#include "socket_info.h"
28
-#include "rand/fastrand.h"
29
-#include "rand/kam_rand.h"
30
-#ifdef PKG_MALLOC
31
-#include "mem/mem.h"
32
-#endif
33
-#ifdef SHM_MEM
34
-#include "mem/shm_mem.h"
35
-#endif
36
-#if defined PKG_MALLOC || defined SHM_MEM
37
-#include "cfg_core.h"
38
-#endif
39
-#include "daemonize.h"
40
-
41
-#include <stdio.h>
42
-#include <time.h> /* time(), used to initialize random numbers */
43
-
44
-#define FORK_DONT_WAIT  /* child doesn't wait for parent before starting 
45
-						   => faster startup, but the child should not assume
46
-						   the parent fixed the pt[] entry for it */
47
-
48
-
49
-#ifdef PROFILING
50
-#include <sys/gmon.h>
51
-
52
-	extern void _start(void);
53
-	extern void etext(void);
54
-#endif
55
-
56
-
57
-static int estimated_proc_no=0;
58
-static int estimated_fds_no=0;
59
-
60
-/* number of usec to wait before forking a process */
61
-static unsigned int fork_delay = 0;
62
-
63
-unsigned int set_fork_delay(unsigned int v)
64
-{
65
-	unsigned int r;
66
-	r =  fork_delay;
67
-	fork_delay = v;
68
-	return r;
69
-}
70
-
71
-/* number of known "common" used fds */
72
-static int calc_common_open_fds_no(void)
73
-{
74
-	int max_fds_no;
75
-	
76
-	/* 1 tcp send unix socket/all_proc, 
77
-	 *  + 1 udp sock/udp proc + 1 possible dns comm. socket + 
78
-	 *  + 1 temporary tcp send sock.
79
-	 * Per process:
80
-	 *  + 1 if mhomed (now mhomed keeps a "cached socket" per process)
81
-	 *  + 1 if mhomed & ipv6
82
-	 */
83
-	max_fds_no=estimated_proc_no*4 /* udp|sctp + tcp unix sock +
84
-									  tmp. tcp send +
85
-									  tmp dns.*/
86
-				-1 /* timer (no udp)*/ + 3 /* stdin/out/err */ +
87
-				2*mhomed
88
-				;
89
-	return max_fds_no;
90
-}
91
-
92
-
93
-
94
-/* returns 0 on success, -1 on error */
95
-int init_pt(int proc_no)
96
-{
97
-#ifdef USE_TCP
98
-	int r;
99
-#endif
100
-	
101
-	estimated_proc_no+=proc_no;
102
-	estimated_fds_no+=calc_common_open_fds_no();
103
-	/*alloc pids*/
104
-#ifdef SHM_MEM
105
-	pt=shm_malloc(sizeof(struct process_table)*estimated_proc_no);
106
-	process_count = shm_malloc(sizeof(int));
107
-#else
108
-	pt=pkg_malloc(sizeof(struct process_table)*estimated_proc_no);
109
-	process_count = pkg_malloc(sizeof(int));
110
-#endif
111
-	process_lock = lock_alloc();
112
-	process_lock = lock_init(process_lock);
113
-	if (pt==0||process_count==0||process_lock==0){
114
-		LM_ERR("out of memory\n");
115
-		return -1;
116
-	}
117
-	memset(pt, 0, sizeof(struct process_table)*estimated_proc_no);
118
-#ifdef USE_TCP
119
-	for (r=0; r<estimated_proc_no; r++){
120
-		pt[r].unix_sock=-1;
121
-		pt[r].idx=-1;
122
-	}
123
-#endif
124
-	process_no=0; /*main process number*/
125
-	pt[process_no].pid=getpid();
126
-	memcpy(pt[process_no].desc,"main",5);
127
-	*process_count=1;
128
-	return 0;
129
-}
130
-
131
-
132
-/* register no processes, used from mod_init when processes will be forked
133
- *  from mod_child 
134
- *  returns 0 on success, -1 on error
135
- */
136
-int register_procs(int no)
137
-{
138
-	if (pt){
139
-		LM_CRIT("(%d) called at runtime\n", no);
140
-		return -1;
141
-	}
142
-	estimated_proc_no+=no;
143
-	return 0;
144
-}
145
-
146
-
147
-
148
-/* returns the maximum number of processes */
149
-int get_max_procs()
150
-{
151
-	if (pt==0){
152
-		LM_CRIT("too early (it must _not_ be called from mod_init())\n");
153
-		abort(); /* crash to quickly catch offenders */
154
-	}
155
-	return estimated_proc_no;
156
-}
157
-
158
-
159
-/* register no fds, used from mod_init when modules will open more global
160
- *  fds (from mod_init or child_init(PROC_INIT)
161
- *  or from child_init(rank) when the module will open fds local to the
162
- *   process "rank".
163
- *   (this is needed because some other parts of ser code rely on knowing
164
- *    the maximum open fd number in a process)
165
- *  returns 0 on success, -1 on error
166
- */
167
-int register_fds(int no)
168
-{
169
-	/* can be called at runtime, but should be called from child_init() */
170
-	estimated_fds_no+=no;
171
-	return 0;
172
-}
173
-
174
-
175
-
176
-/* returns the maximum open fd number */
177
-int get_max_open_fds()
178
-{
179
-	if (pt==0){
180
-		LM_CRIT("too early (it must _not_ be called from mod_init())\n");
181
-		abort(); /* crash to quickly catch offenders */
182
-	}
183
-	return estimated_fds_no;
184
-}
185
-
186
-
187
-/* return processes pid */
188
-int my_pid()
189
-{
190
-	return pt ? pt[process_no].pid : getpid();
191
-}
192
-
193
-
194
-
195
-/* close unneeded sockets */
196
-int close_extra_socks(int child_id, int proc_no)
197
-{
198
-#ifdef USE_TCP
199
-	int r;
200
-	struct socket_info* si;
201
-	
202
-	if (child_id!=PROC_TCP_MAIN){
203
-		for (r=0; r<proc_no; r++){
204
-			if (pt[r].unix_sock>=0){
205
-				/* we can't change the value in pt[] because it's
206
-				 * shared so we only close it */
207
-				close(pt[r].unix_sock);
208
-			}
209
-		}
210
-		/* close all listen sockets (needed only in tcp_main */
211
-		if (!tcp_disable){
212
-			for(si=tcp_listen; si; si=si->next){
213
-				close(si->socket);
214
-				/* safe to change since this is a per process copy */
215
-				si->socket=-1;
216
-			}
217
-#ifdef USE_TLS
218
-			if (!tls_disable){
219
-				for(si=tls_listen; si; si=si->next){
220
-					close(si->socket);
221
-					/* safe to change since this is a per process copy */
222
-					si->socket=-1;
223
-				}
224
-			}
225
-#endif /* USE_TLS */
226
-		}
227
-		/* we still need the udp sockets (for sending) so we don't close them
228
-		 * too */
229
-	}
230
-#endif /* USE_TCP */
231
-	return 0;
232
-}
233
-
234
-
235
-
236
-/**
237
- * Forks a new process.
238
- * @param child_id - rank, if equal to PROC_NOCHLDINIT init_child will not be
239
- *                   called for the new forked process (see sr_module.h)
240
- * @param desc - text description for the process table
241
- * @param make_sock - if to create a unix socket pair for it
242
- * @returns the pid of the new process
243
- */
244
-int fork_process(int child_id, char *desc, int make_sock)
245
-{
246
-	int pid, child_process_no;
247
-	int ret;
248
-	unsigned int new_seed1;
249
-	unsigned int new_seed2;
250
-#ifdef USE_TCP
251
-	int sockfd[2];
252
-#endif
253
-
254
-	if(unlikely(fork_delay>0))
255
-		sleep_us(fork_delay);
256
-
257
-	ret=-1;
258
-	#ifdef USE_TCP
259
-		sockfd[0]=sockfd[1]=-1;
260
-		if(make_sock && !tcp_disable){
261
-			 if (!is_main){
262
-				 LM_CRIT("called from a non "
263
-						 "\"main\" process! If forking from a module's "
264
-						 "child_init() fork only if rank==PROC_MAIN or"
265
-						 " give up tcp send support (use 0 for make_sock)\n");
266
-				 goto error;
267
-			 }
268
-			 if (tcp_main_pid){
269
-				 LM_CRIT("called, but tcp main is already started\n");
270
-				 goto error;
271
-			 }
272
-			 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
273
-				LM_ERR("socketpair failed: %s\n",
274
-							strerror(errno));
275
-				goto error;
276
-			}
277
-		}
278
-	#endif
279
-	lock_get(process_lock);
280
-	if (*process_count>=estimated_proc_no) {
281
-		LM_CRIT("Process limit of %d exceeded. Will simulate fork fail.\n", estimated_proc_no);
282
-		lock_release(process_lock);
283
-		goto error;
284
-	}	
285
-	
286
-	
287
-	child_process_no = *process_count;
288
-	new_seed1=kam_rand();
289
-	new_seed2=random();
290
-	pid = fork();
291
-	if (pid<0) {
292
-		lock_release(process_lock);
293
-		ret=pid;
294
-		goto error;
295
-	}else if (pid==0){
296
-		/* child */
297
-		is_main=0; /* a forked process cannot be the "main" one */
298
-		process_no=child_process_no;
299
-		daemon_status_on_fork_cleanup();
300
-		/* close tcp unix sockets if this is not tcp main */
301
-#ifdef USE_TCP
302
-		close_extra_socks(child_id, process_no);
303
-#endif /* USE_TCP */
304
-		kam_srand(new_seed1);
305
-		fastrand_seed(kam_rand());
306
-		srandom(new_seed2+time(0));
307
-		shm_malloc_on_fork();
308
-#ifdef PROFILING
309
-		monstartup((u_long) &_start, (u_long) &etext);
310
-#endif
311
-#ifdef FORK_DONT_WAIT
312
-		/* record pid twice to avoid the child using it, before
313
-		 * parent gets a chance to set it*/
314
-		pt[process_no].pid=getpid();
315
-#else
316
-		/* wait for parent to get out of critical zone.
317
-		 * this is actually relevant as the parent updates
318
-		 * the pt & process_count. */
319
-		lock_get(process_lock);
320
-		lock_release(process_lock);
321
-#endif
322
-		#ifdef USE_TCP
323
-			if (make_sock && !tcp_disable){
324
-				close(sockfd[0]);
325
-				unix_tcp_sock=sockfd[1];
326
-			}
327
-		#endif		
328
-		if ((child_id!=PROC_NOCHLDINIT) && (init_child(child_id) < 0)) {
329
-			LM_ERR("init_child failed for process %d, pid %d, \"%s\"\n",
330
-					process_no, pt[process_no].pid, pt[process_no].desc);
331
-			return -1;
332
-		}
333
-		return pid;
334
-	} else {
335
-		/* parent */
336
-		(*process_count)++;
337
-#ifdef FORK_DONT_WAIT
338
-		lock_release(process_lock);
339
-#endif
340
-		/* add the process to the list in shm */
341
-		pt[child_process_no].pid=pid;
342
-		if (desc){
343
-			strncpy(pt[child_process_no].desc, desc, MAX_PT_DESC);
344
-		}
345
-		#ifdef USE_TCP
346
-			if (make_sock && !tcp_disable){
347
-				close(sockfd[1]);
348
-				pt[child_process_no].unix_sock=sockfd[0];
349
-				pt[child_process_no].idx=-1; /* this is not a "tcp" process*/
350
-			}
351
-		#endif
352
-#ifdef FORK_DONT_WAIT
353
-#else
354
-		lock_release(process_lock);
355
-#endif
356
-		ret=pid;
357
-		goto end;
358
-	}
359
-error:
360
-#ifdef USE_TCP
361
-	if (sockfd[0]!=-1) close(sockfd[0]);
362
-	if (sockfd[1]!=-1) close(sockfd[1]);
363
-#endif
364
-end:
365
-	return ret;
366
-}
367
-
368
-/**
369
- * Forks a new TCP process.
370
- * @param desc - text description for the process table
371
- * @param r - index in the tcp_children array
372
- * @param *reader_fd_1 - pointer to return the reader_fd[1]
373
- * @returns the pid of the new process
374
- */
375
-#ifdef USE_TCP
376
-int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
377
-{
378
-	int pid, child_process_no;
379
-	int sockfd[2];
380
-	int reader_fd[2]; /* for comm. with the tcp children read  */
381
-	int ret;
382
-	int i;
383
-	unsigned int new_seed1;
384
-	unsigned int new_seed2;
385
-	
386
-	/* init */
387
-	sockfd[0]=sockfd[1]=-1;
388
-	reader_fd[0]=reader_fd[1]=-1;
389
-	ret=-1;
390
-	
391
-	if (!is_main){
392
-		 LM_CRIT("called from a non \"main\" process\n");
393
-		 goto error;
394
-	 }
395
-	 if (tcp_main_pid){
396
-		 LM_CRIT("called _after_ starting tcp main\n");
397
-		 goto error;
398
-	 }
399
-	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
400
-		LM_ERR("socketpair failed: %s\n", strerror(errno));
401
-		goto error;
402
-	}
403
-	if (socketpair(AF_UNIX, SOCK_STREAM, 0, reader_fd)<0){
404
-		LM_ERR("socketpair failed: %s\n", strerror(errno));
405
-		goto error;
406
-	}
407
-	if (tcp_fix_child_sockets(reader_fd)<0){
408
-		LM_ERR("failed to set non blocking on child sockets\n");
409
-		/* continue, it's not critical (it will go slower under
410
-		 * very high connection rates) */
411
-	}
412
-	lock_get(process_lock);
413
-	/* set the local process_no */
414
-	if (*process_count>=estimated_proc_no) {
415
-		LM_CRIT("Process limit of %d exceeded. Simulating fork fail\n",
416
-					estimated_proc_no);
417
-		lock_release(process_lock);
418
-		goto error;
419
-	}
420
-	
421
-	
422
-	child_process_no = *process_count;
423
-	new_seed1=kam_rand();
424
-	new_seed2=random();
425
-	pid = fork();
426
-	if (pid<0) {
427
-		lock_release(process_lock);
428
-		ret=pid;
429
-		goto end;
430
-	}
431
-	if (pid==0){
432
-		is_main=0; /* a forked process cannot be the "main" one */
433
-		process_no=child_process_no;
434
-		/* close unneeded unix sockets */
435
-		close_extra_socks(child_id, process_no);
436
-		/* same for unneeded tcp_children <-> tcp_main unix socks */
437
-		for (i=0; i<r; i++){
438
-			if (tcp_children[i].unix_sock>=0){
439
-				close(tcp_children[i].unix_sock);
440
-				/* tcp_children is per process, so it's safe to change
441
-				 * the unix_sock to -1 */
442
-				tcp_children[i].unix_sock=-1;
443
-			}
444
-		}
445
-		daemon_status_on_fork_cleanup();
446
-		kam_srand(new_seed1);
447
-		fastrand_seed(kam_rand());
448
-		srandom(new_seed2+time(0));
449
-		shm_malloc_on_fork();
450
-#ifdef PROFILING
451
-		monstartup((u_long) &_start, (u_long) &etext);
452
-#endif
453
-#ifdef FORK_DONT_WAIT
454
-		/* record pid twice to avoid the child using it, before
455
--		 * parent gets a chance to set it*/
456
-		pt[process_no].pid=getpid();
457
-#else
458
-		/* wait for parent to get out of critical zone */
459
-		lock_get(process_lock);
460
-		lock_release(process_lock);
461
-#endif
462
-		close(sockfd[0]);
463
-		unix_tcp_sock=sockfd[1];
464
-		close(reader_fd[0]);
465
-		if (reader_fd_1) *reader_fd_1=reader_fd[1];
466
-		if ((child_id!=PROC_NOCHLDINIT) && (init_child(child_id) < 0)) {
467
-			LM_ERR("init_child failed for process %d, pid %d, \"%s\"\n",
468
-				process_no, pt[process_no].pid, pt[process_no].desc);
469
-			return -1;
470
-		}
471
-		return pid;
472
-	} else {
473
-		/* parent */
474
-		(*process_count)++;
475
-#ifdef FORK_DONT_WAIT
476
-		lock_release(process_lock);
477
-#endif
478
-		/* add the process to the list in shm */
479
-		pt[child_process_no].pid=pid;
480
-		pt[child_process_no].unix_sock=sockfd[0];
481
-		pt[child_process_no].idx=r;
482
-		if (desc){
483
-			snprintf(pt[child_process_no].desc, MAX_PT_DESC, "%s child=%d", 
484
-						desc, r);
485
-		}
486
-#ifdef FORK_DONT_WAIT
487
-#else
488
-		lock_release(process_lock);
489
-#endif
490
-		
491
-		close(sockfd[1]);
492
-		close(reader_fd[1]);
493
-		
494
-		tcp_children[r].pid=pid;
495
-		tcp_children[r].proc_no=child_process_no;
496
-		tcp_children[r].busy=0;
497
-		tcp_children[r].n_reqs=0;
498
-		tcp_children[r].unix_sock=reader_fd[0];
499
-		
500
-		ret=pid;
501
-		goto end;
502
-	}
503
-error:
504
-	if (sockfd[0]!=-1) close(sockfd[0]);
505
-	if (sockfd[1]!=-1) close(sockfd[1]);
506
-	if (reader_fd[0]!=-1) close(reader_fd[0]);
507
-	if (reader_fd[1]!=-1) close(reader_fd[1]);
508
-end:
509
-	return ret;
510
-}
511
-#endif
512
-
513
-#ifdef PKG_MALLOC
514
-/* Dumps pkg memory status.
515
- * Per-child process callback that is called
516
- * when mem_dump_pkg cfg var is changed.
517
- */
518
-void mem_dump_pkg_cb(str *gname, str *name)
519
-{
520
-	int	old_memlog;
521
-	int memlog;
522
-
523
-	if (cfg_get(core, core_cfg, mem_dump_pkg) == my_pid()) {
524
-		/* set memlog to ALERT level to force
525
-		printing the log messages */
526
-		old_memlog = cfg_get(core, core_cfg, memlog);
527
-		memlog = L_ALERT;
528
-		/* ugly hack to temporarily switch memlog to something visible,
529
-		   possible race with a parallel cfg_set */
530
-		((struct cfg_group_core*)core_cfg)->memlog=memlog;
531
-
532
-		if (cfg_get(core, core_cfg, mem_summary) & 1) {
533
-			LOG(memlog, "Memory status (pkg) of process %d:\n", my_pid());
534
-			pkg_status();
535
-		}
536
-		if (cfg_get(core, core_cfg, mem_summary) & 4) {
537
-			LOG(memlog, "Memory still-in-use summary (pkg) of process %d:\n",
538
-					my_pid());
539
-			pkg_sums();
540
-		}
541
-
542
-		((struct cfg_group_core*)core_cfg)->memlog=old_memlog;
543
-	}
544
-}
545
-#endif
546
-
547
-#ifdef SHM_MEM
548
-/* Dumps shm memory status.
549
- * fixup function that is called
550
- * when mem_dump_shm cfg var is set.
551
- */
552
-int mem_dump_shm_fixup(void *handle, str *gname, str *name, void **val)
553
-{
554
-	int	old_memlog;
555
-	int memlog;
556
-
557
-	if ((long)(void*)(*val)) {
558
-		/* set memlog to ALERT level to force
559
-		printing the log messages */
560
-		old_memlog = cfg_get(core, core_cfg, memlog);
561
-		memlog = L_ALERT;
562
-		/* ugly hack to temporarily switch memlog to something visible,
563
-		   possible race with a parallel cfg_set */
564
-		((struct cfg_group_core*)core_cfg)->memlog=memlog;
565
-
566
-		LOG(memlog, "Memory status (shm)\n");
567
-		shm_status();
568
-
569
-		((struct cfg_group_core*)core_cfg)->memlog=old_memlog;
570
-		*val = (void*)(long)0;
571
-	}
572
-	return 0;
573
-}
574
-#endif
Browse code

core: update to use kam_rand()

Spencer Thomason authored on 07/07/2016 22:24:13
Showing 1 changed files
... ...
@@ -26,6 +26,7 @@
26 26
 #include "sr_module.h"
27 27
 #include "socket_info.h"
28 28
 #include "rand/fastrand.h"
29
+#include "rand/kam_rand.h"
29 30
 #ifdef PKG_MALLOC
30 31
 #include "mem/mem.h"
31 32
 #endif
... ...
@@ -284,7 +285,7 @@ int fork_process(int child_id, char *desc, int make_sock)
284 285
 	
285 286
 	
286 287
 	child_process_no = *process_count;
287
-	new_seed1=rand();
288
+	new_seed1=kam_rand();
288 289
 	new_seed2=random();
289 290
 	pid = fork();
290 291
 	if (pid<0) {
... ...
@@ -300,8 +301,8 @@ int fork_process(int child_id, char *desc, int make_sock)
300 301
 #ifdef USE_TCP
301 302
 		close_extra_socks(child_id, process_no);
302 303
 #endif /* USE_TCP */
303
-		srand(new_seed1);
304
-		fastrand_seed(rand());
304
+		kam_srand(new_seed1);
305
+		fastrand_seed(kam_rand());
305 306
 		srandom(new_seed2+time(0));
306 307
 		shm_malloc_on_fork();
307 308
 #ifdef PROFILING
... ...
@@ -419,7 +420,7 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
419 420
 	
420 421
 	
421 422
 	child_process_no = *process_count;
422
-	new_seed1=rand();
423
+	new_seed1=kam_rand();
423 424
 	new_seed2=random();
424 425
 	pid = fork();
425 426
 	if (pid<0) {
... ...
@@ -442,8 +443,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
442 443
 			}
443 444
 		}
444 445
 		daemon_status_on_fork_cleanup();
445
-		srand(new_seed1);
446
-		fastrand_seed(rand());
446
+		kam_srand(new_seed1);
447
+		fastrand_seed(kam_rand());
447 448
 		srandom(new_seed2+time(0));
448 449
 		shm_malloc_on_fork();
449 450
 #ifdef PROFILING
Browse code

core: mem_summary taken in consideration for runtime pkg dump callback

Daniel-Constantin Mierla authored on 11/10/2015 17:37:54
Showing 1 changed files
... ...
@@ -528,8 +528,15 @@ void mem_dump_pkg_cb(str *gname, str *name)
528 528
 		   possible race with a parallel cfg_set */
529 529
 		((struct cfg_group_core*)core_cfg)->memlog=memlog;
530 530
 
531
-		LOG(memlog, "Memory status (pkg) of process %d:\n", my_pid());
532
-		pkg_status();
531
+		if (cfg_get(core, core_cfg, mem_summary) & 1) {
532
+			LOG(memlog, "Memory status (pkg) of process %d:\n", my_pid());
533
+			pkg_status();
534
+		}
535
+		if (cfg_get(core, core_cfg, mem_summary) & 4) {
536
+			LOG(memlog, "Memory still-in-use summary (pkg) of process %d:\n",
537
+					my_pid());
538
+			pkg_sums();
539
+		}
533 540
 
534 541
 		((struct cfg_group_core*)core_cfg)->memlog=old_memlog;
535 542
 	}
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Process Table
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG Fokus
... ...
@@ -17,17 +15,7 @@
17 15
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 16
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 17
  */
20
-/*
21
- * History:
22
- * --------
23
- *  2006-06-14	added process table in shared mem (dragos)
24
- *  2006-09-20	added profile support (-DPROFILING) (hscholz)
25
- *  2006-10-25	sanity check before allowing forking w/ tcp support (is_main
26
- *               & tcp not started yet); set is_main=0 in childs (andrei)
27
- *  2007-07-04	added register_fds() and get_max_open_fds(() (andrei)
28
- *  2010-08-19	use daemon_status_on_fork_cleanup() (andrei)
29
- */
30
-/** internal fork functions and process table.
18
+/** Kamailio Core :: internal fork functions and process table.
31 19
  * @file: pt.c
32 20
  * @ingroup core
33 21
  */
Browse code

pt.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 04/10/2014 00:48:51
Showing 1 changed files
... ...
@@ -122,7 +122,7 @@ int init_pt(int proc_no)
122 122
 	process_lock = lock_alloc();
123 123
 	process_lock = lock_init(process_lock);
124 124
 	if (pt==0||process_count==0||process_lock==0){
125
-		LOG(L_ERR, "ERROR: out  of memory\n");
125
+		LM_ERR("out of memory\n");
126 126
 		return -1;
127 127
 	}
128 128
 	memset(pt, 0, sizeof(struct process_table)*estimated_proc_no);
... ...
@@ -147,7 +147,7 @@ int init_pt(int proc_no)
147 147
 int register_procs(int no)
148 148
 {
149 149
 	if (pt){
150
-		LOG(L_CRIT, "BUG: register_procs(%d) called at runtime\n", no);
150
+		LM_CRIT("(%d) called at runtime\n", no);
151 151
 		return -1;
152 152
 	}
153 153
 	estimated_proc_no+=no;
... ...
@@ -160,8 +160,7 @@ int register_procs(int no)
160 160
 int get_max_procs()
161 161
 {
162 162
 	if (pt==0){
163
-		LOG(L_CRIT, "BUG: get_max_procs() called too early "
164
-				"(it must _not_ be called from mod_init())\n");
163
+		LM_CRIT("too early (it must _not_ be called from mod_init())\n");
165 164
 		abort(); /* crash to quickly catch offenders */
166 165
 	}
167 166
 	return estimated_proc_no;
... ...
@@ -189,8 +188,7 @@ int register_fds(int no)
189 188
 int get_max_open_fds()
190 189
 {
191 190
 	if (pt==0){
192
-		LOG(L_CRIT, "BUG: get_max_open_fds() called too early "
193
-				"(it must _not_ be called from mod_init())\n");
191
+		LM_CRIT("too early (it must _not_ be called from mod_init())\n");
194 192
 		abort(); /* crash to quickly catch offenders */
195 193
 	}
196 194
 	return estimated_fds_no;
... ...
@@ -272,19 +270,18 @@ int fork_process(int child_id, char *desc, int make_sock)
272 270
 		sockfd[0]=sockfd[1]=-1;
273 271
 		if(make_sock && !tcp_disable){
274 272
 			 if (!is_main){
275
-				 LOG(L_CRIT, "BUG: fork_process(..., 1) called from a non "
273
+				 LM_CRIT("called from a non "
276 274
 						 "\"main\" process! If forking from a module's "
277 275
 						 "child_init() fork only if rank==PROC_MAIN or"
278 276
 						 " give up tcp send support (use 0 for make_sock)\n");
279 277
 				 goto error;
280 278
 			 }
281 279
 			 if (tcp_main_pid){
282
-				 LOG(L_CRIT, "BUG: fork_process(..., 1) called, but tcp main "
283
-						 " is already started\n");
280
+				 LM_CRIT("called, but tcp main is already started\n");
284 281
 				 goto error;
285 282
 			 }
286 283
 			 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
287
-				LOG(L_ERR, "ERROR: fork_process(): socketpair failed: %s\n",
284
+				LM_ERR("socketpair failed: %s\n",
288 285
 							strerror(errno));
289 286
 				goto error;
290 287
 			}
... ...
@@ -292,8 +289,7 @@ int fork_process(int child_id, char *desc, int make_sock)
292 289
 	#endif
293 290
 	lock_get(process_lock);
294 291
 	if (*process_count>=estimated_proc_no) {
295
-		LOG(L_CRIT, "ERROR: fork_process(): Process limit of %d exceeded."
296
-					" Will simulate fork fail.\n", estimated_proc_no);
292
+		LM_CRIT("Process limit of %d exceeded. Will simulate fork fail.\n", estimated_proc_no);
297 293
 		lock_release(process_lock);
298 294
 		goto error;
299 295
 	}	
... ...
@@ -341,9 +337,8 @@ int fork_process(int child_id, char *desc, int make_sock)
341 337
 			}
342 338
 		#endif		
343 339
 		if ((child_id!=PROC_NOCHLDINIT) && (init_child(child_id) < 0)) {
344
-			LOG(L_ERR, "ERROR: fork_process(): init_child failed for "
345
-					" process %d, pid %d, \"%s\"\n", process_no,
346
-					pt[process_no].pid, pt[process_no].desc);
340
+			LM_ERR("init_child failed for process %d, pid %d, \"%s\"\n",
341
+					process_no, pt[process_no].pid, pt[process_no].desc);
347 342
 			return -1;
348 343
 		}
349 344
 		return pid;
... ...
@@ -405,36 +400,31 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
405 400
 	ret=-1;
406 401
 	
407 402
 	if (!is_main){
408
-		 LOG(L_CRIT, "BUG: fork_tcp_process() called from a non \"main\" "
409
-				 	"process\n");
403
+		 LM_CRIT("called from a non \"main\" process\n");
410 404
 		 goto error;
411 405
 	 }
412 406
 	 if (tcp_main_pid){
413
-		 LOG(L_CRIT, "BUG: fork_tcp_process(..., 1) called _after_ starting"
414
-				 	" tcp main\n");
407
+		 LM_CRIT("called _after_ starting tcp main\n");
415 408
 		 goto error;
416 409
 	 }
417 410
 	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
418
-		LOG(L_ERR, "ERROR: fork_tcp_process(): socketpair failed: %s\n",
419
-					strerror(errno));
411
+		LM_ERR("socketpair failed: %s\n", strerror(errno));
420 412
 		goto error;
421 413
 	}
422 414
 	if (socketpair(AF_UNIX, SOCK_STREAM, 0, reader_fd)<0){
423
-		LOG(L_ERR, "ERROR: fork_tcp_process(): socketpair failed: %s\n",
424
-					strerror(errno));
415
+		LM_ERR("socketpair failed: %s\n", strerror(errno));
425 416
 		goto error;
426 417
 	}
427 418
 	if (tcp_fix_child_sockets(reader_fd)<0){
428
-		LOG(L_ERR, "ERROR: fork_tcp_process(): failed to set non blocking"
429
-					"on child sockets\n");
419
+		LM_ERR("failed to set non blocking on child sockets\n");
430 420
 		/* continue, it's not critical (it will go slower under
431 421
 		 * very high connection rates) */
432 422
 	}
433 423
 	lock_get(process_lock);
434 424
 	/* set the local process_no */
435 425
 	if (*process_count>=estimated_proc_no) {
436
-		LOG(L_CRIT, "ERROR: fork_tcp_process(): Process limit of %d exceeded."
437
-					" Simulating fork fail\n", estimated_proc_no);
426
+		LM_CRIT("Process limit of %d exceeded. Simulating fork fail\n",
427
+					estimated_proc_no);
438 428
 		lock_release(process_lock);
439 429
 		goto error;
440 430
 	}
... ...
@@ -485,9 +475,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
485 475
 		close(reader_fd[0]);
486 476
 		if (reader_fd_1) *reader_fd_1=reader_fd[1];
487 477
 		if ((child_id!=PROC_NOCHLDINIT) && (init_child(child_id) < 0)) {
488
-			LOG(L_ERR, "ERROR: fork_tcp_process(): init_child failed for "
489
-					"process %d, pid %d, \"%s\"\n", process_no, 
490
-					pt[process_no].pid, pt[process_no].desc);
478
+			LM_ERR("init_child failed for process %d, pid %d, \"%s\"\n",
479
+				process_no, pt[process_no].pid, pt[process_no].desc);
491 480
 			return -1;
492 481
 		}
493 482
 		return pid;
Browse code

core and modules: make IPv6 default, remove compile time flags

* Make IPv6 the default in the core and affected modules
* it has been default switched on since a long time, and was introduced in 2002
* even on embedded systems one probably want now proper IPv6 support
* there was an issue in cygwin in 2008, but IPv6 is there also available since v1.7
* remove over 160 #ifdefs, cleanup the code a lot and removes many of rarely
tested alternative code paths to ease support of the codebase
* note for gentoo maintainer: please review your packages, they will maybe not
work now correctly anymore if somebody specified -ipv6 in the use flags

Henning Westerholt authored on 18/05/2013 08:07:25
Showing 1 changed files
... ...
@@ -95,11 +95,7 @@ static int calc_common_open_fds_no(void)
95 95
 									  tmp. tcp send +
96 96
 									  tmp dns.*/
97 97
 				-1 /* timer (no udp)*/ + 3 /* stdin/out/err */ +
98
-#ifdef USE_IPV6
99 98
 				2*mhomed
100
-#else
101
-				mhomed
102
-#endif /* USE_IPV6*/
103 99
 				;
104 100
 	return max_fds_no;
105 101
 }
Browse code

master:core Continue cleaning erroneous definition of functions with no arguments

After testing with gcc 4.5.2, seems that not prototyping function cases extra assembler code regardles of optimization level

Marius Zbihlei authored on 04/04/2012 09:51:50
Showing 1 changed files
... ...
@@ -80,7 +80,7 @@ unsigned int set_fork_delay(unsigned int v)
80 80
 }
81 81
 
82 82
 /* number of known "common" used fds */
83
-static int calc_common_open_fds_no()
83
+static int calc_common_open_fds_no(void)
84 84
 {
85 85
 	int max_fds_no;
86 86
 	
Browse code

core: new cfg parameter fork_delay

- number of usecs to wait before forking a process
- default is 0, don't wait
- useful in case there are some throttling policies for the system
running the sip server (e.g., number of new db connections per second)
-- you can introduce delays so that worker processes are not forked at
once

Daniel-Constantin Mierla authored on 06/01/2012 11:06:02
Showing 1 changed files
... ...
@@ -68,6 +68,16 @@
68 68
 static int estimated_proc_no=0;
69 69
 static int estimated_fds_no=0;
70 70
 
71
+/* number of usec to wait before forking a process */
72
+static unsigned int fork_delay = 0;
73
+
74
+unsigned int set_fork_delay(unsigned int v)
75
+{
76
+	unsigned int r;
77
+	r =  fork_delay;
78
+	fork_delay = v;
79
+	return r;
80
+}
71 81
 
72 82
 /* number of known "common" used fds */
73 83
 static int calc_common_open_fds_no()
... ...
@@ -258,6 +268,9 @@ int fork_process(int child_id, char *desc, int make_sock)
258 268
 	int sockfd[2];
259 269
 #endif
260 270
 
271
+	if(unlikely(fork_delay>0))
272
+		sleep_us(fork_delay);
273
+
261 274
 	ret=-1;
262 275
 	#ifdef USE_TCP
263 276
 		sockfd[0]=sockfd[1]=-1;
Browse code

core: counters can be used before forking

Counters can now be incremented (not only registered) before
counters_prefork_init(). This enables using them also from
mod_init() or the fixup functions (not recommended but needed for
"indirect" calls).
Fixes crashes when modules call a counter using function from
mod_init() or a fixup.
E.g.: xlog(s) does a dns lookup from mod_init. If the lookup fails
the dns code will try to increment the new dns.failed_dns_request
counter.

Reported-by: Michal Matyska michal.matyska iptel org

Andrei Pelinescu-Onciul authored on 24/08/2010 19:14:50
Showing 1 changed files
... ...
@@ -47,6 +47,7 @@
47 47
 #if defined PKG_MALLOC || defined SHM_MEM
48 48
 #include "cfg_core.h"
49 49
 #endif
50
+#include "daemonize.h"
50 51
 
51 52
 #include <stdio.h>
52 53
 #include <time.h> /* time(), used to initialize random numbers */
Browse code

core: daemon status/pipe fixes & interface changes

- moved most of the daemon status stuff to daemonize.[ch].
- nicer interface (e.g. daemon_status_send(code))
- send/read only 1 byte which will be used as exit code
- send an error status on error (fixes
"Main process exited before writing to pipe" error message)
- disabled the timeout. Not needed (now a status is sent always
and even an unlikely process crash before sending it is detected via
the read() failure) and very hard to find a good value (some
setups start very slow).
- close the pipe "send" fd in processes not needing it
- attempt to send back status only if dont_daemonize is not set
(not only if dont_fork==0, it is possible to have forking
enabled, but daemonize disabled: ser -DD)
- BSDed daemonize.[ch] and pt.[ch]

Andrei Pelinescu-Onciul authored on 19/08/2010 18:03:54
Showing 1 changed files
... ...
@@ -3,30 +3,19 @@
3 3
  *
4 4
  * Process Table
5 5
  *
6
- *
7
- *
8 6
  * Copyright (C) 2001-2003 FhG Fokus
9 7
  *
10
- * This file is part of ser, a free SIP server.
11
- *
12
- * ser is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation; either version 2 of the License, or
15
- * (at your option) any later version
8
+ * Permission to use, copy, modify, and distribute this software for any
9
+ * purpose with or without fee is hereby granted, provided that the above
10
+ * copyright notice and this permission notice appear in all copies.
16 11
  *
17
- * For a license to use the ser software under conditions
18
- * other than those described here, or to purchase support for this
19
- * software, please contact iptel.org by e-mail at the following addresses:
20
- *    info@iptel.org
21
- *
22
- * ser is distributed in the hope that it will be useful,
23
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
- * GNU General Public License for more details.
26
- *
27
- * You should have received a copy of the GNU General Public License 
28
- * along with this program; if not, write to the Free Software 
29
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
12
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.