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 192
 	int r;
193 193
 	
194 194
 	if (log_stderr==0)
195
-		openlog(name, LOG_PID, LOG_DAEMON); /* LOG_CONS, LOG_PERRROR ? */
195
+		openlog(name, LOG_PID|LOG_CONS, LOG_LOCAL1 /*LOG_DAEMON*/);
196
+		/* LOG_CONS, LOG_PERRROR ? */
196 197
 
197 198
 	if (chdir("/")<0){
198 199
 		LOG(L_CRIT,"cannot chroot:%s\n", strerror(errno));
... ...
@@ -254,10 +257,12 @@ int main_loop()
254 254
 
255 255
 		/* we need another process to act as the timer*/
256 256
 		if (timer_list){
257
+				process_no++;
257 258
 				if ((pid=fork())<0){
258 259
 					LOG(L_CRIT,  "ERRROR: main_loop: Cannot fork\n");
259 260
 					goto error;
260 261
 				}
262
+				
261 263
 				if (pid==0){
262 264
 					/* child */
263 265
 					/* timer!*/
... ...
@@ -265,10 +270,14 @@ int main_loop()
265 265
 						sleep(TIMER_TICK);
266 266
 						timer_ticker();
267 267
 					}
268
+				}else{
269
+						pids[process_no]=pid; /*should be shared mem anway*/
268 270
 				}
269 271
 		}
270 272
 		/* main process, receive loop */
271 273
 		is_main=1;
274
+		pids[0]=getpid();
275
+		process_no=0; /*main process number*/
272 276
 		udp_rcv_loop();
273 277
 	}else{
274 278
 		for(r=0;r<addresses_no;r++){
... ...
@@ -281,16 +290,20 @@ int main_loop()
281 281
 				}
282 282
 				if (pid==0){
283 283
 					/* child */
284
+					process_no=i+1; /*0=main*/
284 285
 #ifdef STATS
285 286
 					setstats( i );
286 287
 #endif
287 288
 					return udp_rcv_loop();
289
+				}else{
290
+						pids[i+1]=pid; /*should be in shared mem.*/
288 291
 				}
289 292
 			}
290 293
 			/*close(udp_sock);*/ /*parent*/
291 294
 		}
292 295
 	}
293 296
 	/*this is the main process*/
297
+	pids[process_no]=getpid();
294 298
 	is_main=1;
295 299
 	if (timer_list){
296 300
 		for(;;){
... ...
@@ -557,6 +570,18 @@ int main(int argc, char** argv)
557 557
 
558 558
 	
559 559
 	if (children_no<=0) children_no=CHILD_NO;
560
+	/*alloc pids*/
561
+#ifdef SHM_MEM
562
+	pids=shm_malloc(sizeof(int)*children_no);
563
+#else
564
+	pids=malloc(sizeof(int)*children_no);
565
+#endif
566
+	if (pids==0){
567
+		fprintf(stderr, "ERROR: out  of memory\n");
568
+		goto error;
569
+	}
570
+	memset(pids, 0, sizeof(int)*children_no);
571
+
560 572
 	if (addresses_no==0) {
561 573
 		/* get our address, only the first one */
562 574
 		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