SIGINFO interrupts connect() with libpthread
Daniel Eischen
deischen at freebsd.org
Fri Oct 7 09:26:24 PDT 2005
On Thu, 6 Oct 2005, Robert Watson wrote:
>
> I was writing test tools yesterday, and was a bit surprised to find that
> hitting ctrl-T interrupts connect() for applications linked against
> libpthread(). I wrote a simple test tool and found that this is not the
> case for any of the other thread libraries (which seems correct to me).
> Test tool attached:
This isn't a problem with libpthread. If you install a signal
handler for SIGINFO in your application with sa_flags = SA_RESTART,
it gets interrupted even when just linked with libc.
--
DE
/*-
* Copyright (c) 2005 Robert N. M. Watson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <err.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void
sighandler(int sig)
{
}
int
main(int argc, char *argv[])
{
struct sockaddr_in sin;
struct sigaction act;
int sock;
if (argc != 3)
errx(-1, "usage: connect [ip] [port]");
sigfillset(&act.sa_mask);
act.sa_flags = SA_RESTART;
act.sa_handler = sighandler;
sigaction(SIGINFO, &act, NULL);
bzero(&sin, sizeof(sin));
sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr(argv[1]);
sin.sin_port = htons(atoi(argv[2]));
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock < 0)
err(-1, "socket(PF_INET, SOCK_STREAM, 0)");
printf("Connecting to %s:%d\n", inet_ntoa(sin.sin_addr),
htons(sin.sin_port));
if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)
err(-1, "connect(%s %d)", inet_ntoa(sin.sin_addr),
htons(sin.sin_port));
printf("Connected\n");
return (0);
}
More information about the freebsd-threads
mailing list