1 Return-Path: <davrieb@liegesta.at>
\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 1A8FA429E2E
\r
6 for <notmuch@notmuchmail.org>; Sun, 6 Nov 2011 04:23:20 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 3stAXfEVxf87 for <notmuch@notmuchmail.org>;
\r
16 Sun, 6 Nov 2011 04:23:18 -0800 (PST)
\r
17 Received: from plum.liegesta.at (plum.liegesta.at [83.169.17.237])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 8BA82429E2F
\r
19 for <notmuch@notmuchmail.org>; Sun, 6 Nov 2011 04:23:12 -0800 (PST)
\r
20 Received: from ambiguous-mid.liegesta.at (mk046207255168.a1.net
\r
21 [46.207.255.168]) (Authenticated sender: davrieb)
\r
22 by plum.liegesta.at (Postfix) with ESMTPA id 0729527B8230;
\r
23 Sun, 6 Nov 2011 13:23:11 +0100 (CET)
\r
24 Received: by ambiguous-mid.liegesta.at (Postfix, from userid 1000)
\r
25 id D97FA1FF32; Sun, 6 Nov 2011 12:23:07 +0100 (CET)
\r
26 From: David Riebenbauer <davrieb@liegesta.at>
\r
27 To: Notmuch Mailing List <notmuch@notmuchmail.org>
\r
28 Subject: [PATCH 3/3] notmuch-deliver: Convert test program to glib main loop.
\r
29 Date: Sun, 6 Nov 2011 12:23:04 +0100
\r
30 Message-Id: <1320578584-6642-4-git-send-email-davrieb@liegesta.at>
\r
31 X-Mailer: git-send-email 1.7.7.1
\r
32 In-Reply-To: <1320578584-6642-1-git-send-email-davrieb@liegesta.at>
\r
33 References: <1320578584-6642-1-git-send-email-davrieb@liegesta.at>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.13
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Sun, 06 Nov 2011 12:23:20 -0000
\r
48 This makes reporting of success/failure more robust.
\r
50 contrib/notmuch-deliver/test/notmuch-lock.c | 103 +++++++++++++++++++++------
\r
51 1 files changed, 81 insertions(+), 22 deletions(-)
\r
53 diff --git a/contrib/notmuch-deliver/test/notmuch-lock.c b/contrib/notmuch-deliver/test/notmuch-lock.c
\r
54 index 2303843..78e57b6 100644
\r
55 --- a/contrib/notmuch-deliver/test/notmuch-lock.c
\r
56 +++ b/contrib/notmuch-deliver/test/notmuch-lock.c
\r
58 #define MAX_UWAIT 600000000 // 10 minutes
\r
61 +typedef struct ChildFinishedData_
\r
63 + GMainLoop *main_loop;
\r
65 +} ChildFinishedData;
\r
67 +typedef struct SpawnChildData_
\r
70 + ChildFinishedData *child_finidshed_data;
\r
71 + GMainLoop *main_loop;
\r
75 static gint sleep_option = -1;
\r
76 static GOptionEntry entries[] = {
\r
77 @@ -88,6 +101,65 @@ get_db_path(void)
\r
82 +child_finished_cb(GPid pid, gint status, gpointer data)
\r
84 + ChildFinishedData *child_finidshed_data = (ChildFinishedData *)data;
\r
86 + g_printerr("Called child_finished_cb()\n");
\r
88 + if WIFEXITED(status) {
\r
89 + child_finidshed_data->return_val = WEXITSTATUS(status);
\r
90 + g_printerr("PID %d exited normally with exit code %d\n", pid, WEXITSTATUS(status));
\r
93 + g_main_loop_quit(child_finidshed_data->main_loop);
\r
98 +spawn_child_cb(gpointer data)
\r
100 + SpawnChildData *spawn_child_data = (SpawnChildData *)data;
\r
102 + g_printerr("Called spawn_child_cb()\n");
\r
104 + gboolean spawn_success = FALSE;
\r
105 + GPid child_pid = 0;
\r
106 + spawn_success = g_spawn_async(
\r
107 + g_get_current_dir(),
\r
108 + spawn_child_data->new_argv,
\r
110 + G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN | G_SPAWN_DO_NOT_REAP_CHILD,
\r
116 + if (spawn_success) {
\r
117 + g_child_watch_add(child_pid, &child_finished_cb, spawn_child_data->child_finidshed_data);
\r
120 + g_printerr("faild to spawn child\n");
\r
128 +close_db_cb(gpointer data)
\r
130 + notmuch_database_t *db = (notmuch_database_t*)data;
\r
132 + g_printerr("Called close_db_cb()\n");
\r
134 + // Close database again
\r
135 + notmuch_database_close(db);
\r
142 main(int argc, char *argv[])
\r
143 @@ -132,22 +204,6 @@ main(int argc, char *argv[])
\r
145 return EXIT_FAILURE;
\r
147 - gboolean spawn_success = FALSE;
\r
148 - GPid child_pid = 0;
\r
149 - spawn_success = g_spawn_async(
\r
150 - g_get_current_dir(),
\r
153 - G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN | G_SPAWN_DO_NOT_REAP_CHILD,
\r
159 - if (!spawn_success) {
\r
160 - g_printerr("faild to spawn child\n");
\r
163 // Sleep for some time
\r
164 if (sleep_option >= 0) {
\r
165 sleep_time = sleep_option;
\r
166 @@ -155,13 +211,16 @@ main(int argc, char *argv[])
\r
167 sleep_time = g_random_int_range(MIN_UWAIT, MAX_UWAIT);
\r
169 g_printerr("Sleeping for %f secs\n", ((double)sleep_time)/(1000*1000));
\r
170 - usleep(sleep_time);
\r
172 - // Close database again
\r
173 - notmuch_database_close(db);
\r
174 + GMainLoop *main_loop = g_main_loop_new(NULL, FALSE);
\r
176 + ChildFinishedData child_finidshed_data = {main_loop, 0};
\r
177 + SpawnChildData spawn_child_data = {new_argv, &child_finidshed_data, main_loop, 0};
\r
179 + g_idle_add(&spawn_child_cb, &spawn_child_data);
\r
180 + g_timeout_add(sleep_time / 1000, &close_db_cb, db);
\r
181 + g_main_loop_run(main_loop);
\r
183 - int child_status = 0;
\r
184 - child_pid = waitpid(child_pid, &child_status, 0);
\r
186 - return WEXITSTATUS(child_status);
\r
187 + return child_finidshed_data.return_val;
\r