From owner-freebsd-current Tue Feb 27 16:55:18 2001 Delivered-To: freebsd-current@freebsd.org Received: from mail.gmx.net (sproxy.gmx.net [194.221.183.20]) by hub.freebsd.org (Postfix) with SMTP id 1E7F737B719 for ; Tue, 27 Feb 2001 16:55:15 -0800 (PST) (envelope-from tmoestl@gmx.net) Received: (qmail 4772 invoked by uid 0); 28 Feb 2001 00:55:13 -0000 Received: from p3e9e0415.dip.t-dialin.net (HELO forge.local) (62.158.4.21) by mail.gmx.net (mp017-rz3) with SMTP; 28 Feb 2001 00:55:13 -0000 Received: from tmm by forge.local with local (Exim 3.20 #1) id 14Xutg-0001nQ-00 for ; Wed, 28 Feb 2001 01:55:16 +0100 Date: Wed, 28 Feb 2001 01:55:15 +0100 From: Thomas Moestl To: current@FreeBSD.ORG Subject: Re: [PATCH] for linux_connect (ugly) Message-ID: <20010228015515.A6763@crow.dom2ip.de> Mail-Followup-To: Thomas Moestl , current@FreeBSD.ORG References: <3A6C7C25.A6101656@cup.hp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from mb@imp.ch on Wed, Feb 28, 2001 at 01:17:12AM +0100 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, Feb 28, 2001 at 01:17:12AM +0100, Martin Blapp wrote: > Thomas Moestl and I tried to fix linux_connect. Most of this patch > is from Thomas Moestl. I did only a little part of it and testing. > > Staroffice5.2 has been broken about one year now, and it needs > a fix with the same behaviour to work correctly with FreeBSD. > > This patch should be rewritten so it can be comitted to CURRENT > and (IMPORTANT) to STABLE before 4.3 is out. > > + /* > + * Ugly kluge: some applications depend on 0 being > + * returned only the first time. Therefore, we set > + * the (otherwise invisible) SO_KNBCONN flag. > + * If it is set, return EISCONN. > + */ > + error = holdsock(p->p_fd, linux_args.s, &fp); > + if (error) > + return (error); > + iconn = ((struct socket *)fp->f_data)->so_options & > + SO_KNBCONN; > + ((struct socket *)fp->f_data)->so_options |= SO_KNBCONN; > + fdrop(fp, p); > + > + if (iconn) > + return (EISCONN); Some background: when a socket is connected in non-blocking mode and the connect does not immediately succeed (i.e. EINPROGRESS is returned), linux obviously will return the value getsockopt(...SO_ERROR...) on the socket would give on FreeBSD (i.e. 0 if the connection attempt succeeded) from the first connect() call on the socket after the connection has been established. Only the next call will returne EISCONN. So, the linuxulator has been modified in the past to always return the value getsockopt(...SO_ERROR...) gives. This does break applications that loop and wait for EISCONN, e.g. StarOffice. I might add that I do not particularly like this patch (because of fiddling with the socket internals) and consider it more of a quick fix. A somewhat cleaner solution might be to add a SO_USER socket option that can be freely set or reset by any FreeBSD application (without any effect). This could then be used to store connect state, and linux applications would run fine because they are ignorant of this. This way the getsockopt/setsockopt interface could be used in the linuxulator. Then again, maybe it is better to hide this... Well. I dislike the Linux behaviour. I see no really clean way of emulating this without touching our socket internals (a separate state could be kept in the linuxulator, but this is even more ugly, I presume). - thomas To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message