Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 46 / c6c86c1bf1ff5d4cfc28509ecb02d6aabb2c21
1 Return-Path: <novalazy@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 06F4D431FAF\r
6         for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:18:36 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id SF5CcSdigFkr for <notmuch@notmuchmail.org>;\r
17         Sat, 24 Nov 2012 17:18:35 -0800 (PST)\r
18 Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com\r
19         [209.85.220.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 7F6ED431FAE\r
22         for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:18:35 -0800 (PST)\r
23 Received: by mail-pa0-f53.google.com with SMTP id hz1so3911431pad.26\r
24         for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:18:35 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
27         bh=0TcysSCFUVeU5fnpLaZFvvTrATxquUbMYeavyoCVhWQ=;\r
28         b=FP05F1yekaVu3enYVbdrnUZXG/Z3oybND03OuQsVdnQqG9f65y3hSORPYreu+bPcsj\r
29         GvYfATftBdVhhgT8vc0NPS1EF4fc5MaiU25m0WU6QgGurNWBAJvIbRHgncS+7vpSMv/h\r
30         Ry81oEB9uOkiVD6bxmN1daYKDih4ewI/Q89hkIFJ9UKeEFK45Z39cQYakN7KfhioZTXE\r
31         4EF9PRuYNA6LU+WAyVOdKBwzjx6nqkAwUtUjNnLUa7PO2ofcwM22ocAKT7B1Vu7ZzOKM\r
32         ZpTYbjjTnxQnwyadbDfQQyHZNfIlRrcrhJRyuzEzYP8SQvURyNi1Izhg5msfV7jWMP/D\r
33         7N2w==\r
34 Received: by 10.68.209.230 with SMTP id mp6mr26312981pbc.8.1353806315268;\r
35         Sat, 24 Nov 2012 17:18:35 -0800 (PST)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215])\r
38         by mx.google.com with ESMTPS id oj1sm6231031pbb.19.2012.11.24.17.18.32\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Sat, 24 Nov 2012 17:18:34 -0800 (PST)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v2 16/20] insert: trap SIGINT and clean up\r
44 Date: Sun, 25 Nov 2012 12:16:42 +1100\r
45 Message-Id: <1353806206-29133-17-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.7.12.1\r
47 In-Reply-To: <1353806206-29133-1-git-send-email-novalazy@gmail.com>\r
48 References: <1353806206-29133-1-git-send-email-novalazy@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Sun, 25 Nov 2012 01:18:36 -0000\r
62 \r
63 The only potentially long-running part of the 'insert' command should be\r
64 copying stdin to the 'tmp' file.  If SIGINT is received during the\r
65 copying process, abort and clean up the file in 'tmp'.  At all other\r
66 points, just ignore the signal and continue.\r
67 ---\r
68  notmuch-insert.c | 27 +++++++++++++++++++++++++--\r
69  1 file changed, 25 insertions(+), 2 deletions(-)\r
70 \r
71 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
72 index 831b322..28653ee 100644\r
73 --- a/notmuch-insert.c\r
74 +++ b/notmuch-insert.c\r
75 @@ -24,6 +24,21 @@\r
76  #include <sys/stat.h>\r
77  #include <fcntl.h>\r
78  \r
79 +static volatile sig_atomic_t interrupted;\r
80 +\r
81 +static void\r
82 +handle_sigint (unused (int sig))\r
83 +{\r
84 +    static char msg[] = "Stopping...         \n";\r
85 +\r
86 +    /* This write is "opportunistic", so it's okay to ignore the\r
87 +     * result.  It is not required for correctness, and if it does\r
88 +     * fail or produce a short write, we want to get out of the signal\r
89 +     * handler as quickly as possible, not retry it. */\r
90 +    IGNORE_RESULT (write (2, msg, sizeof (msg) - 1));\r
91 +    interrupted = 1;\r
92 +}\r
93 +\r
94  /* Like gethostname but guarantees that a null-terminated hostname is\r
95   * returned, even if it has to make one up.\r
96   * Returns true unless hostname contains a slash. */\r
97 @@ -241,7 +256,7 @@ copy_fd_data (int fdin, int fdout)\r
98      ssize_t remain;\r
99      ssize_t written;\r
100  \r
101 -    for (;;) {\r
102 +    while (! interrupted) {\r
103         remain = read (fdin, buf, sizeof(buf));\r
104         if (remain == 0)\r
105             break;\r
106 @@ -270,7 +285,7 @@ copy_fd_data (int fdin, int fdout)\r
107         } while (remain > 0);\r
108      }\r
109  \r
110 -    return TRUE;\r
111 +    return ! interrupted;\r
112  }\r
113  \r
114  /* Add the specified message file to the notmuch database, applying tags.\r
115 @@ -382,6 +397,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
116  {\r
117      notmuch_config_t *config;\r
118      notmuch_database_t *notmuch;\r
119 +    struct sigaction action;\r
120      const char *db_path;\r
121      const char **new_tags;\r
122      size_t new_tags_length;\r
123 @@ -428,6 +444,13 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
124         return 1;\r
125      }\r
126  \r
127 +    /* Setup our handler for SIGINT */\r
128 +    memset (&action, 0, sizeof (struct sigaction));\r
129 +    action.sa_handler = handle_sigint;\r
130 +    sigemptyset (&action.sa_mask);\r
131 +    action.sa_flags = SA_RESTART;\r
132 +    sigaction (SIGINT, &action, NULL);\r
133 +\r
134      config = notmuch_config_open (ctx, NULL, NULL);\r
135      if (config == NULL)\r
136         return 1;\r
137 -- \r
138 1.7.12.1\r
139 \r