summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1999-02-11 19:55:30 +0000
committerThomas Roessler <roessler@does-not-exist.org>1999-02-11 19:55:30 +0000
commit4ed9d6a028a022c4574090f0a3e986f1bf4930b6 (patch)
tree29fb397b714798a1b4c657b38f9e16b2199a933c
parentc11e9101fc920c907693e3dab00bc9cb43f471a0 (diff)
patch.mutt-0.95.1i.ld.signals.1-2.gz
-rw-r--r--curs_lib.c6
-rw-r--r--curs_main.c4
-rw-r--r--globals.h7
-rw-r--r--menu.c4
-rw-r--r--mutt.h5
-rw-r--r--pager.c6
-rw-r--r--pattern.c4
-rw-r--r--sendlib.c56
-rw-r--r--signal.c44
9 files changed, 62 insertions, 74 deletions
diff --git a/curs_lib.c b/curs_lib.c
index a35d4a55..edbe46d2 100644
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -53,7 +53,7 @@ event_t mutt_getch (void)
if (UngetCount)
return (KeyEvent[--UngetCount]);
- Signals &= ~S_INTERRUPT;
+ SigInt = 0;
#ifdef KEY_RESIZE
/* ncurses 4.2 sends this when the screen is resized */
@@ -62,7 +62,7 @@ event_t mutt_getch (void)
#endif /* KEY_RESIZE */
ch = getch ();
- if (Signals & S_INTERRUPT)
+ if (SigInt)
mutt_query_exit ();
if(ch == ERR)
@@ -180,7 +180,7 @@ void mutt_query_exit (void)
}
mutt_clear_error();
mutt_curs_set (-1);
- Signals &= ~S_INTERRUPT;
+ SigInt = 0;
}
static void clean_error_buf(void)
diff --git a/curs_main.c b/curs_main.c
index 4ea66b6c..3f9e46c0 100644
--- a/curs_main.c
+++ b/curs_main.c
@@ -502,13 +502,13 @@ int mutt_index_menu (void)
mutt_curs_set (1);
#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
- if (Signals & S_SIGWINCH)
+ if (SigWinch)
{
mutt_flushinp ();
mutt_resize_screen ();
menu->redraw = REDRAW_FULL;
menu->menu = MENU_MAIN;
- Signals &= ~S_SIGWINCH;
+ SigWinch = 0;
menu->top = 0; /* so we scroll the right amount */
continue;
}
diff --git a/globals.h b/globals.h
index 836768db..e035a941 100644
--- a/globals.h
+++ b/globals.h
@@ -117,9 +117,10 @@ WHERE short SendmailWait;
WHERE short Timeout;
WHERE short WriteInc;
-/* vector to store received signals */
-/* hopefully it's an integer type... */
-WHERE volatile sig_atomic_t Signals INITVAL (0);
+/* flags for received signals */
+WHERE volatile sig_atomic_t SigAlrm INITVAL (0);
+WHERE volatile sig_atomic_t SigInt INITVAL (0);
+WHERE volatile sig_atomic_t SigWinch INITVAL (0);
WHERE int CurrentMenu;
diff --git a/menu.c b/menu.c
index 3a983357..8a6f6fe8 100644
--- a/menu.c
+++ b/menu.c
@@ -713,11 +713,11 @@ int mutt_menuLoop (MUTTMENU *menu)
mutt_curs_set (1);
#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
- if (Signals & S_SIGWINCH)
+ if (SigWinch)
{
mutt_resize_screen ();
menu->redraw = REDRAW_FULL;
- Signals &= ~S_SIGWINCH;
+ SigWinch = 0;
}
#endif
diff --git a/mutt.h b/mutt.h
index c1f0ddf4..5d2b1cab 100644
--- a/mutt.h
+++ b/mutt.h
@@ -405,11 +405,6 @@ enum
#define toggle_option(x) mutt_bit_toggle(Options,x)
#define option(x) mutt_bit_isset(Options,x)
-/* Bit fields for ``Signals'' */
-#define S_INTERRUPT (1<<0)
-#define S_SIGWINCH (1<<1)
-#define S_ALARM (1<<2)
-
/* Exit values used in send_msg() */
#define S_ERR 127
#define S_BKG 126
diff --git a/pager.c b/pager.c
index 60527803..06805195 100644
--- a/pager.c
+++ b/pager.c
@@ -1659,13 +1659,13 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
mutt_clear_error ();
mutt_curs_set (1);
- if (Signals & S_INTERRUPT)
+ if (SigInt)
{
mutt_query_exit ();
continue;
}
#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
- else if (Signals & S_SIGWINCH)
+ else if (SigWinch)
{
mutt_resize_screen ();
@@ -1710,7 +1710,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
ch = 0;
}
- Signals &= ~S_SIGWINCH;
+ SigWinch = 0;
continue;
}
#endif
diff --git a/pattern.c b/pattern.c
index 0103f557..5556a485 100644
--- a/pattern.c
+++ b/pattern.c
@@ -1140,10 +1140,10 @@ int mutt_search_command (int cur, int op)
return i;
}
- if (Signals & S_INTERRUPT)
+ if (SigInt)
{
mutt_error _("Search interrupted.");
- Signals &= ~S_INTERRUPT;
+ SigInt;
return (-1);
}
diff --git a/sendlib.c b/sendlib.c
index 533cf0eb..0d722c47 100644
--- a/sendlib.c
+++ b/sendlib.c
@@ -50,31 +50,31 @@ static struct sysexits
sysexits_h[] =
{
#ifdef EX_USAGE
- { 0xff & EX_USAGE, "The command was used incorrectly." },
+ { 0xff & EX_USAGE, "Bad usage." },
#endif
#ifdef EX_DATAERR
- { 0xff & EX_DATAERR, "The input data was incorrect." },
+ { 0xff & EX_DATAERR, "Data format error." },
#endif
#ifdef EX_NOINPUT
- { 0xff & EX_NOINPUT, "No input." },
+ { 0xff & EX_NOINPUT, "Cannot open input." },
#endif
#ifdef EX_NOUSER
- { 0xff & EX_NOUSER, "No such user." },
+ { 0xff & EX_NOUSER, "User unknown." },
#endif
#ifdef EX_NOHOST
- { 0xff & EX_NOHOST, "Host not found." },
+ { 0xff & EX_NOHOST, "Host unknown." },
#endif
#ifdef EX_UNAVAILABLE
{ 0xff & EX_UNAVAILABLE, "Service unavailable." },
#endif
#ifdef EX_SOFTWARE
- { 0xff & EX_SOFTWARE, "Software error." },
+ { 0xff & EX_SOFTWARE, "Internal error." },
#endif
#ifdef EX_OSERR
{ 0xff & EX_OSERR, "Operating system error." },
#endif
#ifdef EX_OSFILE
- { 0xff & EX_OSFILE, "System file is missing." },
+ { 0xff & EX_OSFILE, "System file missing." },
#endif
#ifdef EX_CANTCREAT
{ 0xff & EX_CANTCREAT, "Can't create output." },
@@ -83,13 +83,16 @@ sysexits_h[] =
{ 0xff & EX_IOERR, "I/O error." },
#endif
#ifdef EX_TEMPFAIL
- { 0xff & EX_TEMPFAIL, "Temporary failure." },
+ { 0xff & EX_TEMPFAIL, "Deferred." },
#endif
#ifdef EX_PROTOCOL
- { 0xff & EX_PROTOCOL, "Protocol error." },
+ { 0xff & EX_PROTOCOL, "Remote protocol error." },
#endif
#ifdef EX_NOPERM
- { 0xff & EX_NOPERM, "Permission denied." },
+ { 0xff & EX_NOPERM, "Insufficient permission." },
+#endif
+#ifdef EX_CONFIG
+ { 0xff & EX_NOPERM, "Local configuration error." },
#endif
{ S_ERR, "Exec error." },
{ -1, NULL}
@@ -1418,7 +1421,7 @@ char *mutt_gen_msgid (void)
static RETSIGTYPE alarm_handler (int sig)
{
- Signals |= S_ALARM;
+ SigAlrm = 1;
}
/* invoke sendmail in a subshell
@@ -1433,7 +1436,7 @@ send_msg (const char *path, char **args, const char *msg, char **tempfile)
{
sigset_t set;
int fd, st;
- pid_t pid;
+ pid_t pid, ppid;
mutt_block_signals_system ();
@@ -1454,6 +1457,9 @@ send_msg (const char *path, char **args, const char *msg, char **tempfile)
{
struct sigaction act, oldalrm;
+ /* save parent's ID before setsid() */
+ ppid = getppid ();
+
/* we want the delivery to continue even after the main process dies,
* so we put ourselves into another session right away
*/
@@ -1487,10 +1493,10 @@ send_msg (const char *path, char **args, const char *msg, char **tempfile)
{
/* *tempfile will be opened as stdout */
if (open (*tempfile, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0600) < 0)
- _exit (errno);
+ _exit (S_ERR);
/* redirect stderr to *tempfile too */
if (dup (1) < 0)
- _exit (errno);
+ _exit (S_ERR);
}
execv (path, args);
@@ -1509,7 +1515,7 @@ send_msg (const char *path, char **args, const char *msg, char **tempfile)
*/
if (SendmailWait > 0)
{
- Signals &= ~S_ALARM;
+ SigAlrm = 0;
act.sa_handler = alarm_handler;
#ifdef SA_INTERRUPT
/* need to make sure waitpid() is interrupted on SIGALRM */
@@ -1518,11 +1524,6 @@ send_msg (const char *path, char **args, const char *msg, char **tempfile)
act.sa_flags = 0;
#endif
sigemptyset (&act.sa_mask);
- sigaddset (&act.sa_mask, SIGTSTP);
- sigaddset (&act.sa_mask, SIGINT);
-#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
- sigaddset (&act.sa_mask, SIGWINCH);
-#endif
sigaction (SIGALRM, &act, &oldalrm);
alarm (SendmailWait);
}
@@ -1540,7 +1541,7 @@ send_msg (const char *path, char **args, const char *msg, char **tempfile)
}
else
{
- st = (SendmailWait > 0 && errno == EINTR && (Signals & S_ALARM)) ?
+ st = (SendmailWait > 0 && errno == EINTR && SigAlrm) ?
S_BKG : S_ERR;
if (SendmailWait > 0)
{
@@ -1552,7 +1553,14 @@ send_msg (const char *path, char **args, const char *msg, char **tempfile)
/* reset alarm; not really needed, but... */
alarm (0);
sigaction (SIGALRM, &oldalrm, NULL);
-
+
+ if (kill (ppid, 0) == -1 && errno == ESRCH)
+ {
+ /* the parent is already dead */
+ unlink (*tempfile);
+ safe_free ((void **) tempfile);
+ }
+
_exit (st);
}
@@ -1664,9 +1672,7 @@ mutt_invoke_sendmail (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc, /* recips */
if ((i = send_msg (path, args, msg, &childout)) != (EX_OK & 0xff))
{
- if (i == S_BKG)
- mutt_message (_("Delivery continued in background."));
- else
+ if (i != S_BKG)
{
const char *e = strsysexit (i);
diff --git a/signal.c b/signal.c
index 73996313..ab82e43f 100644
--- a/signal.c
+++ b/signal.c
@@ -26,6 +26,8 @@
static sigset_t Sigset;
static sigset_t SigsetSys;
+static struct sigaction SysOldInt;
+static struct sigaction SysOldQuit;
static int IsEndwin = 0;
/* Attempt to catch "ordinary" signals and shut down gracefully. */
@@ -73,12 +75,12 @@ RETSIGTYPE sighandler (int sig)
#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
case SIGWINCH:
- Signals |= S_SIGWINCH;
+ SigWinch = 1;
break;
#endif
case SIGINT:
- Signals |= S_INTERRUPT;
+ SigInt = 1;
break;
}
@@ -108,10 +110,6 @@ void mutt_signal_init (void)
/* we want to avoid race conditions */
sigaddset (&act.sa_mask, SIGTSTP);
- sigaddset (&act.sa_mask, SIGINT);
-#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
- sigaddset (&act.sa_mask, SIGWINCH);
-#endif
/* we also don't want to mess with interrupted system calls */
#ifdef SA_RESTART
@@ -185,50 +183,38 @@ void mutt_block_signals_system (void)
/* POSIX: ignore SIGINT and SIGQUIT & block SIGCHLD before exec */
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
- sigaction (SIGINT, &sa, NULL);
- sigaction (SIGQUIT, &sa, NULL);
+ sigemptyset (&sa.sa_mask);
+ sigaction (SIGINT, &sa, &SysOldInt);
+ sigaction (SIGQUIT, &sa, &SysOldQuit);
sigemptyset (&SigsetSys);
sigaddset (&SigsetSys, SIGCHLD);
sigprocmask (SIG_BLOCK, &SigsetSys, 0);
- set_option (OPTSIGNALSBLOCKED);
+ set_option (OPTSYSSIGNALSBLOCKED);
}
}
void mutt_unblock_signals_system (int catch)
{
- struct sigaction sa;
-
if (option (OPTSYSSIGNALSBLOCKED))
{
sigprocmask (SIG_UNBLOCK, &SigsetSys, NULL);
- sigemptyset (&sa.sa_mask);
- sa.sa_flags = 0;
if (catch)
{
- sa.sa_handler = exit_handler;
- sigaction (SIGQUIT, &sa, NULL);
-
- /* we want to avoid race conditions */
- sigaddset (&sa.sa_mask, SIGTSTP);
- sigaddset (&sa.sa_mask, SIGINT);
-#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
- sigaddset (&sa.sa_mask, SIGWINCH);
-#endif
- /* we also don't want to mess with interrupted system calls */
-#ifdef SA_RESTART
- sa.sa_flags = SA_RESTART;
-#endif
- sa.sa_handler = sighandler;
- sigaction (SIGINT, &sa, NULL);
+ sigaction (SIGQUIT, &SysOldQuit, NULL);
+ sigaction (SIGINT, &SysOldInt, NULL);
}
else
{
+ struct sigaction sa;
+
sa.sa_handler = SIG_DFL;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
sigaction (SIGQUIT, &sa, NULL);
sigaction (SIGINT, &sa, NULL);
}
- unset_option (OPTSIGNALSBLOCKED);
+ unset_option (OPTSYSSIGNALSBLOCKED);
}
}