bug in ucbmail and 4.1bsd csh

Ben Goldfarb Esq. goldfarb at ucf-cs.UUCP
Thu Dec 8 14:45:33 AEST 1983


I resolved a nasty problem here recently that involved both ucbmail
and csh.  I'll describe both, but I only have a fix for ucbmail;
I'd like to hear some opinions on what to do about csh.  These both
apply to 4.1bsd, since I am still waiting for Berkeley to send us
a 4.2 tape.

The user who unearthed the ucbmail problem had a line like the
following in his .mailrc:
   
     set record=~clay/mailout

When he sent mail, most of the time he would have no difficulties,
but occasionally he would get the error message:

     "~clay/mailout": Ambiguous

Checking it out, I found that the code that expands the tilde in
ucbmail forks an instance of csh which pipes the result of "echo ~clay/mailout"
back to mail.  In fio.c (ver. 2.2 7/20/81) the execl appears in the routine
expand() as follows:

     execl(Shell, Shell, "-c", cmdbuf, 0);

The problem with this is that if the user has set the mail variable in
his .cshrc and if h happens to have mail in his spool file,
the instance of csh that was invoked by mail will return
"You have mail." instead of the user's home directory.  Obviously,
ucbmail considers this ambiguous, but it was a bitch to track down since
the error message gives the argument of echo, not the string returned
from csh through the pipe.  This, of course, only happens when the
invoker has mail in his spool file.

I think the solution to this is obvious at this point.  Don't source the
user's .cshrc when you exec the shell and the problem disappears with
the added benefit that the exit from mail is quicker.  Thus, the above line
should be changed to:

     execl(Shell, Shell, "-cf", cmdbuf, 0);

Please let me know if anyone sees any problems in not sourceing .cshrc
in this case; I can't see any.

Now on to the csh problem.  I ran into it when I was investigating the 
previous situation since it involves the conditions under which csh
prints "You have mail." when a new shell is invoked.  I noticed that 
when I invoked a new shell with user=me from my login shell I didn't
get the message even though I had mail in the spool file, but when
I did the same su'ed to clay with user=clay I definitely did get the
message (he had mail in his spool file as well).  I found that the
following lines in checkmail() in csh.c were the reason:

     		if (stb.st_size == 0 || stb.st_atime > stb.st_mtime ||
		    (stb.st_atime < chktim && stb.st_mtime < chktim) ||
		    loginsh && !new)
			continue;

Specifically, the condition "stb.st_atime > stb.st_mtime" was succeeding
for me but failing for Clay even though both spool files hadn't been 
either accessed or updated in some time.  In my case, the spool file
is quite a bit larger than his which is possibly the reason why my
atime is always one second greater than my mtime, whereas his atime
and mtime are the same.

I could change the condition to "stb.st_atime > stb.st_mtime + 1", but that
looks like a kludge.  Does anyone have any strong feelings about how this
problem can be corrected?

Please submit responses to the net, since I think this is of general 
interest.

					Ben Goldfarb
					University of Central Florida
					uucp: {duke, decvax}!ucf-cs!goldfarb
					ARPA: goldfarb.ucf-cs at Rand-Relay



More information about the Comp.unix.wizards mailing list