From: Martin Muenstermann <muenstermann@trustcenter.de>
To: cygwin@cygwin.com
Subject: 1.3.2: setsid() vs. signals
Date: Tue, 04 Sep 2001 04:35:00 -0000 [thread overview]
Message-ID: <3B94BC33.CACAEAF4@trustcenter.de> (raw)
Hi,
I have not found anything about this problem on the mailing list so I am
sending this report:
Running cygwin 1.3.2 on WinNT 4.0 SP 4 I have the following problem:
My app does a fork and daemonizes itself by calling setsid(). When I
press Ctrl-C in the shell where I started the app, the application
receives a SIGINT.
IMHO, after calling setsid() a app should not receive any signals from
the shell any longer (at least this is the case on solaris).
Here is a test application
NOTE: the daemon() function has been taken from openssh (in fact I
noticed the problem by calling "ssh -f myhost xterm"):
/* ---------------------------------- */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define _PATH_DEVNULL "/dev/null"
char* prog;
int
daemon(nochdir, noclose)
int nochdir, noclose;
{
int fd;
switch (fork()) {
case -1:
return (-1);
case 0:
break;
default:
#ifdef HAVE_CYGWIN
/*
* This sleep avoids a race condition which kills the
* child process if parent is started by a NT/W2K service.
*/
sleep(1);
#endif
_exit(0);
}
/* if (setpgid(0,0) < 0 )*/ /* cygwin: setpgid does catch signals */
if (setsid() == -1) /* cygwin: setsid does not catch signals */
return (-1);
if (!nochdir)
(void)chdir("/");
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
(void)dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO);
if (fd > 2)
(void)close (fd);
}
return (0);
}
void sighandler(int sig)
{
printf( "%s: got signal %d, exiting\n", prog, sig );
_exit(2);
}
int main(int argc, char *argv[])
{
int i;
prog = strdup(argv[0]);
for( i = 1; i < 16; i++ )
signal(i, sighandler);
printf( "%s: signal handling activated\n", prog);
printf("running as daemon...\n");
if( daemon(1,1) < 0 )
{
printf("daemon() failed.\n");
exit(3);
}
while(1)
sleep(1);
exit(0);
}
/* ---------------------------------- */
Run it, after the fork press Ctrl-C in the shell.
I receive the message " ./sigint.exe: got signal 2, exiting" and the
process is dead.
BTW: When I call setpgid(0,0) instead of setsid(), signals of the shell
are correctly ignored.
In cygwin 1.1.2 this problem did not occur.
Thanks,
Martin
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
next reply other threads:[~2001-09-04 4:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-04 4:35 Martin Muenstermann [this message]
2001-09-04 18:51 ` Kazuhiro Fujieda
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=3B94BC33.CACAEAF4@trustcenter.de \
--to=muenstermann@trustcenter.de \
--cc=cygwin@cygwin.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).