Skip to Content.
Sympa Menu

freetds - Re: [freetds] Patch to fix nasty HP-UX problem (was TSQL error - connect error: Not owner)

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Patch to fix nasty HP-UX problem (was TSQL error - connect error: Not owner)
  • Date: Wed, 13 Feb 2008 08:47:30 +0100

>
> ZIGLIO, Frediano, VF-IT wrote:
> > # if defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)
> > # undef _XOPEN_SOURCE_EXTENDED
>
> I do not like '#if OS' tests; I prefer '#if FEATURE'. What
> feature are
> you testing?
>
> I think the test is:
>
> For a 64-bit machine, make sure the signature is
>
> extern int getsockopt __((int, int, int, void *, socklen_t *));
>
> and not
>
> extern int getsockopt __((int, int, int, void *, int *));
>
> Is that correct?
>

No, the problem is that hp-ux define

extern int getsockopt __((int, int, int, void *, socklen_t *));

if _XOPEN_SOURCE_EXTENDED is defined and

extern int getsockopt __((int, int, int, void *, int *));

is not defined. However socklen_t and int are not compatible on 64-bit
so the result is that defining _XOPEN_SOURCE_EXTENDED you get a wrong
definition. A wrong definition means that compiled getsockopt is defined
taking an int* instead of a socklen_t. So if you use socklen_t version
you will have a pointer problem. In this case you don't have "classic"
memory errors (leak, overflows) but a bad interpretation. Doing to the
fact that this is a hp-ux problem I used __hpux check.

> We can add a config.ac test that compiles getsockopt passing
> socklen_t* as
> the 4th argument. If that works on a 64-bit machine, ok, else it can
> undefine _XOPEN_SOURCE_EXTENDED and try again. Outcomes:
>
> 1. Works first time, OK out of the box.

It worked so but on hp-ux having _XOPEN_SOURCE_EXTENDED this assume that
socklen_t is correct.

> 2. Works if _XOPEN_SOURCE_EXTENDED is undefined.
> (#define UNDEF_XOPEN_SOURCE_EXTENDED_4_GETSOCKOPT 1)
> 3. Does not work, #error.
>
> Then your code becomes:
>
> #if HAVE_SYS_SOCKET_H
> # if UNDEF_XOPEN_SOURCE_EXTENDED_4_GETSOCKOPT
> # define tds_XOPEN_SOURCE_EXTENDED \
> _XOPEN_SOURCE_EXTENDED
> # undef _XOPEN_SOURCE_EXTENDED
> # include <sys/socket.h>
> # define _XOPEN_SOURCE_EXTENDED \
> tds_XOPEN_SOURCE_EXTENDED
> # undef tds_XOPEN_SOURCE_EXTENDED

Ehmm.... so at the end you have _XOPEN_SOURCE_EXTENDED defined as
tds_XOPEN_SOURCE_EXTENDED ?? I understand what you want to do but these
defines cannot work. Defines are expanded when used. Assuming
_XOPEN_SOURCE_EXTENDED defined as 1 and tds_XOPEN_SOURCE_EXTENDED
undefined

_XOPEN_SOURCE_EXTENDED 1
tds_XOPEN_SOURCE_EXTENDED undefined

#define tds_XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE_EXTENDED

_XOPEN_SOURCE_EXTENDED 1
tds_XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE_EXTENDED

#undef _XOPEN_SOURCE_EXTENDED

_XOPEN_SOURCE_EXTENDED undefined
tds_XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE_EXTENDED

#define _XOPEN_SOURCE_EXTENDED tds_XOPEN_SOURCE_EXTENDED

_XOPEN_SOURCE_EXTENDED tds_XOPEN_SOURCE_EXTENDED
tds_XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE_EXTENDED

#undef tds_XOPEN_SOURCE_EXTENDED

_XOPEN_SOURCE_EXTENDED tds_XOPEN_SOURCE_EXTENDED
tds_XOPEN_SOURCE_EXTENDED undefined

This is why I defined _XOPEN_SOURCE_EXTENDED as 1 at the end. Code check
using #if(n)def or #if so defining to one should work as expected.

> # else
> # include <sys/socket.h>
> # endif
> #endif /* HAVE_SYS_SOCKET_H */
>
> That logic preserves the value of _XOPEN_SOURCE_EXTENDED, in case it
> matters.
>
> How does that sound?
>

Personally I don't like to replace system include with local ones.
Usually in source file local includes are included after system ones...
Also perhaps it would be better to include multiple systems headers in
tdssockets.h.
I don't like all that code just to fix a problem for a single system but
this problem has to be fixed... and problem reside on the system header
so you are just writing a workaround...

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page