Commit 3adbdf31 3adbdf31b646b6b6f804a5c54c19852d770ab120 by Alain Magloire

The reason the interrupt code did not work for me, is that

	by default using signal will make function calls restartable,
	at least on my default RH5.1, when read() was interrupted
	it did not return EINTR inside ml_getc().

	* mail.c (main): Use sigaction if available to set SIGPIPE.
	* mailline.c (sig_handler): Reset "lines" variable.
	Recall signal() if we did not have sigaction.
	(ml_readline_init):  Use sigaction to set SIGWINCH and SIGINT.
1 parent 907ec6bf
......@@ -188,7 +188,17 @@ main (int argc, char **argv)
}
interactive = isatty (fileno(stdin));
#ifdef HAVE_SIGACTION
{
struct sigaction act;
act.sa_handler = SIG_IGN;
sigemptyset (&act.sa_mask);
act.sa_flags = 0;
sigaction (SIGPIPE, &act, NULL);
}
#else
signal (SIGPIPE, SIG_IGN);
#endif
/* set up the default environment */
if (!getenv ("HOME"))
......
......@@ -34,10 +34,13 @@ sig_handler (int signo)
break;
#if defined (SIGWINCH)
case SIGWINCH:
util_do_command ("set screen=%d", util_getlines());
break;
#endif
}
#ifndef HAVE_SIGACTION
signal (signo, sig_handler);
#endif
}
void
......@@ -86,10 +89,23 @@ ml_readline_init ()
rl_attempted_completion_function = (CPPFunction*)ml_command_completion;
rl_getc_function = ml_getc;
#endif
#ifdef HAVE_SIGACTION
{
struct sigaction act;
act.sa_handler = sig_handler;
sigemptyset (&act.sa_mask);
act.sa_flags = 0;
sigaction (SIGINT, &act, NULL);
#if defined(SIGWINCH)
sigaction (SIGWINCH, &act, NULL);
#endif
}
#else
signal (SIGINT, sig_handler);
#if defined(SIGWINCH)
signal (SIGWINCH, sig_handler);
#endif
#endif
}
#ifdef WITH_READLINE
......@@ -192,7 +208,7 @@ set_tty ()
new_settings = term_settings;
new_settings.c_lflag &= ~(ICANON|ECHO);
#if defined(TAB3)
#if defined(TAB3)
new_settings.c_oflag &= ~(TAB3);
#elif defined(OXTABS)
new_settings.c_oflag &= ~(OXTABS);
......@@ -224,7 +240,7 @@ set_tty ()
ch_erase = term_settings.c_cc[VERASE];
ch_kill = term_settings.c_cc[VKILL];
new_settings = term_settings;
new_settings.c_lflag &= ~(ICANON | ECHO);
new_settings.c_oflag &= ~(TAB3);
......@@ -249,13 +265,13 @@ int
set_tty ()
{
struct sgttyb new_settings;
if (ioctl(STDOUT, TIOCGETP, &term_settings) < 0)
return 1;
ch_erase = term_settings.sg_erase;
ch_kill = term_settings.sg_kill;
new_settings = term_settings;
new_settings.sg_flags |= CBREAK;
new_settings.sg_flags &= ~(ECHO | XTABS);
......@@ -284,7 +300,7 @@ ml_reread (char *prompt, char **text)
int line_size;
int pos;
char *p;
if (*text)
{
line = strdup (*text);
......@@ -314,16 +330,16 @@ ml_reread (char *prompt, char **text)
fputs (prompt, stdout);
fflush (stdout);
}
#ifdef TIOCSTI
for (p = line; *p; p++)
{
ioctl(0, TIOCSTI, p);
}
pos = 0;
while ((ch = ml_getc (stdin)) != EOF && ch != '\n')
{
if (pos >= line_size)
......@@ -344,13 +360,13 @@ ml_reread (char *prompt, char **text)
}
#else
fputs (line, stdout);
fflush (stdout);
# ifndef DUMB_MODE
# ifndef DUMB_MODE
set_tty ();
while ((ch = ml_getc (stdin)) != EOF)
{
if (ch == ch_erase)
......@@ -392,7 +408,7 @@ ml_reread (char *prompt, char **text)
}
fflush (stdout);
}
putc ('\n', stdout);
restore_tty ();
# else
......@@ -406,7 +422,7 @@ ml_reread (char *prompt, char **text)
}
pos = 0;
while ((ch = ml_getc (stdin)) != EOF && ch != '\n')
{
if (pos >= line_size)
......@@ -427,9 +443,9 @@ ml_reread (char *prompt, char **text)
}
# endif
#endif
line[pos] = 0;
if (ml_got_interrupt ())
free (line);
else
......
......@@ -235,7 +235,7 @@ util_expand_msglist (const int argc, char **argv, int **list)
* print 7[1],8[1-2]
* should print the first attachment of message 7 and the first
* and second attachments of message 8. The format inside the
* brackets is the same as a msglist, so we should be able to
* brackets is the same as a msglist, so we should be able to
* reuse this function for its expansion. This will primarily
* be used by the new decode command, which needs discussion on
* the mailing list to nail its syntax down (should it default to
......@@ -917,12 +917,12 @@ util_error (va_alist)
#else
char *format;
va_start(ap);
format = va_arg(ap, char *);
va_start (ap);
format = va_arg (ap, char *);
#endif
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
vfprintf (stderr, format, ap);
fprintf (stderr, "\n");
va_end(ap);
}
......@@ -1025,7 +1025,7 @@ void *
util_calloc (size_t nitems, size_t size)
{
void *p;
size *= nitems;
p = util_malloc (size);
memset (p, 0, size);
......