From: "John Z. Bohach" <jzb2@aexorsyst.com>
To: linux-kernel@vger.kernel.org
Subject: signals dropped when proc. run as daemon, but not when in the foreground
Date: Tue, 25 Sep 2007 20:43:41 -0700 [thread overview]
Message-ID: <200709252043.41319.jzb2@aexorsyst.com> (raw)
Hello,
I'm writing a system app. that becomes a daemon by the usual fork() ->
setsid() -> fork() method.
It then registers a signal handler for SIGCHLD via sigaction (SA_SIGINFO
style).
chldAction.sa_sigaction = sigChld;
sigemptyset(&(chldAction.sa_mask));
chldAction.sa_flags = SA_SIGINFO;
rc = sigaction(SIGCHLD, &chldAction, NULL);
Its a network service server, so it does the usual
socket->bind->listen->select->accept->fork sequence to handle a new
connection.
The child processes the connection, then exits. This should generate
the standard SIGCHLD signal to the parent, which catches it via the
sigaction with the following handler:
static void
sigChld(int signum, siginfo_t * siginfo, void * ucontext)
{
int childStat;
log_dbg("received signal %d\n", signum);
if (signum != SIGCHLD) /* technically can't happen here... */
return; /* but ignore it if it does */
if (waitpid(siginfo->si_pid, &childStat, 0) > 0)
{
if (WIFEXITED(childStat))
log_dbg("child %d WIFEXITED with childStat %d\n",
siginfo->si_pid, WEXITSTATUS(childStat));
if (WIFSIGNALED(childStat))
{
log_dbg("child %d WIFSIGNALED with childStat %d\n",
siginfo->si_pid, WTERMSIG(childStat));
}
}
return;
}
Here's the problem: when run as a daemon, as above, I don't get the
SIGCHLD. I've instrumented it to show the child exiting, and it does,
and it even becomes defunct (on account of the lack of waitpid from the
signal handler).
HOWEVER, if I run the program in the foreground, without
fork()->setsid()->fork() sequence, EVERYTHING is FINE!
I am going insane? This is on a 2.6.20.6 kernel, and I just can't see
that this would be a kernel bug, but I don't know if/what I'm doing
wrong myself?
Is there something I could do to test something...I've been at this for
a few days now and I'm out of ideas...
Thanks,
John
reply other threads:[~2007-09-26 3:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200709252043.41319.jzb2@aexorsyst.com \
--to=jzb2@aexorsyst.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®