w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit 0af2ab75fb33fefa45db46b9e20b40a2cb81a71e
parent 61c5cf116c5183ffb9c3923fd02987edfe85aae0
Author: ukai <ukai>
Date:   Tue, 18 Feb 2003 15:43:23 +0000

[w3m-dev 03758] Re: SVR4 signal behavior
* etc.c (reset_signals): use mySignal()
	(setup_child): ditto
	(myExec): ditto
	(mySignal): added, use sigaction if available
* fm.h (TRAP_ON): use mySignal
	(TRAP_OFF): ditto
* istream.c (ISclose): ditto
* main.c (sig_chld): ditto
	(main): ditto
	(do_dump): ditto
	(resize_hook): ditto
	(resize_handler): ditto
	(srchcore): ditto
	(readsh): ditto
	(SigAlarm): ditto
* proto.h (mySignal): added
* terms.c (error_dump): use mySignal()
	(set_int): ditto
	(mouse_init): ditto
From: Atsushi YOKOYAMA <yoko-a@cmh.fuchu.toshiba.co.jp>

Diffstat:
MChangeLog | 23+++++++++++++++++++++++
Metc.c | 47+++++++++++++++++++++++++++++++++++------------
Mfm.h | 4++--
Mistream.c | 4++--
Mmain.c | 38+++++++++++++++++++-------------------
Mproto.h | 1+
Mterms.c | 24++++++++++++------------
7 files changed, 94 insertions(+), 47 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,26 @@ +2003-02-19 Atsushi YOKOYAMA <yoko-a@cmh.fuchu.toshiba.co.jp> + + * [w3m-dev 03758] Re: SVR4 signal behavior + * etc.c (reset_signals): use mySignal() + (setup_child): ditto + (myExec): ditto + (mySignal): added, use sigaction if available + * fm.h (TRAP_ON): use mySignal + (TRAP_OFF): ditto + * istream.c (ISclose): ditto + * main.c (sig_chld): ditto + (main): ditto + (do_dump): ditto + (resize_hook): ditto + (resize_handler): ditto + (srchcore): ditto + (readsh): ditto + (SigAlarm): ditto + * proto.h (mySignal): added + * terms.c (error_dump): use mySignal() + (set_int): ditto + (mouse_init): ditto + 2003-02-19 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> * [w3m-dev 03753] Fixed multipart.cgi diff --git a/etc.c b/etc.c @@ -1335,21 +1335,21 @@ romanAlphabet(int n) static void reset_signals(void) { - signal(SIGHUP, SIG_DFL); /* terminate process */ - signal(SIGINT, SIG_DFL); /* terminate process */ - signal(SIGQUIT, SIG_DFL); /* terminate process */ - signal(SIGTERM, SIG_DFL); /* terminate process */ - signal(SIGILL, SIG_DFL); /* create core image */ - signal(SIGIOT, SIG_DFL); /* create core image */ - signal(SIGFPE, SIG_DFL); /* create core image */ + mySignal(SIGHUP, SIG_DFL); /* terminate process */ + mySignal(SIGINT, SIG_DFL); /* terminate process */ + mySignal(SIGQUIT, SIG_DFL); /* terminate process */ + mySignal(SIGTERM, SIG_DFL); /* terminate process */ + mySignal(SIGILL, SIG_DFL); /* create core image */ + mySignal(SIGIOT, SIG_DFL); /* create core image */ + mySignal(SIGFPE, SIG_DFL); /* create core image */ #ifdef SIGBUS - signal(SIGBUS, SIG_DFL); /* create core image */ + mySignal(SIGBUS, SIG_DFL); /* create core image */ #endif /* SIGBUS */ #ifdef SIGCHLD - signal(SIGCHLD, SIG_IGN); + mySignal(SIGCHLD, SIG_IGN); #endif #ifdef SIGPIPE - signal(SIGPIPE, SIG_IGN); + mySignal(SIGPIPE, SIG_IGN); #endif } @@ -1379,7 +1379,7 @@ void setup_child(int child, int i, int f) { reset_signals(); - signal(SIGINT, SIG_IGN); + mySignal(SIGINT, SIG_IGN); if (!child) SETPGRP(); close_tty(); @@ -1450,7 +1450,7 @@ open_pipe_rw(FILE ** fr, FILE ** fw) void myExec(char *command) { - signal(SIGINT, SIG_DFL); + mySignal(SIGINT, SIG_DFL); execl("/bin/sh", "sh", "-c", command, NULL); exit(127); } @@ -1973,3 +1973,26 @@ FQDN(char *host) } #endif /* USE_COOKIE */ + +void (*mySignal(int signal_number, void (*action)(int)))(int) +{ +#ifdef SA_RESTART + struct sigaction new_action, old_action; + + sigemptyset(&new_action.sa_mask); + new_action.sa_handler = action; + if (signal_number == SIGALRM) { +#ifdef SA_INTERRUPT + new_action.sa_flags = SA_INTERRUPT; +#else + new_action.sa_flags = 0; +#endif + } else { + new_action.sa_flags = SA_RESTART; + } + sigaction(signal_number, &new_action, &old_action); + return(old_action.sa_handler); +#else + return(signal(signal_number, action)); +#endif +} diff --git a/fm.h b/fm.h @@ -781,7 +781,7 @@ global char fmInitialized init(FALSE); global char QuietMessage init(FALSE); global char TrapSignal init(TRUE); #define TRAP_ON if (TrapSignal) { \ - prevtrap = signal(SIGINT, KeyAbort); \ + prevtrap = mySignal(SIGINT, KeyAbort); \ if (fmInitialized) \ term_cbreak(); \ } @@ -789,7 +789,7 @@ global char TrapSignal init(TRUE); if (fmInitialized) \ term_raw(); \ if (prevtrap) \ - signal(SIGINT, prevtrap); \ + mySignal(SIGINT, prevtrap); \ } extern unsigned char GlobalKeymap[]; diff --git a/istream.c b/istream.c @@ -183,9 +183,9 @@ ISclose(InputStream stream) if (stream == NULL || stream->base.close == NULL || stream->base.type & IST_UNCLOSE) return -1; - prevtrap = signal(SIGINT, SIG_IGN); + prevtrap = mySignal(SIGINT, SIG_IGN); stream->base.close(stream->base.handle); - signal(SIGINT, prevtrap); + mySignal(SIGINT, prevtrap); return 0; } diff --git a/main.c b/main.c @@ -317,7 +317,7 @@ sig_chld(int signo) #else wait(&p_stat); #endif - signal(SIGCHLD, sig_chld); + mySignal(SIGCHLD, sig_chld); return; } #endif @@ -730,7 +730,7 @@ main(int argc, char **argv, char **envp) if (!w3m_dump && !w3m_backend) { fmInit(); #ifdef SIGWINCH - signal(SIGWINCH, resize_hook); + mySignal(SIGWINCH, resize_hook); #else /* not SIGWINCH */ setlinescols(); setupscreen(); @@ -751,12 +751,12 @@ main(int argc, char **argv, char **envp) backend(); if (w3m_dump) - signal(SIGINT, SIG_IGN); + mySignal(SIGINT, SIG_IGN); #ifdef SIGCHLD - signal(SIGCHLD, sig_chld); + mySignal(SIGCHLD, sig_chld); #endif #ifdef SIGPIPE - signal(SIGPIPE, SigPipe); + mySignal(SIGPIPE, SigPipe); #endif orig_GC_warn_proc = GC_set_warn_proc(wrap_GC_warn_proc); @@ -1024,7 +1024,7 @@ main(int argc, char **argv, char **envp) #endif /* USE_MOUSE */ #ifdef USE_ALARM if (CurrentAlarm->sec > 0) { - signal(SIGALRM, SigAlarm); + mySignal(SIGALRM, SigAlarm); alarm(CurrentAlarm->sec); } #endif @@ -1033,7 +1033,7 @@ main(int argc, char **argv, char **envp) need_resize_screen = FALSE; resize_screen(); } - signal(SIGWINCH, resize_handler); + mySignal(SIGWINCH, resize_handler); #endif #ifdef USE_IMAGE if (activeImage && displayImage && Currentbuf->img && @@ -1045,7 +1045,7 @@ main(int argc, char **argv, char **envp) #endif c = getch(); #ifdef SIGWINCH - signal(SIGWINCH, resize_hook); + mySignal(SIGWINCH, resize_hook); #endif #ifdef USE_ALARM if (CurrentAlarm->sec > 0) { @@ -1163,9 +1163,9 @@ do_dump(Buffer *buf) { MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; - prevtrap = signal(SIGINT, intTrap); + prevtrap = mySignal(SIGINT, intTrap); if (SETJMP(IntReturn) != 0) { - signal(SIGINT, prevtrap); + mySignal(SIGINT, prevtrap); return; } if (w3m_dump & DUMP_EXTRA) @@ -1176,7 +1176,7 @@ do_dump(Buffer *buf) dump_source(buf); if (w3m_dump == DUMP_BUFFER) saveBuffer(buf, stdout, FALSE); - signal(SIGINT, prevtrap); + mySignal(SIGINT, prevtrap); } void @@ -1358,7 +1358,7 @@ static MySignalHandler resize_hook(SIGNAL_ARG) { need_resize_screen = TRUE; - signal(SIGWINCH, resize_hook); + mySignal(SIGWINCH, resize_hook); SIGNAL_RETURN; } @@ -1366,7 +1366,7 @@ static MySignalHandler resize_handler(SIGNAL_ARG) { resize_screen(); - signal(SIGWINCH, resize_handler); + mySignal(SIGWINCH, resize_handler); SIGNAL_RETURN; } @@ -1387,7 +1387,7 @@ SigPipe(SIGNAL_ARG) #ifdef USE_MIGEMO init_migemo(); #endif - signal(SIGPIPE, SigPipe); + mySignal(SIGPIPE, SigPipe); SIGNAL_RETURN; } #endif @@ -1564,7 +1564,7 @@ srchcore(char *str, int (*func) (Buffer *, char *)) if (SearchString == NULL || *SearchString == '\0') return SR_NOTFOUND; - prevtrap = signal(SIGINT, intTrap); + prevtrap = mySignal(SIGINT, intTrap); crmode(); if (SETJMP(IntReturn) == 0) { for (i = 0; i < PREC_NUM; i++) { @@ -1573,7 +1573,7 @@ srchcore(char *str, int (*func) (Buffer *, char *)) clear_mark(Currentbuf->currentLine); } } - signal(SIGINT, prevtrap); + mySignal(SIGINT, prevtrap); term_raw(); return result; } @@ -1973,10 +1973,10 @@ readsh(void) displayBuffer(Currentbuf, B_NORMAL); return; } - prevtrap = signal(SIGINT, intTrap); + prevtrap = mySignal(SIGINT, intTrap); crmode(); buf = getshell(cmd); - signal(SIGINT, prevtrap); + mySignal(SIGINT, prevtrap); term_raw(); if (buf == NULL) { disp_message("Execution failed", TRUE); @@ -5581,7 +5581,7 @@ SigAlarm(SIGNAL_ARG) if (!Currentbuf->event) CurrentAlarm = &DefaultAlarm; if (CurrentAlarm->sec > 0) { - signal(SIGALRM, SigAlarm); + mySignal(SIGALRM, SigAlarm); alarm(CurrentAlarm->sec); } } diff --git a/proto.h b/proto.h @@ -610,6 +610,7 @@ extern char *url_unquote_conv(char *url, char code); extern char *expandName(char *name); extern Str tmpfname(int type, char *ext); extern time_t mymktime(char *timestr); +extern void (*mySignal(int signal_number, void (*action)(int)))(int); #ifdef USE_COOKIE extern char *FQDN(char *host); extern Str find_cookie(ParsedURL *pu); diff --git a/terms.c b/terms.c @@ -603,7 +603,7 @@ reset_exit(SIGNAL_ARG) MySignalHandler error_dump(SIGNAL_ARG) { - signal(SIGIOT, SIG_DFL); + mySignal(SIGIOT, SIG_DFL); reset_tty(); abort(); SIGNAL_RETURN; @@ -612,17 +612,17 @@ error_dump(SIGNAL_ARG) void set_int(void) { - signal(SIGHUP, reset_exit); - signal(SIGINT, reset_exit); - signal(SIGQUIT, reset_exit); - signal(SIGTERM, reset_exit); - signal(SIGILL, error_dump); - signal(SIGIOT, error_dump); - signal(SIGFPE, error_dump); + mySignal(SIGHUP, reset_exit); + mySignal(SIGINT, reset_exit); + mySignal(SIGQUIT, reset_exit); + mySignal(SIGTERM, reset_exit); + mySignal(SIGILL, error_dump); + mySignal(SIGIOT, error_dump); + mySignal(SIGFPE, error_dump); #ifdef SIGBUS - signal(SIGBUS, error_dump); + mySignal(SIGBUS, error_dump); #endif /* SIGBUS */ - /* signal(SIGSEGV, error_dump); */ + /* mySignal(SIGSEGV, error_dump); */ } @@ -2082,13 +2082,13 @@ mouse_init() } #endif /* defined(FBIO_MODEINFO) || * defined(CONS_MODEINFO) */ - signal(SIGUSR2, SIG_IGN); + mySignal(SIGUSR2, SIG_IGN); mi.operation = MOUSE_MODE; mi.u.mode.mode = 0; mi.u.mode.signal = SIGUSR2; sysm_handler = NULL; if (ioctl(tty, CONS_MOUSECTL, &mi) != -1) { - signal(SIGUSR2, sysmouse); + mySignal(SIGUSR2, sysmouse); mi.operation = MOUSE_SHOW; ioctl(tty, CONS_MOUSECTL, &mi); sysm_handler = sysm_process_mouse;