Commit 55086f94 55086f9411acfcf185f8f535b301b52600c48c68 by Sergey Poznyakoff

comsat: provide a fine-grained control over where biffrc errors are output

* comsat/comsat.c (biffrc_errors): New variable.
(comsat_cfg_param): New statements: biffrc-errors-to-tty and
biffrc-errors-to-err
(main): In test mode, set biffrc_errors to BIFFRC_ERRORS_TO_ERR.
* comsat/comsat.h (BIFFRC_ERRORS_TO_TTY)
(BIFFRC_ERRORS_TO_ERR): New flags.
(biffrc_errors): New variable.
* comsat/action.c (report_error): Consult biffrc_errors.
1 parent e20d435c
...@@ -314,15 +314,19 @@ struct biffrc_environ ...@@ -314,15 +314,19 @@ struct biffrc_environ
314 static void 314 static void
315 report_error (struct biffrc_environ *env, const char *fmt, ...) 315 report_error (struct biffrc_environ *env, const char *fmt, ...)
316 { 316 {
317 va_list ap; 317 if (biffrc_errors)
318 va_start (ap, fmt); 318 {
319 mu_vasnprintf (&env->errbuf, &env->errsize, fmt, ap); 319 va_list ap;
320 mu_stream_printf (env->logstr, "%s\n", env->errbuf); 320 va_start (ap, fmt);
321 mu_diag_output (MU_DIAG_ERROR, "%s", env->errbuf); 321 mu_vasnprintf (&env->errbuf, &env->errsize, fmt, ap);
322 va_end (ap); 322 if (biffrc_errors & BIFFRC_ERRORS_TO_TTY)
323 mu_stream_printf (env->logstr, "%s\n", env->errbuf);
324 if (biffrc_errors & BIFFRC_ERRORS_TO_ERR)
325 mu_diag_output (MU_DIAG_ERROR, "%s", env->errbuf);
326 va_end (ap);
327 }
323 } 328 }
324 329
325
326 static void 330 static void
327 action_beep (struct biffrc_environ *env, size_t argc, char **argv) 331 action_beep (struct biffrc_environ *env, size_t argc, char **argv)
328 { 332 {
......
...@@ -54,7 +54,7 @@ typedef struct utmp UTMP; ...@@ -54,7 +54,7 @@ typedef struct utmp UTMP;
54 #define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line)) 54 #define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line))
55 55
56 const char *program_version = "comsatd (" PACKAGE_STRING ")"; 56 const char *program_version = "comsatd (" PACKAGE_STRING ")";
57 static char doc[] = N_("GNU comsatd -- the Comsat daemon."); 57 static char doc[] = N_("GNU comsatd -- notify users about incoming mail");
58 static char args_doc[] = N_("\n--test MBOX-URL MSG-QID"); 58 static char args_doc[] = N_("\n--test MBOX-URL MSG-QID");
59 59
60 #define OPT_FOREGROUND 256 60 #define OPT_FOREGROUND 256
...@@ -100,6 +100,7 @@ int maxlines = 5; ...@@ -100,6 +100,7 @@ int maxlines = 5;
100 char *hostname; 100 char *hostname;
101 const char *username; 101 const char *username;
102 int require_tty; 102 int require_tty;
103 int biffrc_errors = BIFFRC_ERRORS_TO_TTY | BIFFRC_ERRORS_TO_ERR;
103 mu_m_server_t server; 104 mu_m_server_t server;
104 105
105 static void comsat_init (void); 106 static void comsat_init (void);
...@@ -114,11 +115,45 @@ static int reload = 0; ...@@ -114,11 +115,45 @@ static int reload = 0;
114 int test_mode; 115 int test_mode;
115 char *biffrc = BIFF_RC; 116 char *biffrc = BIFF_RC;
116 117
118 static int
119 biffrc_error_ctl (mu_config_value_t *val, int flag)
120 {
121 int res;
122
123 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
124 return 1;
125 if (mu_cfg_parse_boolean (val->v.string, &res))
126 mu_diag_output (MU_LOG_ERROR, _("not a boolean"));
127 else if (res)
128 biffrc_errors |= flag;
129 else
130 biffrc_errors &= ~flag;
131 return 0;
132 }
133
134 static int
135 cb_biffrc_errors_to_tty (void *data, mu_config_value_t *val)
136 {
137 return biffrc_error_ctl (val, BIFFRC_ERRORS_TO_TTY);
138 }
139
140 static int
141 cb_biffrc_errors_to_err (void *data, mu_config_value_t *val)
142 {
143 return biffrc_error_ctl (val, BIFFRC_ERRORS_TO_ERR);
144 }
145
117 struct mu_cfg_param comsat_cfg_param[] = { 146 struct mu_cfg_param comsat_cfg_param[] = {
118 { "allow-biffrc", mu_cfg_bool, &allow_biffrc, 0, NULL, 147 { "allow-biffrc", mu_cfg_bool, &allow_biffrc, 0, NULL,
119 N_("Read .biffrc file from the user home directory.") }, 148 N_("Read .biffrc file from the user home directory.") },
120 { "require-tty", mu_cfg_bool, &require_tty, 0, NULL, 149 { "require-tty", mu_cfg_bool, &require_tty, 0, NULL,
121 N_("Notify only if the user is logged on one of the ttys.") }, 150 N_("Notify only if the user is logged on one of the ttys.") },
151 { "biffrc-errors-to-tty", mu_cfg_callback, NULL, 0, cb_biffrc_errors_to_tty,
152 N_("Send biffrc errors to user's tty."),
153 N_("arg: bool") },
154 { "biffrc-errors-to-err", mu_cfg_callback, NULL, 0, cb_biffrc_errors_to_err,
155 N_("Send biffrc errors to Mailutils error output."),
156 N_("arg: bool") },
122 { "max-lines", mu_cfg_int, &maxlines, 0, NULL, 157 { "max-lines", mu_cfg_int, &maxlines, 0, NULL,
123 N_("Maximum number of message body lines to be output.") }, 158 N_("Maximum number of message body lines to be output.") },
124 { "max-requests", mu_cfg_uint, &maxrequests, 0, NULL, 159 { "max-requests", mu_cfg_uint, &maxrequests, 0, NULL,
...@@ -548,6 +583,7 @@ main (int argc, char **argv) ...@@ -548,6 +583,7 @@ main (int argc, char **argv)
548 argv += ind; 583 argv += ind;
549 584
550 mu_stdstream_strerr_setup (MU_STRERR_STDERR); 585 mu_stdstream_strerr_setup (MU_STRERR_STDERR);
586 biffrc_errors = BIFFRC_ERRORS_TO_ERR;
551 if (argc < 2 || argc > 2) 587 if (argc < 2 || argc > 2)
552 { 588 {
553 mu_error (_("mailbox URL and message QID are required in test mode")); 589 mu_error (_("mailbox URL and message QID are required in test mode"));
......
...@@ -68,6 +68,10 @@ ...@@ -68,6 +68,10 @@
68 68
69 #define BIFF_RC ".biffrc" 69 #define BIFF_RC ".biffrc"
70 70
71 /* Where to report biffrc errors to: */
72 #define BIFFRC_ERRORS_TO_TTY 0x01 /* Send them to the user's tty */
73 #define BIFFRC_ERRORS_TO_ERR 0x02 /* Send them to strerr */
74
71 extern int allow_biffrc; 75 extern int allow_biffrc;
72 extern unsigned maxrequests; 76 extern unsigned maxrequests;
73 extern time_t request_control_interval; 77 extern time_t request_control_interval;
...@@ -78,6 +82,7 @@ extern const char *username; ...@@ -78,6 +82,7 @@ extern const char *username;
78 extern char *hostname; 82 extern char *hostname;
79 extern struct daemon_param daemon_param; 83 extern struct daemon_param daemon_param;
80 extern char *biffrc; 84 extern char *biffrc;
85 extern int biffrc_errors;
81 86
82 void run_user_action (const char *device, mu_message_t msg); 87 void run_user_action (const char *device, mu_message_t msg);
83 88
......