.DA "12 May 1990"
.TL
Known Porting Problems With C News
.AU
Henry Spencer
.AI
Dept. of Zoology
University of Toronto
.SH
Intro
.PP
C News in general is pretty portable.
People have got it to run on a very wide range of systems with little
trouble.
Difficulties are usually problems in the system, not C News.
Some of them, however, are widespread enough to be worth comment, for
the guidance of people having problems.
If you run into a novel problem,
we are always interested in hearing about such things.
.SH
Unix Dependencies
.PP
The biggest portability glitch in C News is that it depends a lot on Unix
utilities.
The extensive use of complex shell files, \fIsed\fR and \fIawk\fR programs,
and a wide range of lesser Unix utilities would make it quite difficult
to move C News to a system that is seriously non-Unix-like.
The actual C programs seldom depend on Unix in major ways.
(An exception is the use
of \fIread\fR system calls in \fIexpire\fR, to avoid difficulties with
stdio end-of-file behavior;
we now know how to avoid this but haven't implemented the fixes yet.)
.PP
We know that \fIawk\fR and the colon (:) operator of \fIexpr\fR are
problem areas under Minix.
.SH
Shell Problems
.PP
C News seriously stress-tests shells.
The current Minix shell is not robust enough
in the face of complex inputs, botches some constructs entirely,
and can run out of memory on the complex shell files.
Any shell that is too old to implement comments begun
by ``#'' is big trouble, since we use such comments everywhere.
.PP
Any system/shell combination that thinks that a shell script starting
with ``#!\ /bin/sh'' should be run by the C Shell (because it starts
with `#') is also big trouble:
you will have to change that line to ``:\ use\ /bin/sh'' everywhere.
We know that at least some releases of Xenix have this problem.
It is not necessary that your kernel understand the ``#!'' feature\(emwe
believe that nothing in C News relies on it\(embut it is essential that
it not cause invocation of the C Shell.
.PP
We know that some Hewlett-Packard Unixes have broken shells, probably
the result of mistakes in
HP's efforts to make
the shell 8-bit-clean; the symptom is
that something like:
.DS
x=y
if test " $x" != " y"
then
	echo oops
fi
.DE
prints ``oops''.
This is, again, big trouble, because we do that a lot.
.PP
Many people using 3B1s, aka UNIX PCs,
run the Korn shell as their \fI/bin/sh\fR.
Some other folks may do this too.
Beware that \fIksh\fR was not fully \fIsh\fR-compatible for a
long time, with some subtle differences in the
ill-documented behavior of backquotes and backslashes.
Some of the C News shell scripts,
notably \fIinews\fR,
are known to hit these bugs.
We are \fItold\fR that current \fIksh\fRs have fixed them.
.SH
Make vs. Test
.PP
There is a persistent problem on 3B2s with implementations of \fImake\fR
that violate the SVID in a subtle way.
They attempt to execute makefile commands directly, rather than via the
shell, if the commands do not contain metacharacters.
This means that if\(emas on many 3B2s\(em\fItest\fR is a shell builtin
\fIand there is no /bin/test program\fR, the makefile line
``test\ \-s\ file'' will cause \fImake\fR to complain about an unknown
command.
(The SVID says that makefile commands must be executed as if by
the shell, and the shell will execute this line correctly.)
We've added `;' on the ends of such lines, which suffices to convince
\fImake\fR to run a shell on the systems we've encountered, but AT&T
is good at finding ways to break such workarounds.
This problem is also known to occur in A/UX.
.SH
Offsetof
.PP
ANSI C requires C compilers to supply a macro \fIoffsetof\fR, which can
be used to find the offset of a structure member within the structure.
\fIRelaynews\fR's header-parsing code uses it,
defining it if the system has not supplied it.
Unfortunately, it is really hard to write a portable version of this.
The implementation we currently use is:
.DS
#define offsetof(type, mem) ((char *)&((type *)NULL)\->mem \- (char *)NULL)
.DE
The table in \fIrelay/hdrdefs.c\fR
puts invocations of \fIoffsetof\fR in initializers.
This turns out to be a severe stress test for C compilers.
A compilation error in \fIhdrdefs.c\fR is almost certain
to be problems with this macro.
Some compilers,
notably the one in Microport System V for the 286,
reject it.
We have heard a report that System V Release 2 on the VAX silently
miscompiles it!
If you have trouble with \fIoffsetof\fR, you might try this version instead:
.DS
#define offsetof(type, mem) ((int)&((type *)NULL)\->mem)
.DE
.SH
Fast Stdio Routines
.PP
We supply a set of fast standard-I/O routines that are compatible with
most AT&T-derived implementations of \fIstdio\fR.
They speed up C News quite a bit.
However, they don't work on all Unixes.
The tester program we supply, which the library-build procedure runs,
is thought to diagnose such problems 100% of the time.
It has been reported in the past that A/UX and Microport 386 stdios
flunk the test.
SunOS 4.0 used to pass the test falsely, but improvements in both
the test and the routines
seem to have cured the problems:
4.0.3 passes the test and
as far as we can tell,
the routines run correctly under it.
.PP
In any case, if you are feeling nervous or are having mysterious problems,
telling \fIbuild\fR that you don't want to use the fast-stdio stuff is
always safe.
.SH
Readnews vs. System V
.PP
The terminal handling in the Australian \fIreadnews\fR that we include
is known not to work under a ``pure'' System V.
There are stubs for System V code but it's never been implemented.
Most current System V implementations from serious suppliers have enough
BSD compatibility that this is not an issue.
.SH
Readnews Simplicity
.PP
Generally, the Australian \fIreadnews\fR
is a bit on the simple and buggy side.
There are various things wrong with it that we're not very interested
in fixing\(emwe consider it useful primarily for naive users who just
want to read system announcements, and recommend that sophisticated
users use something else.
One known interoperability issue is that it is fussier about the format
of \fI.newsrc\fR files than fancier readers.
.PP
Problems will arise if the news directories are in non-standard places,
because \fIreadnews\fR is not well integrated into our configuration
machinery; we want to fix this someday.
.SH
void
.PP
Old compilers that don't understand the \fIvoid\fR type will choke on
much of our code.
There is a commented-out ``#define\ void\ int'' in \fInews.h\fR that
cures most cases of this if you uncomment it.
(We have a report that you might need to add ``\-Dvoid=int'' to the
Makefile in \fIlibv7\fR if you're using that library.)
C News does not rely on the ANSI C ``void\ *'' type as far as we know.
.SH
Read/write Modes in fopen
.PP
Unix V7 documented only ``r'', ``w'', and ``a'' as suitable mode arguments
to \fIfopen\fR.
It actually implemented the read/write modes, ``r+'', ``w+'', and ``a+'',
as well, and C News relies on them.
Unix reimplementations based on old documentation may have trouble here;
we know that at least the older versions of Minix really don't implement
these modes.
.SH
MAXLONG
.PP
The \fIrelay/cpu.h\fR file formerly defined a constant \fIMAXLONG\fR
which is the biggest positive value of a \fIlong\fR.
The definition was clever but failed on some odd systems (Unisys?).
Current versions of C News
generate the value dynamically in a less fallible way,
and check the value for plausibility.
(This is encountered when \fIrelaynews\fR is asked to
process a single article, not a batch.
This happens primarily when an article is posted locally, with \fIinews\fR.)
It is still barely possible that the plausibility check will fail on some
bizarre system.
.SH
df Output Format
.PP
The \fIspacefor\fR utility needs to understand the output format of \fIdf\fR.
There are numerous variations on \fIdf\fR.
\fIBuild\fR and the relevant makefiles know about the more common ones,
but customization may be necessary.
\fISpacefor\fR is commented well enough that it should be possible to
figure out the necessary changes; usually the initializations of \fInr\fR
and \fInf\fR are all that need changing.
If there are colons (:) in your \fIdf\fR's output format, you should
probably start from the ``sysv'' \fIspacefor\fR, which attempts to
preprocess the output to get rid of System V garbage;
otherwise the ``bsd'' one is a reasonable starting point.
.PP
One constant nuisance is \fIdf\fRs that are too stupid to take a directory
name as an argument.
The long-term solution to this is to edit a suitable variant of \fIspacefor\fR
to know about the proper arguments.
A short-term solution is to use the ``null'' variant, sacrificing space
checking for the sake of getting something working.
.PP
We're told that HP-UX 7.0 users are best advised to
choose the ``bsd'' variant of spacefor, and edit it to
call \fIbdf\fR instead of \fIdf\fR.
Similar approaches may be useful on other hybrid SysV/BSD systems.
.SH
Floating Point
.PP
The only place in C News where floating point is used, as far as we know,
is in the calculation of expiry dates in \fIexpire\fR.
This is not a performance bottleneck, so slow floating-point arithmetic
is not a problem.
Complete absence of floating point would require minor modifications to
\fIexpire\fR.
.SH
386 Optimizer vs. dbz
.PP
We have a reliable report that the System V 386 optimizer (invoked when
\fIcc\fR is given the \fB\-O\fR option) miscompiles the \fIdbz\fR package
badly enough to cripple it, without producing any error messages.
The only fix is to compile \fIdbz\fR without \fB\-O\fR.
.PP
SCO Xenix/386 2.3 has the same problem.
.SH
nnafree and nnfree
.PP
We have a reliable report that
the HP Spectrum C compiler has an optimiser bug that makes it throw up
(with a 
``cc: Internal error 3279: Please contact your local HP representative''
message)
on the \fInnafree\fR macro
(and \fInnfree\fR, a historical synonym)
in \fIh/news.h\fR.
The following revised version of
the macro reportedly avoids
the problem.
.DS
#define nnafree(mempp) do { if (*(mempp) != 0) { free((char *)*(mempp)); \e
   *(mempp) = 0; }} while (0)
.DE
.PP
It is also reliably reported that the Microport compiler objects to
these macros in large model.
Whether the above fix would suffice is not known.
Manual expansion [barf!] is known to work, although it would be less
painful to define a function containing the right code and change the
macro to call the function.
Code for a suitable function can, in fact, be found
in \fIh/news.h\fR,
inside `#ifdef\ lint'.
.SH
ANSI C
.PP
Although we made an effort to be ANSI-C compatible,
lack of access to a real ANSI C compiler limits our ability to do this.
A secondary problem is that it's really very difficult to get code that
is 100% acceptable to both ANSI C compilers and older compilers.
Some issues inevitably got resolved in favor of current compilers,
and may cause complaints from ANSI C compilers.
.SH
GNU C
.PP
If compiling with the GNU compiler, you will need the
\fB\-traditional\fR flag.
Beware, also, that if you are using your system's \fIdbm\fR library,
it contains functions that return structure values, and the GNU conventions
for handling such values are incompatible with the ones in many AT&T-derived
compilers.
The
\fB\-fpcc-struct-return\fR option cures this.
.SH
Eccentric Awks
.PP
A number of problems can arise if your \fIawk\fR has bugs, since the shell
files rely on \fIawk\fR fairly extensively.
For example, \fIawk\fR is a prime suspect if \fIspacefor\fR doesn't work.
We've fixed the worst trouble spots, but would appreciate detailed information
on any more.
.SH
Systems Without Hard Links
.PP
Some vaguely Unixoid systems have trouble implementing real (``hard'') links.
Examples are VMS in general and Eunice in particular.
There are some hooks for dealing with this, but it's not trivial.
.PP
\fIRelaynews\fR will try to make symbolic links if real ones fail.
There is one exception:
if \fIrelaynews\fR cannot buffer up enough of the article in memory to
find the `Newsgroups:' line, it will drop the article into a temporary
file and will rely on being able to move that to the first of the
`real' locations by manipulating links.
This should essentially never happen except on 16-bit machines,
and should be rare even on them.
.PP
\fIExpire\fR has a \fB\-l\fR option which
tells it to consider the first filename of an article its `leader',
not expiring the article under that name until it has expired under
all others.
This has not been tested much recently.
.PP
The locking system (both C routines and the \fInewslock\fR program)
will need revision in some system-dependent way to avoid use of links.
.PP
There is one minor use of links in installation (\fIinews\fR is found
in two places, and the Makefile attempts a link before doing a copy),
and substantially more in the regression tests.
.SH
16-bit Machines
.PP
C News has been tested on 16-bit machines\(emindeed, a good bit of the
early development work was done on one\(emand does run on them.
Nothing relies on ints being 32 bits.
Nothing relies on pointers and ints being the same size, as far as we know.
Nothing relies on large address spaces,
although one or two modules come in separate small-space and large-space
versions, and the small-space versions are slower.
.PP
However, there are some fundamental limits
to consider.
Both \fIrelaynews\fR and \fIexpire\fR\(emthe usual trouble spots for
space shortages\(emwant to keep lots of stuff in core.
There isn't any easy way around this one.
.SH
Number of File Descriptors
.PP
There is a constant, NOPENBFS, in \fIrelay/trbatch.c\fR, that defines
how many batch files are kept open simultaneously.
If you are feeding much news to more systems than this,
\fIrelaynews\fR performance will suffer.
.PP
The major limit on NOPENBFS is available file descriptors
(although on a 16-bit machine there might also be a shortage of memory
for \fIstdio\fR buffers).
Other parts of \fIrelaynews\fR want perhaps 10 file descriptors for
other purposes, so with the usual total supply of 20, a NOPENBFS value
of 10 is the right default.
If you feed many people,
and your kernel provides a process with more than 20 file
descriptors,
you probably want to boost
NOPENBFS (this can be done with -DNOPENBFS=xxx in the makefile).
Remember to leave about 10 descriptors worth of headroom.
.SH
Shell Processing Order
.PP
Normally, shell
variable expansion should take place before scanning for syntax
elements such as ``0<&1''.
At least one reimplementation of the shell
(specifically, Bash 1.04) does things in the
wrong order.
This is known to affect, at least, \fIrelay/sh/anne.jones\fR,
which can be fixed by changing (circa line 44)
.DS
"")	USER="`who am i <&$fd |
.DE
to
.DS
"")	USER="`eval \e"who am i <&$fd\e" |
.DE
or so we are told.
.SH
Binary-Mode Fopen
.PP
In several places, the new
\fIdbz\fR
uses ANSI C ``binary mode'' fopen codes, e.g.
`fopen(...,\ "r+b")'.
The text/binary distinction involved is meaningless
under Unix, and most Unix implementations just ignore trailing nonsense in
the second argument of
\fIfopen\fR,
so it all works out nicely.
.PP
Unfortunately... at least one version of DEC's Ultrix objects to the `b's,
we are told.
Sigh.
DEC will have to fix this to make their systems ANSI
compatible, but heaven only knows how long that will take.
.PP
Meanwhile, the fix is to delete the `b's in the second arguments of the
\fIfopen\fRs
in three places in
\fIdbminit()\fR
in
\fIdbz/dbz.c\fR,
if your system has
this particular bit of brain damage.
.SH
size_t
.PP
Some systems, notably from Microport, do not define the
\fIsize_t\fR type in the \fI<sys/types.h>\fR header.
Worse, the \fIsize_t\fR in that header doesn't necessarily bear any
relationship to the ANSI C \fIsize_t\fR.
This causes trouble in the \fIdbz\fR library in particular.
The proper type for \fIsize_t\fR is whatever the C \fIsizeof\fR
operator returns, nominally an unsigned type which is large enough to
contain the size of any memory object.
We think nothing relies too heavily on it being unsigned.
Note that \fIsize_t\fR must also be suitable for use in the two middle
arguments of \fIfread\fR and \fIfwrite\fR, the last argument of
\fImemcpy\fR, \fImemchr\fR, and \fImemcmp\fR,
and the argument of \fImalloc\fR.
.SH
Background Processes vs. csh
.PP
\fIInews\fR runs much of its processing in the background.
We are told that this can hit problems, in some circumstances,
with \fIcsh\fR's manipulations of signals, terminal modes, etc etc.
We prefer a standard shell, and have made no attempt to understand the
C shell's weirdnesses.
We're aware that well-written programs can fail
under the C shell due to bizarre problems with weird signals, etc., but
we class this as the fault of the C shell and its co-conspirators and
decline to contort our programs to compensate for its failings.
We do
sympathize with people victimized by it, but can be of no practical help.
