Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: notesfiles Path: utzoo!linus!decvax!tektronix!hplabs!hp-pcd!hp-dcd!hpfcls!rml From: rml@hpfcls.UUCP (rml) Newsgroups: net.unix-wizards Subject: Re: The errno variable can get trashed Message-ID: <132000007@hpfcls.UUCP> Date: Tue, 14-Aug-84 18:50:00 EDT Article-I.D.: hpfcls.132000007 Posted: Tue Aug 14 18:50:00 1984 Date-Received: Fri, 10-Aug-84 08:08:21 EDT References: <511@calgary.UUCP> Organization: Hewlett-Packard - Fort Collins, CO Lines: 40 Nf-ID: #R:calgary:-51100:hpfcls:132000007:000:1569 Nf-From: hpfcls!rml Aug 6 14:50:00 1984 > The solution would seem to be to have the C signal handling mechanism > save errno before calling the signal routine and restore it after > the routine has returned. This is impossible with the standard implementation of the system call interface and errno. Errno is is an arbitrary location in the user's address space which is unknown to the kernel. That's why the kernel passes the errno value back in a register and an assembly language library routine copies the value to the global variable. If this problem is a concern for you, you can simulate your suggested solution in your own signal handler: void i() { int save_errno; extern int errno; save_errno = errno; signal(SIGALRM,i); alarm(1); open(".",1); /* Fails, since is a directory */ errno = save_errno; } > Is the fact that this bug has been present for upwards of ten years > in all versions of Unix, apparently without anyone noticing, an > indication of how often Unix programmers check for errors? The fact that you can cause this behavior about once a minute with a contrived example does not indicate that this is a serious problem. Admittedly, many programs running on UNIX* systems (including a number of commands shipped with UNIX systems) are lax about checking for errors in system calls or about reporting the reason for the error when they do check. However, the fact that a simple workaround exists for those programmers who are concerned is a point in favor of UNIX systems. Bob Lenk {hplabs, ihnp4}!hpfcla!rml *UNIX is a trademark of AT&T Bell Laboratories