SIGINFO interrupts connect() with libpthread

Robert Watson rwatson at FreeBSD.org
Thu Oct 6 04:15:10 PDT 2005


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:

peppercorn:~/tmp/connect> ./connect 192.168.100.203 80
Connecting to 192.168.100.203:80
load: 0.00  cmd: connect 54400 [runnable] 0.00u 0.00s 0% 972k
^C

peppercorn:~/tmp/connect> ./connect_libthr 192.168.100.203 80
Connecting to 192.168.100.203:80
load: 0.00  cmd: connect_libthr 54399 [connec] 0.00u 0.00s 0% 740k
^C

peppercorn:~/tmp/connect> ./connect_libpthread 192.168.100.203 80
Connecting to 192.168.100.203:80
load: 0.00  cmd: connect_libpthread 54401 [runnable] 0.00u 0.00s 0% 844k

connect_libpthread: connect(192.168.100.203 80): Interrupted system call
peppercorn:~/tmp/connect> ./connect_libc_r 192.168.100.203 80
Connecting to 192.168.100.203:80
load: 0.00  cmd: connect_libc_r 54402 [runnable] 0.00u 0.00s 0% 972k
^C

(note the importance of running the connect tool against an IP that won't 
respond, or you will connect rather than blocking)

Robert N M Watson
-------------- next part --------------
all: connect connect_libthr connect_libpthread connect_libc_r

connect: connect.c
	gcc -Wall -o connect connect.c

connect_libthr: connect.c
	gcc -Wall -o connect_libthr connect.c -lthr

connect_libpthread: connect.c
	gcc -Wall -o connect_libpthread connect.c -lpthread

connect_libc_r: connect.c
	gcc -Wall -o connect_libc_r connect.c -lc_r


-------------- next part --------------
/*-
 * 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 <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char *argv[])
{
	struct sockaddr_in sin;
	int sock;

	if (argc != 3)
		errx(-1, "usage: connect [ip] [port]");

	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