if (!ctx->quiet)
mutt_message(progress, ctx->realpath);
- mutt_block_signals();
+ mutt_sig_block();
endwin();
fflush(stdout);
mutt_error(_("Error running \"%s\"!"), sys_cmd);
}
- mutt_unblock_signals();
+ mutt_sig_unblock();
return rc;
}
if (ConnectTimeout > 0)
alarm(ConnectTimeout);
- mutt_allow_interrupt(1);
+ mutt_sig_allow_interrupt(1);
/* FreeBSD's connect() does not respect SA_RESTART, meaning
* a SIGWINCH will cause the connect to fail. */
if (ConnectTimeout > 0)
alarm(0);
- mutt_allow_interrupt(0);
+ mutt_sig_allow_interrupt(0);
sigprocmask(SIG_UNBLOCK, &set, NULL);
return save_errno;
{
int rc;
- mutt_allow_interrupt(1);
+ mutt_sig_allow_interrupt(1);
rc = read(conn->fd, buf, len);
if (rc == -1)
{
mutt_sleep(2);
SigInt = 0;
}
- mutt_allow_interrupt(0);
+ mutt_sig_allow_interrupt(0);
if (SigInt)
{
{
int rc;
- mutt_allow_interrupt(1);
+ mutt_sig_allow_interrupt(1);
rc = write(conn->fd, buf, count);
if (rc == -1)
{
mutt_sleep(2);
SigInt = 0;
}
- mutt_allow_interrupt(0);
+ mutt_sig_allow_interrupt(0);
if (SigInt)
{
return -1;
}
- mutt_block_signals_system();
+ mutt_sig_block_system();
pid = fork();
if (pid == 0)
{
- mutt_unblock_signals_system(0);
+ mutt_sig_unblock_system(0);
devnull = open("/dev/null", O_RDWR);
if (devnull < 0 || dup2(pout[0], STDIN_FILENO) < 0 ||
dup2(pin[1], STDOUT_FILENO) < 0 || dup2(devnull, STDERR_FILENO) < 0)
execle(EXECSHELL, "sh", "-c", Tunnel, NULL, mutt_envlist());
_exit(127);
}
- mutt_unblock_signals_system(1);
+ mutt_sig_unblock_system(1);
if (pid == -1)
{
SigInt = 0;
- mutt_allow_interrupt(1);
+ mutt_sig_allow_interrupt(1);
#ifdef KEY_RESIZE
/* ncurses 4.2 sends this when the screen is resized */
ch = KEY_RESIZE;
while (ch == KEY_RESIZE)
#endif /* KEY_RESIZE */
ch = getch();
- mutt_allow_interrupt(0);
+ mutt_sig_allow_interrupt(0);
if (SigInt)
{
}
}
- mutt_block_signals_system();
+ mutt_sig_block_system();
thepid = fork();
if (thepid == 0)
{
- mutt_unblock_signals_system(0);
+ mutt_sig_unblock_system(0);
if (in)
{
}
else if (thepid == -1)
{
- mutt_unblock_signals_system(1);
+ mutt_sig_unblock_system(1);
if (in)
{
int rc;
waitpid(pid, &rc, 0);
- mutt_unblock_signals_system(1);
+ mutt_sig_unblock_system(1);
rc = WIFEXITED(rc) ? WEXITSTATUS(rc) : -1;
return rc;
}
/* Allow interruptions, particularly useful if there are network problems. */
- mutt_allow_interrupt(1);
+ mutt_sig_allow_interrupt(1);
do
rc = imap_cmd_step(idata);
while (rc == IMAP_CMD_CONTINUE);
- mutt_allow_interrupt(0);
+ mutt_sig_allow_interrupt(0);
if (rc == IMAP_CMD_NO && (flags & IMAP_CMD_FAIL_OK))
return -2;
sigprocmask(SIG_SETMASK, NULL, &oldmask);
sigemptyset(&act.sa_mask);
- act.sa_handler = empty_signal_handler;
+ act.sa_handler = mutt_sig_empty_handler;
#ifdef SA_INTERRUPT
act.sa_flags = SA_INTERRUPT;
#else
mutt_perror(ctx->path);
return -1;
}
- mutt_block_signals();
+ mutt_sig_block();
if (mbox_lock_mailbox(ctx, 0, 1) == -1)
{
- mutt_unblock_signals();
+ mutt_sig_unblock();
return -1;
}
mutt_file_touch_atime(fileno(ctx->fp));
mbox_unlock_mailbox(ctx);
- mutt_unblock_signals();
+ mutt_sig_unblock();
return rc;
}
if (ctx->append)
{
mutt_file_unlock(ctx->path, fileno(ctx->fp));
- mutt_unblock_signals();
+ mutt_sig_unblock();
}
mutt_file_fclose(&ctx->fp);
/* lock the file if it isn't already */
if (!ctx->locked)
{
- mutt_block_signals();
+ mutt_sig_block();
if (mbox_lock_mailbox(ctx, 0, 0) == -1)
{
- mutt_unblock_signals();
+ mutt_sig_unblock();
/* we couldn't lock the mailbox, but nothing serious happened:
* probably the new mail arrived: no reason to wait till we can
* parse it: we'll get it on the next pass
if (unlock)
{
mbox_unlock_mailbox(ctx);
- mutt_unblock_signals();
+ mutt_sig_unblock();
}
return MUTT_NEW_MAIL; /* signal that new mail arrived */
if (unlock)
{
mbox_unlock_mailbox(ctx);
- mutt_unblock_signals();
+ mutt_sig_unblock();
}
return MUTT_REOPENED;
}
mbox_unlock_mailbox(ctx);
mx_fastclose_mailbox(ctx);
- mutt_unblock_signals();
+ mutt_sig_unblock();
mutt_error(_("Mailbox was corrupted!"));
return -1;
}
return -1;
}
- mutt_block_signals();
+ mutt_sig_block();
if (mbox_lock_mailbox(ctx, 1, 1) == -1)
{
- mutt_unblock_signals();
+ mutt_sig_unblock();
mutt_error(_("Unable to lock mailbox!"));
goto bail;
}
fp = fopen(tempfile, "r");
if (!fp)
{
- mutt_unblock_signals();
+ mutt_sig_unblock();
mx_fastclose_mailbox(ctx);
mutt_debug(1, "unable to reopen temp copy of mailbox!\n");
mutt_perror(tempfile);
snprintf(savefile, sizeof(savefile), "%s/mutt.%s-%s-%u", NONULL(Tmpdir),
NONULL(Username), NONULL(ShortHostname), (unsigned int) getpid());
rename(tempfile, savefile);
- mutt_unblock_signals();
+ mutt_sig_unblock();
mx_fastclose_mailbox(ctx);
mutt_pretty_mailbox(savefile, sizeof(savefile));
mutt_error(_("Write failed! Saved partial mailbox to %s"), savefile);
if (!ctx->fp)
{
unlink(tempfile);
- mutt_unblock_signals();
+ mutt_sig_unblock();
mx_fastclose_mailbox(ctx);
mutt_error(_("Fatal error! Could not reopen mailbox!"));
FREE(&newOffset);
FREE(&newOffset);
FREE(&oldOffset);
unlink(tempfile); /* remove partial copy of the mailbox */
- mutt_unblock_signals();
+ mutt_sig_unblock();
if (option(OPT_CHECK_MBOX_SIZE))
{
/* this is ok to call even if we haven't locked anything */
mbox_unlock_mailbox(ctx);
- mutt_unblock_signals();
+ mutt_sig_unblock();
FREE(&newOffset);
FREE(&oldOffset);
*
* Signal handling
*
- * | Function | Description
- * | :---------------------------- | :---------------------------------------------------------
- * | default_exit_handler | Notify the user and shutdown gracefully
- * | empty_signal_handler | Dummy signal handler
- * | mutt_allow_interrupt | Allow/disallow Ctrl-C (SIGINT)
- * | mutt_block_signals | Block signals during critical operations
- * | mutt_block_signals_system | Block signals before calling exec()
- * | mutt_sig_init | Initialise the signal handling
- * | mutt_unblock_signals | Restore previously blocked signals
- * | mutt_unblock_signals_system | Restore previously blocked signals
+ * | Function | Description
+ * | :------------------------- | :---------------------------------------------------------
+ * | mutt_sig_exit_handler() | Notify the user and shutdown gracefully
+ * | mutt_sig_empty_handler() | Dummy signal handler
+ * | mutt_sig_allow_interrupt() | Allow/disallow Ctrl-C (SIGINT)
+ * | mutt_sig_block() | Block signals during critical operations
+ * | mutt_sig_block_system() | Block signals before calling exec()
+ * | mutt_sig_init() | Initialise the signal handling
+ * | mutt_sig_unblock() | Restore previously blocked signals
+ * | mutt_sig_unblock_system() | Restore previously blocked signals
*/
#include "config.h"
static bool SignalsBlocked;
static bool SysSignalsBlocked;
-static sig_handler_t sig_handler = empty_signal_handler;
-static sig_handler_t exit_handler = default_exit_handler;
+static sig_handler_t sig_handler = mutt_sig_empty_handler;
+static sig_handler_t exit_handler = mutt_sig_exit_handler;
/**
- * empty_signal_handler - Dummy signal handler
+ * mutt_sig_empty_handler - Dummy signal handler
* @param sig Signal number, e.g. SIGINT
*
* Useful for signals that we can't ignore,
* or don't want to do anything with.
*/
-void empty_signal_handler(int sig)
+void mutt_sig_empty_handler(int sig)
{
mutt_debug(2, "Received signal %d\n", sig);
}
/**
- * default_exit_handler - Notify the user and shutdown gracefully
+ * mutt_sig_exit_handler - Notify the user and shutdown gracefully
* @param sig Signal number, e.g. SIGINT
*/
-void default_exit_handler(int sig)
+void mutt_sig_exit_handler(int sig)
{
#if HAVE_DECL_SYS_SIGLIST
printf(_("%s... Exiting.\n"), sys_siglist[sig]);
/* POSIX doesn't allow us to ignore SIGCHLD,
* so we just install a dummy handler for it */
- act.sa_handler = empty_signal_handler;
+ act.sa_handler = mutt_sig_empty_handler;
/* don't need to block any other signals here */
sigemptyset(&act.sa_mask);
/* we don't want to mess with stopped children */
}
/**
- * mutt_block_signals - Block signals during critical operations
+ * mutt_sig_block - Block signals during critical operations
*
* It's important that certain signals don't interfere with critical operations.
- * Call mutt_unblock_signals() to restore the signals' behaviour.
+ * Call mutt_sig_unblock() to restore the signals' behaviour.
*/
-void mutt_block_signals(void)
+void mutt_sig_block(void)
{
if (SignalsBlocked)
return;
}
/**
- * mutt_unblock_signals - Restore previously blocked signals
+ * mutt_sig_unblock - Restore previously blocked signals
*/
-void mutt_unblock_signals(void)
+void mutt_sig_unblock(void)
{
if (!SignalsBlocked)
return;
}
/**
- * mutt_block_signals_system - Block signals before calling exec()
+ * mutt_sig_block_system - Block signals before calling exec()
*
* It's important that certain signals don't interfere with the child process.
- * Call mutt_unblock_signals_system() to restore the signals' behaviour.
+ * Call mutt_sig_unblock_system() to restore the signals' behaviour.
*/
-void mutt_block_signals_system(void)
+void mutt_sig_block_system(void)
{
if (SysSignalsBlocked)
return;
}
/**
- * mutt_unblock_signals_system - Restore previously blocked signals
+ * mutt_sig_unblock_system - Restore previously blocked signals
* @param catch If true, restore previous SIGINT, SIGQUIT behaviour
*/
-void mutt_unblock_signals_system(int catch)
+void mutt_sig_unblock_system(int catch)
{
if (!SysSignalsBlocked)
return;
}
/**
- * mutt_allow_interrupt - Allow/disallow Ctrl-C (SIGINT)
+ * mutt_sig_allow_interrupt - Allow/disallow Ctrl-C (SIGINT)
* @param disposition True to allow Ctrl-C to interrupt signals
*
* Allow the user to interrupt some long operations.
*/
-void mutt_allow_interrupt(int disposition)
+void mutt_sig_allow_interrupt(int disposition)
{
struct sigaction sa;
typedef void (*sig_handler_t)(int sig);
-void mutt_block_signals(void);
-void mutt_unblock_signals(void);
-void mutt_block_signals_system(void);
-void mutt_unblock_signals_system(int catch);
-void default_exit_handler(int sig);
-void empty_signal_handler(int sig);
void mutt_sig_init(sig_handler_t sig_fn, sig_handler_t exit_fn);
-void mutt_allow_interrupt(int disposition);
+void mutt_sig_exit_handler(int sig);
+void mutt_sig_empty_handler(int sig);
+
+void mutt_sig_block(void);
+void mutt_sig_unblock(void);
+void mutt_sig_block_system(void);
+void mutt_sig_unblock_system(int catch);
+void mutt_sig_allow_interrupt(int disposition);
#endif /* _MUTT_SIGNAL_H */
void mutt_add_to_reference_headers(struct Envelope *env, struct Envelope *curenv);
void mutt_adv_mktemp(char *s, size_t l);
void mutt_alias_menu(char *buf, size_t buflen, struct Alias *aliases);
-void mutt_allow_interrupt(int disposition);
+void mutt_sig_allow_interrupt(int disposition);
int mutt_body_handler(struct Body *b, struct State *s);
int mutt_bounce_message(FILE *fp, struct Header *h, struct Address *to);
void mutt_buffy(char *s, size_t slen);
else
fc = fgetconv_open(fpin, 0, 0, 0);
- mutt_allow_interrupt(1);
+ mutt_sig_allow_interrupt(1);
if (a->encoding == ENCQUOTEDPRINTABLE)
encode_quoted(fc, f, write_as_text_part(a));
else if (a->encoding == ENCBASE64)
encode_8bit(fc, f, write_as_text_part(a));
else
mutt_file_copy_stream(fpin, f);
- mutt_allow_interrupt(0);
+ mutt_sig_allow_interrupt(0);
fgetconv_close(&fc);
mutt_file_fclose(&fpin);
int fd, st;
pid_t pid, ppid;
- mutt_block_signals_system();
+ mutt_sig_block_system();
sigemptyset(&set);
/* we also don't want to be stopped right now */
else
st = S_ERR; /* error */
- mutt_unblock_signals_system(1);
+ mutt_sig_unblock_system(1);
return st;
}
/* must ignore SIGINT and SIGQUIT */
- mutt_block_signals_system();
+ mutt_sig_block_system();
act.sa_handler = SIG_DFL;
/* we want to restart the waitpid() below */
act.sa_flags = 0;
/* reset signals for the child; not really needed, but... */
- mutt_unblock_signals_system(0);
+ mutt_sig_unblock_system(0);
act.sa_handler = SIG_DFL;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGTSTP, &oldtstp, NULL);
/* reset SIGINT, SIGQUIT and SIGCHLD */
- mutt_unblock_signals_system(1);
+ mutt_sig_unblock_system(1);
rc = (thepid != -1) ? (WIFEXITED(rc) ? WEXITSTATUS(rc) : -1) : -1;