Commit 1814cf1d 1814cf1d9b07f3e6d47c5d23daa03288d8426040 by Sergey Poznyakoff

Minor changes.

* libmu_cfg/tls.c (SSL_KEY_FILE_CHECKS): Mask out
MU_FILE_SAFETY_OWNER_MISMATCH bit.
* mu/shell.c: Handle SIGPIPE and SIGINTR.
1 parent c7fb4a0f
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
28 MU_FILE_SAFETY_GROUP_WRITABLE | \ 28 MU_FILE_SAFETY_GROUP_WRITABLE | \
29 MU_FILE_SAFETY_LINKED_WRDIR) 29 MU_FILE_SAFETY_LINKED_WRDIR)
30 30
31 #define SSL_KEY_FILE_CHECKS MU_FILE_SAFETY_ALL 31 #define SSL_KEY_FILE_CHECKS (MU_FILE_SAFETY_ALL & ~MU_FILE_SAFETY_OWNER_MISMATCH)
32 32
33 #define SSL_CA_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \ 33 #define SSL_CA_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
34 MU_FILE_SAFETY_GROUP_WRITABLE | \ 34 MU_FILE_SAFETY_GROUP_WRITABLE | \
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 #endif 19 #endif
20 #include <stdlib.h> 20 #include <stdlib.h>
21 #include <string.h> 21 #include <string.h>
22 #include <signal.h>
22 #include <mailutils/mailutils.h> 23 #include <mailutils/mailutils.h>
23 #include <mailutils/tls.h> 24 #include <mailutils/tls.h>
24 #include "mailutils/libargp.h" 25 #include "mailutils/libargp.h"
...@@ -35,6 +36,33 @@ char **mutool_prompt_env; ...@@ -35,6 +36,33 @@ char **mutool_prompt_env;
35 int mutool_shell_interactive; 36 int mutool_shell_interactive;
36 37
37 38
39 static int got_signal = 0;
40
41 static void
42 _shell_sig (int sig)
43 {
44 got_signal = sig;
45 }
46
47 #define shell_interrupted() (got_signal == SIGINT)
48
49 static void
50 report_signals ()
51 {
52 switch (got_signal)
53 {
54 case 0:
55 break;
56
57 case SIGINT:
58 mu_stream_printf (mu_strerr, _("Interrupt\n"));
59 mu_stream_flush (mu_strerr);
60
61 default:
62 got_signal = 0;
63 }
64 }
65
38 static int shell_exit (int, char **); 66 static int shell_exit (int, char **);
39 static int shell_help (int, char **); 67 static int shell_help (int, char **);
40 static int shell_prompt (int, char **); 68 static int shell_prompt (int, char **);
...@@ -274,6 +302,27 @@ get_history_file_name () ...@@ -274,6 +302,27 @@ get_history_file_name ()
274 return filename; 302 return filename;
275 } 303 }
276 304
305 static int
306 _shell_getc (FILE *stream)
307 {
308 unsigned char c;
309
310 while (1)
311 {
312 if (read (fileno (stream), &c, 1) == 1)
313 return c;
314 if (errno == EINTR)
315 {
316 if (shell_interrupted ())
317 break;
318 /* keep going if we handled the signal */
319 }
320 else
321 break;
322 }
323 return EOF;
324 }
325
277 /* Interface to Readline Completion */ 326 /* Interface to Readline Completion */
278 327
279 static char *shell_command_generator (const char *, int); 328 static char *shell_command_generator (const char *, int);
...@@ -288,6 +337,7 @@ mutool_initialize_readline (const char *name) ...@@ -288,6 +337,7 @@ mutool_initialize_readline (const char *name)
288 /* Allow conditional parsing of the ~/.inputrc file. */ 337 /* Allow conditional parsing of the ~/.inputrc file. */
289 rl_readline_name = (char *) name; 338 rl_readline_name = (char *) name;
290 rl_attempted_completion_function = (CPPFunction *) shell_completion; 339 rl_attempted_completion_function = (CPPFunction *) shell_completion;
340 rl_getc_function = _shell_getc;
291 read_history (get_history_file_name ()); 341 read_history (get_history_file_name ());
292 } 342 }
293 343
...@@ -507,6 +557,7 @@ input_line_interactive () ...@@ -507,6 +557,7 @@ input_line_interactive ()
507 int wsflags = MU_WRDSF_NOSPLIT | MU_WRDSF_NOCMD; 557 int wsflags = MU_WRDSF_NOSPLIT | MU_WRDSF_NOCMD;
508 struct mu_wordsplit ws; 558 struct mu_wordsplit ws;
509 559
560 report_signals ();
510 if (mutool_prompt_env) 561 if (mutool_prompt_env)
511 { 562 {
512 ws.ws_env = (const char **)mutool_prompt_env; 563 ws.ws_env = (const char **)mutool_prompt_env;
...@@ -528,6 +579,7 @@ input_line_script () ...@@ -528,6 +579,7 @@ input_line_script ()
528 size_t size = 0, n; 579 size_t size = 0, n;
529 char *buf = NULL; 580 char *buf = NULL;
530 581
582 report_signals ();
531 if (mu_stream_getline (mu_strin, &buf, &size, &n) || n == 0) 583 if (mu_stream_getline (mu_strin, &buf, &size, &n) || n == 0)
532 return NULL; 584 return NULL;
533 return buf; 585 return buf;
...@@ -547,6 +599,7 @@ mutool_shell (const char *name, struct mutool_command *cmd) ...@@ -547,6 +599,7 @@ mutool_shell (const char *name, struct mutool_command *cmd)
547 { 599 {
548 size_t n; 600 size_t n;
549 char *(*input_line) (); 601 char *(*input_line) ();
602 static int sigv[] = { SIGPIPE, SIGINT };
550 603
551 mutool_shell_interactive = isatty (0); 604 mutool_shell_interactive = isatty (0);
552 input_line = mutool_shell_interactive ? 605 input_line = mutool_shell_interactive ?
...@@ -562,11 +615,20 @@ mutool_shell (const char *name, struct mutool_command *cmd) ...@@ -562,11 +615,20 @@ mutool_shell (const char *name, struct mutool_command *cmd)
562 memcpy (shell_comtab + n, default_comtab, sizeof (default_comtab)); 615 memcpy (shell_comtab + n, default_comtab, sizeof (default_comtab));
563 616
564 mutool_initialize_readline (name); 617 mutool_initialize_readline (name);
618 mu_set_signals (_shell_sig, sigv, MU_ARRAY_SIZE (sigv));
565 while (!done) 619 while (!done)
566 { 620 {
567 char *s, *line = input_line (); 621 char *s, *line = input_line ();
568 if (!line) 622 if (!line)
623 {
624 if (shell_interrupted ())
625 {
626 report_signals ();
627 continue;
628 }
629 else
569 break; 630 break;
631 }
570 632
571 /* Remove leading and trailing whitespace from the line. 633 /* Remove leading and trailing whitespace from the line.
572 Then, if there is anything left, add it to the history list 634 Then, if there is anything left, add it to the history list
......