Browse code

- added pid and process no information when logging to stderror

Andrei Pelinescu-Onciul authored on 12/12/2001 23:59:36
Showing 5 changed files
... ...
@@ -46,7 +46,7 @@ ARCH = $(shell uname -s)
46 46
 #		malloc etc.)
47 47
 DEFS= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
48 48
 	 -DDNS_IP_HACK  -DPKG_MALLOC -DSHM_MEM  -DSHM_MMAP \
49
-	 -DDBG_QM_MALLOC #-DNO_DEBUG #
49
+	 -DDBG_QM_MALLOC -DNO_DEBUG #
50 50
 #-DEXTRA_DEBUG
51 51
 # -DUSE_SHM_MEM
52 52
 #-DNO_DEBUG 
... ...
@@ -14,6 +14,7 @@ void dprint(char * format, ...)
14 14
 {
15 15
 	va_list ap;
16 16
 
17
+	fprintf(stderr, "%2d(%d) ", process_no, pids[process_no]);
17 18
 	va_start(ap, format);
18 19
 	vfprintf(stderr,format,ap);
19 20
 	fflush(stderr);
... ...
@@ -31,6 +31,8 @@ extern int log_stderr;
31 31
 extern int check_via;
32 32
 extern int received_dns;
33 33
 extern int loop_checks;
34
+extern int process_no;
35
+extern int *pids;
34 36
 
35 37
 extern int cfg_errors;
36 38
 extern unsigned int msg_no;
... ...
@@ -148,6 +148,8 @@ unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do not
148 148
 				      		durig the auto-probing procedure; may be
149 149
 				      		re-configured */
150 150
 int children_no = 0;           /* number of children processing requests */
151
+int *pids;		       /*array with childrens pids, 0= main proc,
152
+				alloc'ed in shared mem if possible*/
151 153
 int debug = 0;
152 154
 int dont_fork = 0;
153 155
 int log_stderr = 0;
... ...
@@ -192,7 +194,8 @@ int daemonize(char*  name)
192 194
 	int r;
193 195
 	
194 196
 	if (log_stderr==0)
195
-		openlog(name, LOG_PID, LOG_DAEMON); /* LOG_CONS, LOG_PERRROR ? */
197
+		openlog(name, LOG_PID|LOG_CONS, LOG_LOCAL1 /*LOG_DAEMON*/);
198
+		/* LOG_CONS, LOG_PERRROR ? */
196 199
 
197 200
 	if (chdir("/")<0){
198 201
 		LOG(L_CRIT,"cannot chroot:%s\n", strerror(errno));
... ...
@@ -254,10 +257,12 @@ int main_loop()
254 257
 
255 258
 		/* we need another process to act as the timer*/
256 259
 		if (timer_list){
260
+				process_no++;
257 261
 				if ((pid=fork())<0){
258 262
 					LOG(L_CRIT,  "ERRROR: main_loop: Cannot fork\n");
259 263
 					goto error;
260 264
 				}
265
+				
261 266
 				if (pid==0){
262 267
 					/* child */
263 268
 					/* timer!*/
... ...
@@ -265,10 +270,14 @@ int main_loop()
265 270
 						sleep(TIMER_TICK);
266 271
 						timer_ticker();
267 272
 					}
273
+				}else{
274
+						pids[process_no]=pid; /*should be shared mem anway*/
268 275
 				}
269 276
 		}
270 277
 		/* main process, receive loop */
271 278
 		is_main=1;
279
+		pids[0]=getpid();
280
+		process_no=0; /*main process number*/
272 281
 		udp_rcv_loop();
273 282
 	}else{
274 283
 		for(r=0;r<addresses_no;r++){
... ...
@@ -281,16 +290,20 @@ int main_loop()
281 290
 				}
282 291
 				if (pid==0){
283 292
 					/* child */
293
+					process_no=i+1; /*0=main*/
284 294
 #ifdef STATS
285 295
 					setstats( i );
286 296
 #endif
287 297
 					return udp_rcv_loop();
298
+				}else{
299
+						pids[i+1]=pid; /*should be in shared mem.*/
288 300
 				}
289 301
 			}
290 302
 			/*close(udp_sock);*/ /*parent*/
291 303
 		}
292 304
 	}
293 305
 	/*this is the main process*/
306
+	pids[process_no]=getpid();
294 307
 	is_main=1;
295 308
 	if (timer_list){
296 309
 		for(;;){
... ...
@@ -557,6 +570,18 @@ int main(int argc, char** argv)
557 570
 
558 571
 	
559 572
 	if (children_no<=0) children_no=CHILD_NO;
573
+	/*alloc pids*/
574
+#ifdef SHM_MEM
575
+	pids=shm_malloc(sizeof(int)*children_no);
576
+#else
577
+	pids=malloc(sizeof(int)*children_no);
578
+#endif
579
+	if (pids==0){
580
+		fprintf(stderr, "ERROR: out  of memory\n");
581
+		goto error;
582
+	}
583
+	memset(pids, 0, sizeof(int)*children_no);
584
+
560 585
 	if (addresses_no==0) {
561 586
 		/* get our address, only the first one */
562 587
 		if (uname (&myname) <0){
... ...
@@ -2,11 +2,11 @@ debug=9          # debug level (cmd line: -dddddddddd)
2 2
 check_via=yes     # (cmd. line: -v)
3 3
 dns=on           # (cmd. line: -r)
4 4
 rev_dns=yes      # (cmd. line: -R)
5
-fork=yes          # (cmd. line: -D)
6
-children=4
5
+fork=no          # (cmd. line: -D)
6
+children=10
7 7
 log_stderror=yes # (cmd line: -E)
8 8
 #port=5080
9
-listen=127.0.0.1
9
+#listen=127.0.0.1
10 10
 loop_checks=1
11 11
 # for more info: sip_router -h
12 12