do_add_files_print_progress = 1;
}
+static volatile sig_atomic_t interrupted;
+
+static void
+handle_sigint (unused (int sig))
+{
+ static char msg[] = "Stopping... \n";
+ write(2, msg, sizeof(msg)-1);
+ interrupted = 1;
+}
+
static void
tag_inbox_and_unread (notmuch_message_t *message)
{
pathconf (path, _PC_NAME_MAX) + 1;
entry = malloc (entry_length);
- while (1) {
+ while (!interrupted) {
err = readdir_r (dir, entry, &e);
if (err) {
fprintf (stderr, "Error reading directory: %s\n",
pathconf (path, _PC_NAME_MAX) + 1;
entry = malloc (entry_length);
- while (1) {
+ while (!interrupted) {
err = readdir_r (dir, entry, &e);
if (err) {
fprintf (stderr, "Error reading directory: %s\n",
struct stat st;
const char *db_path;
char *dot_notmuch_path;
- int new_database = 0;
+ struct sigaction action;
+
+ /* Setup our handler for SIGINT */
+ memset (&action, 0, sizeof (struct sigaction));
+ action.sa_handler = handle_sigint;
+ sigemptyset (&action.sa_mask);
+ action.sa_flags = SA_RESTART;
+ sigaction (SIGINT, &action, NULL);
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
if (stat (dot_notmuch_path, &st)) {
- new_database = 1;
+ int count;
+
+ count = 0;
+ count_files (db_path, &count);
+ if (interrupted)
+ return 1;
+
notmuch = notmuch_database_create (db_path);
+ add_files_state.ignore_read_only_directories = FALSE;
+ add_files_state.total_files = count;
} else {
notmuch = notmuch_database_open (db_path);
+ add_files_state.ignore_read_only_directories = TRUE;
+ add_files_state.total_files = 0;
}
if (notmuch == NULL)
talloc_free (dot_notmuch_path);
dot_notmuch_path = NULL;
- if (new_database) {
- int count;
- count = 0;
- count_files (db_path, &count);
- add_files_state.ignore_read_only_directories = FALSE;
- add_files_state.total_files = count;
- } else {
- add_files_state.ignore_read_only_directories = TRUE;
- add_files_state.total_files = 0;
- }
-
add_files_state.saw_read_only_directory = FALSE;
add_files_state.total_files = 0;
add_files_state.processed_files = 0;
notmuch_database_close (notmuch);
- return ret;
+ return ret || interrupted;
}
#include "notmuch-client.h"
+static volatile sig_atomic_t interrupted;
+
+static void
+handle_sigint (unused (int sig))
+{
+ static char msg[] = "Stopping... \n";
+ write(2, msg, sizeof(msg)-1);
+ interrupted = 1;
+}
+
int
notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
{
notmuch_query_t *query;
notmuch_messages_t *messages;
notmuch_message_t *message;
+ struct sigaction action;
int i;
+ /* Setup our handler for SIGINT */
+ memset (&action, 0, sizeof (struct sigaction));
+ action.sa_handler = handle_sigint;
+ sigemptyset (&action.sa_mask);
+ action.sa_flags = SA_RESTART;
+ sigaction (SIGINT, &action, NULL);
+
add_tags = talloc_size (ctx, argc * sizeof (int));
if (add_tags == NULL) {
fprintf (stderr, "Out of memory.\n");
}
for (messages = notmuch_query_search_messages (query, 0, -1);
- notmuch_messages_has_more (messages);
+ notmuch_messages_has_more (messages) && !interrupted;
notmuch_messages_advance (messages))
{
message = notmuch_messages_get (messages);
notmuch_query_destroy (query);
notmuch_database_close (notmuch);
- return 0;
+ return interrupted;
}