diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-06-07 03:35:20 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-06-07 03:35:20 +0000 |
commit | 912020678b6f45f900b66e637e5848d9fa3b92b7 (patch) | |
tree | fed315ea71f42adc5b7f91b77e54ce06be52220c /usr.bin/less/os.c | |
parent | ca740922f63b8d6806ffacd67092fc0f20e90976 (diff) |
Use interruptible syscalls instead of setjmp/longjmp. This makes
less's signal handlers safe. No one has reported problems so far...
Diffstat (limited to 'usr.bin/less/os.c')
-rw-r--r-- | usr.bin/less/os.c | 58 |
1 files changed, 1 insertions, 57 deletions
diff --git a/usr.bin/less/os.c b/usr.bin/less/os.c index ac63960df95..c5343a043a8 100644 --- a/usr.bin/less/os.c +++ b/usr.bin/less/os.c @@ -23,7 +23,6 @@ #include "less.h" #include <signal.h> -#include <setjmp.h> #if HAVE_TIME_H #include <time.h> #endif @@ -40,31 +39,10 @@ #define time_type long #endif -/* - * BSD setjmp() saves (and longjmp() restores) the signal mask. - * This costs a system call or two per setjmp(), so if possible we clear the - * signal mask with sigsetmask(), and use _setjmp()/_longjmp() instead. - * On other systems, setjmp() doesn't affect the signal mask and so - * _setjmp() does not exist; we just use setjmp(). - */ -#if HAVE__SETJMP && HAVE_SIGSETMASK -#define SET_JUMP _setjmp -#define LONG_JUMP _longjmp -#else -#define SET_JUMP setjmp -#define LONG_JUMP longjmp -#endif - -public int reading; - -static jmp_buf read_label; - extern int sigs; /* * Like read() system call, but is deliberately interruptible. - * A call to intread() from a signal handler will interrupt - * any pending iread(). */ public int iread(fd, buf, len) @@ -90,32 +68,8 @@ iread(fd, buf, len) } #endif #endif - if (SET_JUMP(read_label)) - { - /* - * We jumped here from intread. - */ - reading = 0; -#if HAVE_SIGPROCMASK - { - sigset_t mask; - sigemptyset(&mask); - sigprocmask(SIG_SETMASK, &mask, NULL); - } -#else -#if HAVE_SIGSETMASK - sigsetmask(0); -#else -#ifdef _OSK - sigmask(~0); -#endif -#endif -#endif - return (READ_INTR); - } flush(); - reading = 1; #if MSDOS_COMPILER==DJGPPC if (isatty(fd)) { @@ -154,22 +108,12 @@ iread(fd, buf, len) } } #endif - reading = 0; if (n < 0) - return (-1); + return (errno == EINTR ? READ_INTR : -1); return (n); } /* - * Interrupt a pending iread(). - */ - public void -intread() -{ - LONG_JUMP(read_label, 1); -} - -/* * Return the current time. */ #if HAVE_TIME |