From e5448adbb864736fd7e310fe25e6dd8439c269d0 Mon Sep 17 00:00:00 2001 From: djcb Date: Tue, 26 Jun 2012 13:11:50 +0300 Subject: [PATCH] * robustness/cleanup fixes: - mu-util.c: don't raise errors when fputs failes (this would spam us when a pipe broke) - mu-cmd-server.c: handle SIGPIPE, ignore empty command lines --- lib/mu-util.c | 7 +------ mu/mu-cmd-server.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/mu-util.c b/lib/mu-util.c index 6aa16029..421d4362 100644 --- a/lib/mu-util.c +++ b/lib/mu-util.c @@ -431,12 +431,7 @@ mu_util_fputs_encoded (const char *str, FILE *stream) g_free (conv); } - if (rv == EOF) { /* note, apparently, does not set errno */ - g_warning ("%s: fputs failed", __FUNCTION__); - return FALSE; - } - - return TRUE; + return (rv == EOF) ? FALSE : TRUE; } diff --git a/mu/mu-cmd-server.c b/mu/mu-cmd-server.c index 04fdce59..ae3f5c70 100644 --- a/mu/mu-cmd-server.c +++ b/mu/mu-cmd-server.c @@ -67,7 +67,7 @@ static void install_sig_handler (void) { struct sigaction action; - int i, sigs[] = { SIGINT, SIGHUP, SIGTERM }; + int i, sigs[] = { SIGINT, SIGHUP, SIGTERM, SIGPIPE }; MU_TERMINATE = FALSE; @@ -123,15 +123,18 @@ print_expr (const char* frm, ...) * COOKIE_PRE COOKIE_POST */ rv = write (outfd, cookie, lenlen + 2); - if (rv != -1) + if (rv != -1) { rv = write (outfd, expr, exprlen); + g_free (expr); + } if (rv != -1) rv = write (outfd, "\n", 1); - if (rv == -1) - g_warning ("%s: write() failed: %s", + if (rv == -1) { + g_critical ("%s: write() failed: %s", __FUNCTION__, strerror(errno)); - - g_free (expr); + /* terminate ourselves */ + raise (SIGTERM); + } } @@ -1351,6 +1354,11 @@ handle_args (MuStore *store, MuQuery *query, GSList *args, GError **err) }; cmd = (const char*) args->data; + + /* ignore empty */ + if (strlen (cmd) == 0) + return MU_OK; + for (u = 0; u != G_N_ELEMENTS (cmd_map); ++u) if (g_strcmp0(cmd, cmd_map[u].cmd) == 0) return cmd_map[u].func (store, query,