From owner-freebsd-hackers@FreeBSD.ORG Wed May 24 09:31:02 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2865716A453 for ; Wed, 24 May 2006 09:31:02 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5D0C843D46 for ; Wed, 24 May 2006 09:31:01 +0000 (GMT) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id B539F2089; Wed, 24 May 2006 11:30:56 +0200 (CEST) X-Spam-Tests: none X-Spam-Learn: disabled X-Spam-Score: 0.0/3.0 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on tim.des.no Received: from xps.des.no (des.no [80.203.243.180]) by tim.des.no (Postfix) with ESMTP id 41EEF2087; Wed, 24 May 2006 11:30:56 +0200 (CEST) Received: by xps.des.no (Postfix, from userid 1001) id 2093633CAD; Wed, 24 May 2006 11:30:56 +0200 (CEST) From: des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=) To: "Artem Kazakov" References: <1148448723.1639.102.camel@tyoma.linac.kek.jp> <44740A9F.9080202@elischer.org> Date: Wed, 24 May 2006 11:30:55 +0200 In-Reply-To: (Artem Kazakov's message of "Wed, 24 May 2006 16:41:27 +0900") Message-ID: <86hd3fixbk.fsf@xps.des.no> User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Hackers , Julian Elischer Subject: Re: process descriptor table X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 May 2006 09:31:02 -0000 "Artem Kazakov" writes: > The problem is that at some point a socket() function is called. And > it returns descriptor =3D 1, which is a standart ouput. socket() will not return 1 unless you previously closed descriptor 1, either directly with close(1) or indirectly with fclose(stdout). You probably did something like this: if (sd =3D socket(AF_INET, SOCK_STREAM, 0) !=3D -1) { /* foo */ } which assigns either 1 or 0 to sd depending on whether socket() returned -1. You need to parenthesize the assignment: if ((sd =3D socket(AF_INET, SOCK_STREAM, 0)) !=3D -1) { /* foo */ } You also need to check the return value from either bind() or connect() (they should have failed and set errno to ENOTSOCK), and enable compiler warnings (gcc should have warned you about the dodgy assignment / comparison). DES --=20 Dag-Erling Sm=F8rgrav - des@des.no