* Re: accept does not return in case a signal arrives
2004-11-03 13:26 accept does not return in case a signal arrives Gerrit Bruchhäuser
@ 2004-11-03 13:21 ` Alan Cox
2004-11-03 14:18 ` Andreas Schwab
1 sibling, 0 replies; 3+ messages in thread
From: Alan Cox @ 2004-11-03 13:21 UTC (permalink / raw)
To: Gerrit Bruchhäuser; +Cc: Linux Kernel Mailing List
On Mer, 2004-11-03 at 13:26, Gerrit Bruchhäuser wrote:
> Dear Kernel-team,
>
> on Linux, 'accept' system call does not return in case I send SIGTERM to
> my application; while it does on OSF-Alpha.
signal() may or may not interrupt some system calls. Use sigaction if
you want to force a given behaviour (and write portable code)
^ permalink raw reply [flat|nested] 3+ messages in thread
* accept does not return in case a signal arrives
@ 2004-11-03 13:26 Gerrit Bruchhäuser
2004-11-03 13:21 ` Alan Cox
2004-11-03 14:18 ` Andreas Schwab
0 siblings, 2 replies; 3+ messages in thread
From: Gerrit Bruchhäuser @ 2004-11-03 13:26 UTC (permalink / raw)
To: linux-kernel; +Cc: gbruchhaeuser
Dear Kernel-team,
on Linux, 'accept' system call does not return in case I send SIGTERM to
my application; while it does on OSF-Alpha.
Given the following sample:
,----[ main.cc ]
| #include <sys/types.h>
| #include <sys/socket.h>
| #include <errno.h>
| #include <string.h>
| #include <stdio.h>
| #include <stdlib.h>
| #include <resolv.h>
| #include <signal.h>
|
| #define CHECK_RET_M(arg, x) \
| if (-1 == (x) && errno != EINTR) { \
| printf("System call '%s' failed: %s\n", #arg, strerror(errno)); \
| exit(1); \
| }
|
| typedef struct sockaddr SA;
|
| static void TermHandler(int signu)
| {
| // Nothing
| }
|
| int main(int argc, char *argv[])
| {
| // Create signal handler 4 SIGTERM
| signal(SIGTERM, &TermHandler);
|
| // Create listening socket...
| // argv[1] will be the port number!
| int port = atoi(argv[1]);
| int listen_fd = socket(AF_INET, SOCK_STREAM, 0); CHECK_RET_M(socket,
listen_fd);
|
| struct sockaddr_in servaddr;
| bzero((char *) &servaddr, sizeof(servaddr));
| servaddr.sin_family = AF_INET;
| servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
| servaddr.sin_port = htons(port);
|
| // Bind the socket and switch its state to 'listen'...
| int r = bind(listen_fd, (SA *) &servaddr, sizeof(servaddr));
CHECK_RET_M(bind, r);
| int backlog = 1000;
| r = listen(listen_fd, backlog); CHECK_RET_M(listen, r);
|
| // Wait until client tries to connect...
| struct sockaddr_in cliaddr;
| socklen_t clilen = (socklen_t) sizeof(cliaddr);
| int conn_fd = accept(listen_fd, (SA *) &cliaddr, &clilen);
|
| // If SIGTERM arrives ... the following message should be printed!
| printf("EXIT NOW\n");
| return 0;
| }
`----
Compiled once on each of the systems:
$> g++ -D_POSIX_PII_SOCKET -o main main.cc
Execute in 1st shell:
$> ./main 10000
Execute in 2nd shell:
$> ps -ef | grep -v grep | grep main
$> kill -TERM <pid-of-main>
Results (in 1st shell, on OSF):
EXIT NOW
$>
Linux exectutes the signal handlers code - but 'accept' does not return.
So I've no chance to quit my application in case I have to.
Is there any workaround for my problem?
As I did not subscribe to the list; can you please put me on CC personally?
Many thanks and cheers,
Gerrit
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: accept does not return in case a signal arrives
2004-11-03 13:26 accept does not return in case a signal arrives Gerrit Bruchhäuser
2004-11-03 13:21 ` Alan Cox
@ 2004-11-03 14:18 ` Andreas Schwab
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2004-11-03 14:18 UTC (permalink / raw)
To: Gerrit Bruchhäuser; +Cc: linux-kernel
Gerrit Bruchhäuser <gbruchhaeuser@orga-systems.com> writes:
> Given the following sample:
>
> ,----[ main.cc ]
> | #include <sys/types.h>
> | #include <sys/socket.h>
> | #include <errno.h>
> | #include <string.h>
> | #include <stdio.h>
> | #include <stdlib.h>
> | #include <resolv.h>
> | #include <signal.h>
> |
> | #define CHECK_RET_M(arg, x) \
> | if (-1 == (x) && errno != EINTR) { \
> | printf("System call '%s' failed: %s\n", #arg, strerror(errno)); \
> | exit(1); \
> | }
> |
> | typedef struct sockaddr SA;
> |
> | static void TermHandler(int signu)
> | {
> | // Nothing
> | }
> |
> | int main(int argc, char *argv[])
> | {
> | // Create signal handler 4 SIGTERM
> | signal(SIGTERM, &TermHandler);
Use sigaction.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-11-03 14:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-03 13:26 accept does not return in case a signal arrives Gerrit Bruchhäuser
2004-11-03 13:21 ` Alan Cox
2004-11-03 14:18 ` Andreas Schwab
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.