[PATCH] logging of pids
Gerd v. Egidy
Wed Apr 28 10:00:32 2010
Hi,
I'm calling dhcpcd from another daemon to handle internet connections via
cable modem (the public ip is configured via dhcp when using a cable modem).
I had problems with multiple dhcpcd running at once. The bugs turned out to be
in my code. But I added the attached two patches to dhcpcd to help me
debugging it.
With them I can exactly see when which daemon is forked by whom.
Please consider applying.
Kind regards,
Gerd
--
Address (better: trap) for people I really don't want to get mail from:
jonas@xxxxxxxxxxxxxxxxx
From d96efffc6b23e37a6e1bf2ba11f477c7a338349b Mon Sep 17 00:00:00 2001
From: Gerd von Egidy <gerd.von.egidy@xxxxxxxxxxxxx>
Date: Wed, 28 Apr 2010 11:51:26 +0200
Subject: [PATCH 1/2] add the pid of the current process to all messages sent to syslog.
useful when debugging forking-problems, multiple daemons running in parallel etc.
---
dhcpcd.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/dhcpcd.c b/dhcpcd.c
index f7d4f9e..983c3b6 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1607,7 +1607,7 @@ main(int argc, char **argv)
struct timespec ts;
closefrom(3);
- openlog(PACKAGE, LOG_PERROR, LOG_DAEMON);
+ openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON);
setlogmask(LOG_UPTO(LOG_INFO));
/* Test for --help and --version */
--
1.6.6.2
From d30c7ea67cab5eb09cd265749e96a5310b66082a Mon Sep 17 00:00:00 2001
From: Gerd von Egidy <gerd.von.egidy@xxxxxxxxxxxxx>
Date: Wed, 28 Apr 2010 11:53:30 +0200
Subject: [PATCH 2/2] log the pid when forking to background.
mark the log entry before forking as LOG_DEBUG as we usually don't have problems
here and don't want to log twice with LOG_INFO
---
bind.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bind.c b/bind.c
index 9e79cea..2987f9c 100644
--- a/bind.c
+++ b/bind.c
@@ -73,7 +73,7 @@ daemonise(void)
syslog(LOG_ERR, "pipe: %m");
return -1;
}
- syslog(LOG_INFO, "forking to background");
+ syslog(LOG_DEBUG, "forking to background");
switch (pid = fork()) {
case -1:
syslog(LOG_ERR, "fork: %m");
@@ -105,6 +105,7 @@ daemonise(void)
}
/* Done with the fd now */
if (pid != 0) {
+ syslog(LOG_INFO, "forked to background, child pid %d",pid);
writepid(pidfd, pid);
close(pidfd);
pidfd = -1;
--
1.6.6.2
Archive administrator: postmaster@marples.name