[Pkg-gnupg-commit] [gpgme] 409/412: imported small documentation and test patches from upstream
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Thu Sep 22 21:27:31 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gpgme.
commit 828c1154b062e1d57b706493baed76fd475db879
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date: Thu Sep 22 17:14:04 2016 -0400
imported small documentation and test patches from upstream
---
...-Fix-minor-errors-in-I-O-callback-example.patch | 72 +++++
...003-tests-Fix-select-usage-in-t-eventloop.patch | 37 +++
...gpg-Add-option-exit-on-status-write-error.patch | 32 +++
.../0005-tests-Add-test-for-cancellation.patch | 312 +++++++++++++++++++++
debian/patches/series | 4 +
5 files changed, 457 insertions(+)
diff --git a/debian/patches/0002-doc-Fix-minor-errors-in-I-O-callback-example.patch b/debian/patches/0002-doc-Fix-minor-errors-in-I-O-callback-example.patch
new file mode 100644
index 0000000..b4be7ed
--- /dev/null
+++ b/debian/patches/0002-doc-Fix-minor-errors-in-I-O-callback-example.patch
@@ -0,0 +1,72 @@
+From: Daiki Ueno <ueno at gnu.org>
+Date: Tue, 9 Feb 2016 17:03:50 +0900
+Subject: doc: Fix minor errors in I/O callback example
+
+* gpgme.texi (I/O Callback Example): Fix typos, add timeout to select,
+and initialize mutex as recursive.
+
+Signed-off-by: Daiki Ueno <ueno at gnu.org>
+---
+ doc/gpgme.texi | 22 +++++++++++++++++-----
+ 1 file changed, 17 insertions(+), 5 deletions(-)
+
+diff --git a/doc/gpgme.texi b/doc/gpgme.texi
+index ec7ebb7..6d6d692 100644
+--- a/doc/gpgme.texi
++++ b/doc/gpgme.texi
+@@ -6016,6 +6016,7 @@ do_select (struct event_loop *loop)
+ fd_set wfds;
+ int i, n;
+ int any = 0;
++ struct timeval tv;
+ struct one_fd *fdlist = loop->fds;
+
+ pthread_mutex_lock (&loop->lock);
+@@ -6024,11 +6025,14 @@ do_select (struct event_loop *loop)
+ for (i = 0; i < MAX_FDS; i++)
+ if (fdlist[i].fd != -1)
+ FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds);
+- pthread_mutex_unlock (&loop->unlock);
++ pthread_mutex_unlock (&loop->lock);
++
++ tv.tv_sec = 0;
++ tv.tv_usec = 1000;
+
+ do
+ @{
+- n = select (FD_SETSIZE, &rfds, &wfds, NULL, 0);
++ n = select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
+ @}
+ while (n < 0 && errno == EINTR);
+
+@@ -6082,6 +6086,7 @@ main (int argc, char *argv[])
+ gpgme_error_t err;
+ gpgme_data_t sig, text;
+ int i;
++ pthread_mutexattr_t attr;
+ struct gpgme_io_cbs io_cbs =
+ @{
+ add_io_cb,
+@@ -6091,12 +6096,19 @@ main (int argc, char *argv[])
+ &result
+ @};
+
+- init_gpgme (void);
++ init_gpgme ();
+
+ /* Initialize the loop structure. */
+- pthread_mutex_init (&loop.lock, NULL);
++
++ /* The mutex must be recursive, since remove_io_cb (which acquires a
++ lock) can be called while holding a lock acquired in do_select. */
++ pthread_mutexattr_init (&attr);
++ pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
++ pthread_mutex_init (&loop.lock, &attr);
++ pthread_mutexattr_destroy (&attr);
++
+ for (i = 0; i < MAX_FDS; i++)
+- loop->fds[i].fd = -1;
++ loop.fds[i].fd = -1;
+
+ /* Initialize the result structure. */
+ result.done = 0;
diff --git a/debian/patches/0003-tests-Fix-select-usage-in-t-eventloop.patch b/debian/patches/0003-tests-Fix-select-usage-in-t-eventloop.patch
new file mode 100644
index 0000000..21d1eb3
--- /dev/null
+++ b/debian/patches/0003-tests-Fix-select-usage-in-t-eventloop.patch
@@ -0,0 +1,37 @@
+From: Daiki Ueno <ueno at gnu.org>
+Date: Tue, 9 Feb 2016 17:03:51 +0900
+Subject: tests: Fix select usage in t-eventloop
+
+* tests/gpg/t-eventloop.c (do_select): Supply timeout value to select.
+
+Signed-off-by: Daiki Ueno <ueno at gnu.org>
+---
+ tests/gpg/t-eventloop.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/tests/gpg/t-eventloop.c b/tests/gpg/t-eventloop.c
+index 74af35f..2d3df41 100644
+--- a/tests/gpg/t-eventloop.c
++++ b/tests/gpg/t-eventloop.c
+@@ -111,6 +111,7 @@ do_select (void)
+ fd_set wfds;
+ int i, n;
+ int any = 0;
++ struct timeval tv;
+
+ FD_ZERO (&rfds);
+ FD_ZERO (&wfds);
+@@ -118,9 +119,12 @@ do_select (void)
+ if (fdlist[i].fd != -1)
+ FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds);
+
++ tv.tv_sec = 0;
++ tv.tv_usec = 1000;
++
+ do
+ {
+- n = select (FD_SETSIZE, &rfds, &wfds, NULL, 0);
++ n = select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
+ }
+ while (n < 0 && errno == EINTR);
+
diff --git a/debian/patches/0004-gpg-Add-option-exit-on-status-write-error.patch b/debian/patches/0004-gpg-Add-option-exit-on-status-write-error.patch
new file mode 100644
index 0000000..0fb701b
--- /dev/null
+++ b/debian/patches/0004-gpg-Add-option-exit-on-status-write-error.patch
@@ -0,0 +1,32 @@
+From: Daiki Ueno <ueno at gnu.org>
+Date: Tue, 9 Feb 2016 17:03:53 +0900
+Subject: gpg: Add option --exit-on-status-write-error
+
+* src/engine-gpg.c (gpg_new): Add --exit-on-status-write-error if the
+engine version is latest enough to expect progress output from gpg.
+
+--
+GnuPG-bug-id: 1415
+Signed-off-by: Daiki Ueno <ueno at gnu.org>
+
+Changed the version test from the patch to use the newer
+have_gpg_version.
+
+Signed-off-by: Werner Koch <wk at gnupg.org>
+---
+ src/engine-gpg.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/src/engine-gpg.c b/src/engine-gpg.c
+index 8bb348f..3f1d34d 100644
+--- a/src/engine-gpg.c
++++ b/src/engine-gpg.c
+@@ -544,6 +544,8 @@ gpg_new (void **engine, const char *file_name, const char *home_dir,
+ rc = add_arg (gpg, "utf8");
+ if (!rc)
+ rc = add_arg (gpg, "--enable-progress-filter");
++ if (!rc && have_gpg_version (gpg, "2.1.11"))
++ rc = add_arg (gpg, "--exit-on-status-write-error");
+ if (rc)
+ goto leave;
+
diff --git a/debian/patches/0005-tests-Add-test-for-cancellation.patch b/debian/patches/0005-tests-Add-test-for-cancellation.patch
new file mode 100644
index 0000000..b0cd003
--- /dev/null
+++ b/debian/patches/0005-tests-Add-test-for-cancellation.patch
@@ -0,0 +1,312 @@
+From: Daiki Ueno <ueno at gnu.org>
+Date: Tue, 9 Feb 2016 17:03:54 +0900
+Subject: tests: Add test for cancellation
+
+* tests/gpg/t-cancel.c: New file.
+* tests/gpg/Makefile.am (tests_skipped): New variable, default to
+t-genkey and t-cancel.
+(noinst_PROGRAMS): Add $(tests_skipped).
+* tests/gpg/.gitignore: Add t-cancel.
+
+Signed-off-by: Daiki Ueno <ueno at gnu.org>
+---
+ tests/gpg/Makefile.am | 12 ++-
+ tests/gpg/t-cancel.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 275 insertions(+), 2 deletions(-)
+ create mode 100644 tests/gpg/t-cancel.c
+
+diff --git a/tests/gpg/Makefile.am b/tests/gpg/Makefile.am
+index 9877843..2538f63 100644
+--- a/tests/gpg/Makefile.am
++++ b/tests/gpg/Makefile.am
+@@ -62,9 +62,17 @@ AM_CPPFLAGS = -I$(top_builddir)/src @GPG_ERROR_CFLAGS@
+ AM_LDFLAGS = -no-install
+ LDADD = ../../src/libgpgme.la
+ t_thread1_LDADD = ../../src/libgpgme-pthread.la -lpthread
++t_cancel_LDADD = ../../src/libgpgme-pthread.la -lpthread
++
++# We don't run t-genkey and t-cancel in the test suite, because it
++# takes too long
++tests_skipped = t-genkey
++if !HAVE_W32_SYSTEM
++tests_skipped += t-cancel
++endif
++
++noinst_PROGRAMS = $(c_tests) $(tests_skipped)
+
+-# We don't run t-genkey in the test suite, because it takes too long
+-noinst_PROGRAMS = $(c_tests) t-genkey
+
+ clean-local:
+ -$(top_srcdir)/tests/start-stop-agent --stop
+diff --git a/tests/gpg/t-cancel.c b/tests/gpg/t-cancel.c
+new file mode 100644
+index 0000000..af98af9
+--- /dev/null
++++ b/tests/gpg/t-cancel.c
+@@ -0,0 +1,265 @@
++/* t-thread-cancel.c - Regression test.
++ Copyright (C) 2000 Werner Koch (dd9jn)
++ Copyright (C) 2001, 2003, 2004 g10 Code GmbH
++
++ This file is part of GPGME.
++
++ GPGME is free software; you can redistribute it and/or modify it
++ under the terms of the GNU Lesser General Public License as
++ published by the Free Software Foundation; either version 2.1 of
++ the License, or (at your option) any later version.
++
++ GPGME is distributed in the hope that it will be useful, but
++ WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Lesser General Public License for more details.
++
++ You should have received a copy of the GNU Lesser General Public
++ License along with this program; if not, write to the Free Software
++ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
++ 02111-1307, USA. */
++
++/* We need to include config.h so that we know whether we are building
++ with large file system (LFS) support. */
++#ifdef HAVE_CONFIG_H
++#include <config.h>
++#endif
++
++#include <stdlib.h>
++#include <stdio.h>
++#include <string.h>
++#include <assert.h>
++#include <limits.h>
++#include <ctype.h>
++#include <errno.h>
++#include <unistd.h>
++#include <pthread.h>
++
++#include <gpgme.h>
++
++#include "t-support.h"
++
++struct op_result
++{
++ int done;
++ gpgme_error_t err;
++};
++
++static struct op_result op_result;
++
++struct one_fd
++{
++ int fd;
++ int dir;
++ gpgme_io_cb_t fnc;
++ void *fnc_data;
++};
++
++#define FDLIST_MAX 32
++static struct one_fd fdlist[FDLIST_MAX];
++
++static pthread_mutex_t lock;
++
++static gpgme_error_t
++add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc, void *fnc_data,
++ void **r_tag)
++{
++ struct one_fd *fds = data;
++ int i;
++
++ pthread_mutex_lock (&lock);
++ for (i = 0; i < FDLIST_MAX; i++)
++ {
++ if (fds[i].fd == -1)
++ {
++ fds[i].fd = fd;
++ fds[i].dir = dir;
++ fds[i].fnc = fnc;
++ fds[i].fnc_data = fnc_data;
++ break;
++ }
++ }
++ pthread_mutex_unlock (&lock);
++ if (i == FDLIST_MAX)
++ return gpgme_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_GENERAL);
++ *r_tag = &fds[i];
++ return 0;
++}
++
++static void
++remove_io_cb (void *tag)
++{
++ struct one_fd *fd = tag;
++
++ pthread_mutex_lock (&lock);
++ fd->fd = -1;
++ pthread_mutex_unlock (&lock);
++}
++
++static void
++io_event (void *data, gpgme_event_io_t type, void *type_data)
++{
++ struct op_result *result = data;
++
++ if (type == GPGME_EVENT_DONE)
++ {
++ result->done = 1;
++ result->err = * (gpgme_error_t *) type_data;
++ }
++}
++
++
++static int
++do_select (void)
++{
++ fd_set rfds;
++ fd_set wfds;
++ int i, n;
++ int any = 0;
++ struct timeval tv;
++
++ pthread_mutex_lock (&lock);
++ FD_ZERO (&rfds);
++ FD_ZERO (&wfds);
++ for (i = 0; i < FDLIST_MAX; i++)
++ if (fdlist[i].fd != -1)
++ FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds);
++ pthread_mutex_unlock (&lock);
++
++ tv.tv_sec = 0;
++ tv.tv_usec = 1000;
++
++ do
++ {
++ n = select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
++ }
++ while (n < 0 && errno == EINTR);
++
++ if (n < 0)
++ return n; /* Error or timeout. */
++
++ pthread_mutex_lock (&lock);
++ for (i = 0; i < FDLIST_MAX && n; i++)
++ {
++ if (fdlist[i].fd != -1)
++ {
++ if (FD_ISSET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds))
++ {
++ assert (n);
++ n--;
++ any = 1;
++ (*fdlist[i].fnc) (fdlist[i].fnc_data, fdlist[i].fd);
++ }
++ }
++ }
++ pthread_mutex_unlock (&lock);
++ return any;
++}
++
++static int
++my_wait (void)
++{
++ int n;
++
++ do
++ {
++ n = do_select ();
++ }
++ while (n >= 0 && !op_result.done);
++ return 0;
++}
++
++
++static struct gpgme_io_cbs io_cbs =
++ {
++ add_io_cb,
++ fdlist,
++ remove_io_cb,
++ io_event,
++ &op_result
++ };
++
++
++static void *
++thread_cancel (void *data)
++{
++ gpgme_ctx_t ctx = data;
++ gpgme_error_t err;
++
++ usleep (100000);
++ err = gpgme_cancel (ctx);
++ fail_if_err (err);
++
++ return NULL;
++}
++
++int
++main (void)
++{
++ gpgme_ctx_t ctx;
++ gpgme_error_t err;
++ gpgme_engine_info_t info;
++ int i;
++ pthread_mutexattr_t attr;
++ pthread_t tcancel;
++ const char *parms = "<GnupgKeyParms format=\"internal\">\n"
++ "Key-Type: RSA\n"
++ "Key-Length: 2048\n"
++ "Subkey-Type: RSA\n"
++ "Subkey-Length: 2048\n"
++ "Name-Real: Joe Tester\n"
++ "Name-Comment: (pp=abc)\n"
++ "Name-Email: joe at foo.bar\n"
++ "Expire-Date: 0\n"
++ "Passphrase: abc\n"
++ "</GnupgKeyParms>\n";
++
++ init_gpgme (GPGME_PROTOCOL_OpenPGP);
++
++ err = gpgme_get_engine_info (&info);
++ fail_if_err (err);
++
++ /* The mutex must be recursive, since remove_io_cb (which acquires a
++ lock) can be called while holding a lock acquired in do_select. */
++ pthread_mutexattr_init (&attr);
++ pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
++ pthread_mutex_init (&lock, &attr);
++ pthread_mutexattr_destroy (&attr);
++
++ for (i = 0; i < FDLIST_MAX; i++)
++ fdlist[i].fd = -1;
++
++ err = gpgme_new (&ctx);
++ fail_if_err (err);
++ gpgme_set_armor (ctx, 1);
++ gpgme_set_io_cbs (ctx, &io_cbs);
++ op_result.done = 0;
++
++ pthread_create (&tcancel, NULL, thread_cancel, ctx);
++
++ err = gpgme_op_genkey_start (ctx, parms, NULL, NULL);
++ fail_if_err (err);
++
++ my_wait ();
++
++ pthread_join (tcancel, NULL);
++
++ if (op_result.err)
++ {
++ if (gpgme_err_code (op_result.err) == GPG_ERR_CANCELED)
++ fputs ("Successfully cancelled\n", stdout);
++ else
++ {
++ fprintf (stderr,
++ "%s:%i: Operation finished with unexpected error: %s\n",
++ __FILE__, __LINE__, gpgme_strerror (op_result.err));
++ exit (1);
++ }
++ }
++ else
++ fputs ("Successfully finished before cancellation\n", stdout);
++
++ gpgme_release (ctx);
++
++ return 0;
++}
diff --git a/debian/patches/series b/debian/patches/series
index a45150a..8616548 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,5 @@
0001-avoid-identifying-as-beta.patch
+0002-doc-Fix-minor-errors-in-I-O-callback-example.patch
+0003-tests-Fix-select-usage-in-t-eventloop.patch
+0004-gpg-Add-option-exit-on-status-write-error.patch
+0005-tests-Add-test-for-cancellation.patch
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git
More information about the Pkg-gnupg-commit
mailing list