From a54af70c02f730ab7f550b9bb3b3281c36dda74a Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Thu, 29 Jan 2009 20:05:41 -0500 Subject: [PATCH] A few more pthread_testcancel()'s. Should be the last of them. --- src/commands.c | 28 +++++++++++++++++++++++++--- src/lock.h | 1 - src/pwmd.c | 3 ++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/commands.c b/src/commands.c index dfe17d04..4680c20b 100644 --- a/src/commands.c +++ b/src/commands.c @@ -149,6 +149,7 @@ gpg_error_t lock_file_mutex(struct client_s *client) */ while (pthread_mutex_trylock(&m->mutex) == EBUSY) { gpg_error_t rc = send_status(client->ctx, STATUS_LOCKED, NULL); + pthread_testcancel(); if (rc) return rc; @@ -1019,6 +1020,7 @@ gpg_error_t do_xml_encrypt(struct client_s *client, if (iter_progress && crypto->fh->fh2.iter >= iter_progress) { rc = send_status(client ? client->ctx : NULL, STATUS_ENCRYPT, "%u %u", 0, crypto->fh->fh2.iter); + pthread_testcancel(); if (rc) return rc; @@ -1028,7 +1030,9 @@ gpg_error_t do_xml_encrypt(struct client_s *client, if (iter_progress > 0 && xiter >= iter_progress) { if (!(xiter % iter_progress)) { rc = send_status(client ? client->ctx : NULL, STATUS_ENCRYPT, - "%u %u", ++n_iter * iter_progress, crypto->fh->fh2.iter); + "%u %u", ++n_iter * iter_progress, + crypto->fh->fh2.iter); + pthread_testcancel(); if (rc) return rc; @@ -1070,6 +1074,7 @@ gpg_error_t do_xml_encrypt(struct client_s *client, if (iter_progress && crypto->fh->fh2.iter >= iter_progress) { rc = send_status(client ? client->ctx : NULL, STATUS_ENCRYPT, "%u %u", crypto->fh->fh2.iter, crypto->fh->fh2.iter); + pthread_testcancel(); if (rc) return rc; @@ -1083,6 +1088,7 @@ write_file: } if (lstat(filename, &st) == 0) { + pthread_testcancel(); mode = st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO); /* @@ -1092,6 +1098,7 @@ write_file: return gpg_error_from_errno(EACCES); } else { + pthread_testcancel(); if (errno != ENOENT) return gpg_error_from_errno(errno); } @@ -1116,6 +1123,7 @@ write_file: do_write_file: crypto->fh->fh2.version = VERSION_HEX; len = write(crypto->fh->fd, &crypto->fh->fh2, sizeof(crypto->fh->fh2)); + pthread_testcancel(); if (len != sizeof(crypto->fh->fh2)) { len = errno; @@ -1127,17 +1135,22 @@ do_write_file: } len = write(crypto->fh->fd, crypto->inbuf, crypto->insize); + pthread_testcancel(); if (len != crypto->insize) { + pthread_testcancel(); len = errno; - if (filename && strcmp(filename, "-")) + if (filename && strcmp(filename, "-")) { unlink(tmp); + pthread_testcancel(); + } return gpg_error_from_errno(len); } if (fsync(crypto->fh->fd) == -1) { + pthread_testcancel(); len = errno; if (filename && strcmp(filename, "-")) @@ -1153,6 +1166,7 @@ do_write_file: g_snprintf(tmp2, sizeof(tmp2), "%s.backup", filename); if (rename(filename, tmp2) == -1) { + pthread_testcancel(); unlink(tmp); len = errno; return gpg_error_from_errno(len); @@ -1160,18 +1174,22 @@ do_write_file: } if (rename(tmp, filename) == -1) { + pthread_testcancel(); len = errno; unlink(tmp); return gpg_error_from_errno(len); } - if (mode) + if (mode) { chmod(filename, mode); + pthread_testcancel(); + } } if (client && lstat(filename, &st) == 0) client->mtime = st.st_mtime; + pthread_testcancel(); return 0; } @@ -3027,6 +3045,7 @@ gpg_error_t try_xml_decrypt(assuan_context_t ctx, guchar *key, crypto->insize = insize; len = read(crypto->fh->fd, crypto->inbuf, crypto->insize); + pthread_testcancel(); if (len != crypto->insize) return GPG_ERR_INV_LENGTH; @@ -3049,6 +3068,7 @@ gpg_error_t try_xml_decrypt(assuan_context_t ctx, guchar *key, if (iter_progress > 0 && fh_iter >= iter_progress) { rc = send_status(ctx, STATUS_DECRYPT, "%u %u", 0, fh_iter); + pthread_testcancel(); if (rc) return rc; @@ -3080,6 +3100,7 @@ gpg_error_t try_xml_decrypt(assuan_context_t ctx, guchar *key, if (!(iter % iter_progress)) { rc = send_status(ctx, STATUS_DECRYPT, "%u %u", ++n_iter * iter_progress, fh_iter); + pthread_testcancel(); if (rc) return rc; @@ -3103,6 +3124,7 @@ gpg_error_t try_xml_decrypt(assuan_context_t ctx, guchar *key, if (iter_progress && fh_iter >= iter_progress) { rc = send_status(ctx, STATUS_DECRYPT, "%u %u", fh_iter, fh_iter); + pthread_testcancel(); if (rc) return rc; diff --git a/src/lock.h b/src/lock.h index 32d1283c..fd03ae96 100644 --- a/src/lock.h +++ b/src/lock.h @@ -23,7 +23,6 @@ #include #include "cache.h" -#define DEBUG 1 #ifdef DEBUG #define MUTEX_LOCK_DEBUG \ log_write("%s(%i): %s: LOCK", __FILE__, __LINE__, __FUNCTION__); diff --git a/src/pwmd.c b/src/pwmd.c index 0e57b270..3579b681 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -638,7 +638,6 @@ static void *client_msg_sender_thread(void *arg) MUTEX_LOCK(&thd->msg_sender_mutex); thd->msg_queue = g_slist_remove(thd->msg_queue, msg); g_free(msg); - pthread_testcancel(); if (rc) { log_write(N_("msg for %i failed: %s"), thd->fd, @@ -759,6 +758,8 @@ static void *client_thread(void *data) close(thd->fd); goto fail; } + + pthread_testcancel(); } #endif -- 2.11.4.GIT