[net.unix-wizards] Identify program error messages, please!

idallen (07/23/82)

Programs that issue error messages should always, always, always
prefix the message by their invoking name.  I've just seen three
"can't stat" messages come after doing an inews and while doing
a readnews.  Do I know which program they came from?  No.
I'll have to mess around needlessly to find out where the problem is.

Please, all you Wizards and programmers, label your output!
This is so very important in a multi-process environment where
messages could come from any of several concurrently executing
processes.     -IAN!    U of Waterloo

smb (07/25/82)

I agree that error messages should be identified.  Unfortunately, it
takes a little forethought -- 'perror' doesn't make that easy on you; it
should take two arguments, or it should fill in the command-name itself.
Amdahl's UTS (UNIX/370) system stores argv[0] in 'cmdname' in the
run-time startup routine (crt0.o); that makes it globally accessible,
like 'environ', and hence makes it easier on programmers.


		--Steve Bellovin

dan@Bbn-Unix@sri-unix (08/21/82)

From: Dan Franklin <dan@Bbn-Unix>
Date: 10 Aug 1982  9:52:14 EDT (Tuesday)
When I started working with UNIX I wrote a set of routines which act
a lot like printf, but make it easy to print the name of the
command and the system error. The basic one was 
	cmderr(errno_value, format_string, args...)
which printed out the value of the global variable "progname",
followed by a colon, followed by the format_string and args a la printf,
followed by the system error message corresponding to errno_value
(if it's not zero). If errno_value was -1 it looked at "errno" itself
and used that. A useful variant of this routine was "ecmderr", which did
all that and then exited. 

The problem with any routine which takes a fixed number of arguments
is that I always have more to say than it can accomodate. The typical
case is a failed open; I want to print the program name, an error message
containing the filename, and the system error message. Only printf-style
routines are flexible enough to handle this and similar cases.

gwyn@Brl@sri-unix (08/21/82)

From:     Doug Gwyn <gwyn@Brl>
Date:     10 Aug 82 13:25:34-EDT (Tue)
Whitesmiths run-time library has the right idea; their equivalent of
"perror" prefixes error messages with the program name (set by the
equivalent of crt0).  I think this should be made standard on UNIX.

thomas (08/21/82)

We have a macro, called SCREAM, which prints the file name, a colon, and
an error message.  Not quite as good as the program name, but it is
easily determined by the pre-processor at compile time.  The text is:

#define	SCREAM(msg)	(fprintf(stderr,"%s: ",__FILE__),\
 			eprintf msg)	/* print an error msg */

eprintf is like printf, but printes on stderr.  The only weird thing with
this macro is that it takes only a single argument:  The printf argument
list, enclosed in parens.  Thus, an invocation might be:
	SCREAM( ("Can't open file %s\n", filename) );

=Spencer