1 Return-Path: <bremner@unb.ca>
\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 D87E040D141
\r
6 for <notmuch@notmuchmail.org>; Mon, 11 Oct 2010 06:27:35 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.6 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id haDA-XLbZceo for <notmuch@notmuchmail.org>;
\r
16 Mon, 11 Oct 2010 06:27:17 -0700 (PDT)
\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 84B0C40BFD3
\r
19 for <notmuch@notmuchmail.org>; Mon, 11 Oct 2010 06:27:16 -0700 (PDT)
\r
20 Received: from rocinante.cs.unb.ca
\r
21 (fctnnbsc30w-142167176217.pppoe-dynamic.High-Speed.nb.bellaliant.net
\r
22 [142.167.176.217]) (authenticated bits=0)
\r
23 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id o9BDRG7B003861
\r
24 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);
\r
25 Mon, 11 Oct 2010 10:27:16 -0300
\r
26 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.72)
\r
27 (envelope-from <bremner@unb.ca>)
\r
28 id 1P5IPL-0004ca-Ra; Mon, 11 Oct 2010 10:27:15 -0300
\r
29 From: david@tethera.net
\r
30 To: notmuch@notmuchmail.org
\r
31 Subject: [PATCH 1/3] Initial implementation of low level logging routines.
\r
32 Date: Mon, 11 Oct 2010 10:26:55 -0300
\r
33 Message-Id: <1286803617-17328-2-git-send-email-david@tethera.net>
\r
34 X-Mailer: git-send-email 1.7.1
\r
35 In-Reply-To: <1286803617-17328-1-git-send-email-david@tethera.net>
\r
36 References: <1286803617-17328-1-git-send-email-david@tethera.net>
\r
37 Cc: David Bremner <bremner@unb.ca>
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Mon, 11 Oct 2010 13:27:36 -0000
\r
52 From: David Bremner <bremner@unb.ca>
\r
54 notmuch_log_open: open a log file; just a wrapper around open(2)
\r
55 notmuch_log_append: atomically append a buffer (character array) to a log file
\r
57 Based on per-write file locking, performance will have to be tested.
\r
59 Makefile.local | 1 +
\r
60 notmuch-client.h | 10 +++++
\r
61 notmuch-config.c | 15 ++++++++
\r
62 notmuch-log.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
63 4 files changed, 128 insertions(+), 0 deletions(-)
\r
64 create mode 100644 notmuch-log.c
\r
66 diff --git a/Makefile.local b/Makefile.local
\r
67 index ade8412..8dbda15 100644
\r
68 --- a/Makefile.local
\r
69 +++ b/Makefile.local
\r
70 @@ -240,6 +240,7 @@ notmuch_client_srcs = \
\r
78 diff --git a/notmuch-client.h b/notmuch-client.h
\r
79 index 20be43b..0422b1c 100644
\r
80 --- a/notmuch-client.h
\r
81 +++ b/notmuch-client.h
\r
82 @@ -191,6 +191,16 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
83 const char *new_tags[],
\r
87 +notmuch_config_get_log_path (notmuch_config_t *config,
\r
88 + const char *name);
\r
91 +notmuch_log_open (const char *path);
\r
94 +notmuch_log_append (int file_desc, const char *buffer, size_t len);
\r
97 debugger_is_active (void);
\r
99 diff --git a/notmuch-config.c b/notmuch-config.c
\r
100 index cf30603..c01e8f4 100644
\r
101 --- a/notmuch-config.c
\r
102 +++ b/notmuch-config.c
\r
103 @@ -562,3 +562,18 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
104 config->new_tags = NULL;
\r
108 +notmuch_config_get_log_path (notmuch_config_t *config, const char *name)
\r
110 + char *path, *rpath;
\r
112 + path= g_key_file_get_string (config->key_file,
\r
113 + "log", name, NULL);
\r
114 + if (path != NULL) {
\r
115 + rpath = talloc_strdup (config, path);
\r
122 diff --git a/notmuch-log.c b/notmuch-log.c
\r
123 new file mode 100644
\r
124 index 0000000..c4ddcd3
\r
126 +++ b/notmuch-log.c
\r
129 +/* notmuch - Not much of an email program, (just index and search)
\r
131 + * Copyright © 2010 David Bremner
\r
133 + * This program is free software: you can redistribute it and/or modify
\r
134 + * it under the terms of the GNU General Public License as published by
\r
135 + * the Free Software Foundation, either version 3 of the License, or
\r
136 + * (at your option) any later version.
\r
138 + * This program is distributed in the hope that it will be useful,
\r
139 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
140 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
141 + * GNU General Public License for more details.
\r
143 + * You should have received a copy of the GNU General Public License
\r
144 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
146 + * Author: David Bremner <david@tethera.net>
\r
149 +#include <sys/types.h>
\r
150 +#include <sys/stat.h>
\r
151 +#include <fcntl.h>
\r
152 +#include <unistd.h>
\r
154 +#include "notmuch-client.h"
\r
156 + Look a key up in the config file; open the corresponding file as a
\r
159 + Return a file descriptor to the open log file, or -1 if an error
\r
164 +notmuch_log_open (const char *path)
\r
168 + fd = open (path, O_CREAT|O_WRONLY|O_APPEND);
\r
170 + fprintf (stderr, "Failed to open %s: %s\n",
\r
171 + path, strerror (errno));
\r
178 +notmuch_log_append (int file_desc, const char *buffer, size_t len){
\r
180 + struct flock lock;
\r
182 + lock.l_type = F_WRLCK;
\r
183 + lock.l_whence = SEEK_SET;
\r
184 + lock.l_start = 0;
\r
187 + if (fcntl (file_desc, F_SETLKW, &lock) != 0) {
\r
188 + fprintf (stderr, "Failed to lock %s\n",
\r
189 + strerror (errno));
\r
191 + return NOTMUCH_STATUS_FILE_ERROR;
\r
198 + written = write(file_desc, buffer, len);
\r
199 + if (written < 0 || (written == 0 && errno !=0))
\r
201 + fprintf (stderr, "Failed to write %zd characters: %s\n",
\r
202 + len, strerror (errno));
\r
204 + return NOTMUCH_STATUS_FILE_ERROR;
\r
208 + buffer += written;
\r
212 + if (fdatasync (file_desc) != 0) {
\r
213 + fprintf (stderr, "Failed to sync: %s\n",
\r
214 + strerror (errno));
\r
216 + return NOTMUCH_STATUS_FILE_ERROR;
\r
219 + lock.l_type=F_UNLCK;
\r
221 + if (fcntl (file_desc, F_SETLK, &lock) != 0) {
\r
222 + fprintf (stderr, "Failed to unlock: %s\n",
\r
223 + strerror (errno));
\r
225 + return NOTMUCH_STATUS_FILE_ERROR;
\r
228 + return NOTMUCH_STATUS_SUCCESS;
\r