🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #19625

Re: Problem with 'snprintf' in Solaris 2.5 (INN 1.6b1)

#19625
From: USENET news
Date: Thu, 24 Jul 1997 00:00
100 lines
5565 bytes
In article <casper.869756597@uk-usenet.uk.sun.com>,
Casper H.S. Dik - Network Security Engineer <Casper.Dik@Holland.Sun.COM> wrote:
>news@news.cam.ac.uk (USENET news) writes:
>
>>On Solaris 2.5.1 with Sun's C compiler (V4.0), the recipe which I found to
>>work was
>
>>(a) Enable the assignment "BAD_FLOAT = -DBad_float_h" (near the top of the 
>>newlog Makefile) by removing the "#" comment character.
>
>What does this do?

It "#undef's __STDC__" in one source file, though why that is needed is not
explained anywhere that I've noticed. This probably ties in with your 
comments below about gcc's interpretation of __STDC__ and knock-on effects 
for code written with gcc in mind.

>>(b) Add " -Dsun -D__svr4__ -Xc" to the "live" CFLAGS line (not the 
>>commented-out alternative one) in Makefile.
>
>Why do they need this?
>
>Gcc uses __svr4__ && __SVR4; Sun's compiler's use __SVR4.  Why not
>use __SVR4?
>
>Why -Xc?  That tells the include files not to include anything that's
>not standard conformant. (i.e., anything that conflicts with the
>user defined namespace).  Do they need to have __STDC__ defined as 1?
>(Which should mean obsolute standard conformance; but gcc maintainers
>feel you can defined __STDC__ as 1 w/o being standard conformant; and
>have invented __STRICT_ANSI__ for that purpose.  Kinda defeats the
>reason of having standards in the first place)

I think the answer to both questions is "because the newlog package assumes 
gcc will be used". Since I hadn't been planning on spending time building a 
new version of INN until later in the summer (and was expecting that to be 
just building 1.5.1 for our main server, when I'd been running it for a 
while on other systems), my aim was to get it working without extensive
rewriting or analysis of the supplied source code. 

The code appeared to misbehave if _STDC_ wasn't defined (tested in some
places with "#if defined(__STDC__)", in others, "#if __STDC__") and since it 
was supposedly portable (for some odd definition of portable :-), shouldn't
need any Sun extensions so that -Xc should be OK. Conditional sections
elsewhere in the code rely on test like "#if defined(sun) &&
defined(__svr4__)", so defining them explicitly was the quick solution.

[Until I worked out the above combination, linking e.g. the test programs 
needed -lsocket -lsunmath -lm, and then caused syslog messages to vanish.]

>>but nothing would get logged by INN via syslog. It provides a replacement
>>syslog() which will truncate the logged message if necessary - with an
>>indication that it's happened - but without the magic noted above, syslogd
>>wouldn't recognise those messages (or something...).
>
>You dont' need that in Solaris; it's syslog will truncate such messages.

I thought I'd seen that mentioned (quite probably by you on 
comp.unix.solaris!) - but wasn't sure which versions (as shipped, or with
patches?), and in any case, short of hacking things (not necessarily
extensively!), it's what happens naturally once you get past the other
problems.

>>in Makefile implies that float.h is *always* broken if you aren't using gcc 
>>(and hence is right if using gcc :-); that seems far-fetched, but
>>un-commenting the line did make things work with Sun's cc, even though it
>>compiled OK (but didn't work) without. (b) is needed because Sun's cc
>>defines different preprocessor symbols to indicate you're on Sun hardware
>>and SVR4, and its default mode (ANSI C plus Sun extensions) does not set
>>_STDC_, which you get only if you specify strict ANSI C compliance with -Xc
>
>
>Actually, it sets __STDC__ as 0.  And you'd perhaps want
>-Xc -D__EXTENSIONS__ instead. (__STDC__ as 1 but w/ the extensions)

Ah, useful to know (and not mentioned or hinted at by "man cc", as far as 
I can see quickly :-).

>Beats me why they think float.h is bad.

It looks like the newlog code makes some odd assumptions about float.h and
then has to fix reality to match, but I haven't tried analysing just what
its requirements actually are. The README file indicates newlog's basically
bits of BSD 4.4-lite modified to fix the syslog buffer overflow problems,
plus providing snprintf for systems that don't have it. [Since this has all 
been something of a rush, I - for one - have not followed up by mailing the 
newlog contact address about these issues.]

For info, the functions which appear to be defined in the libnewlog
resulting from using the above recipe (from "nm -g") are BSD__sfvwrite,
BSD__dtoa, BSD_vfprintf, closelog, openlog, setlogmask, snprintf, strerror,
syslog, vsnprintf, vsyslog.

                                John Line
--
Cambridge University Computing Service - USENET news manager. Usually John Line
newsmaster@ucs.cam.ac.uk    (alias {newsmaster,news,usenet}@news.cam.ac.uk)

Technical Details
Message-ID: <5r89lh$c48@lyra.csx.cam.ac.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <33D4F714.41C6@rediris.es> <33d4fff4.586615989@nntp.uunet.ca> <5r7gf7$knm@lyra.csx.cam.ac.uk> <casper.869756597@uk-usenet.uk.sun.com>

Show Full Headers
Complete Article Headers
Message-ID: <5r89lh$c48@lyra.csx.cam.ac.uk>
Subject: Re: Problem with 'snprintf' in Solaris 2.5 (INN 1.6b1)
Date: Thu, 24 Jul 1997 00:00:00 +0000
From: news@news.cam.ac.uk (USENET news)
References: <33D4F714.41C6@rediris.es> <33d4fff4.586615989@nntp.uunet.ca> <5r7gf7$knm@lyra.csx.cam.ac.uk> <casper.869756597@uk-usenet.uk.sun.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 258547338
Organization: Computing Service, Cambridge University, England
Newsgroups: news.software.nntp