Date: Wed, 24 May 2006 11:30:55 +0200 From: des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=) To: "Artem Kazakov" <kazakov@gmail.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org>, Julian Elischer <julian@elischer.org> Subject: Re: process descriptor table Message-ID: <86hd3fixbk.fsf@xps.des.no> In-Reply-To: <f84a63260605240041u3c7fe086lb2c7d7aa3309a26c@mail.gmail.com> (Artem Kazakov's message of "Wed, 24 May 2006 16:41:27 %2B0900") References: <1148448723.1639.102.camel@tyoma.linac.kek.jp> <44740A9F.9080202@elischer.org> <f84a63260605240041u3c7fe086lb2c7d7aa3309a26c@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
"Artem Kazakov" <kazakov@gmail.com> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86hd3fixbk.fsf>