From 74b3256bc5be38a17439afb941ade1e6e08533dc Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Mon, 6 Oct 2003 16:17:13 +0000 Subject: [PATCH] doc/ 2003-10-06 Marcus Brinkmann * gpgme.texi (Signal Handling): New section. gpgme/ 2003-10-06 Marcus Brinkmann * io.h (_gpgme_io_subsystem_init): New prototype. * posix-io.c (_gpgme_io_subsystem_init): Add function. (_gpgme_io_spawn): Do not fixup signal handler here. * version.c (do_subsystem_inits): Call _gpgme_io_subsystem_init. tests/ 2003-10-06 Marcus Brinkmann * gpg/t-thread1.c (thread_one): Do not call initialize_gpgme. Likewise. --- trunk/assuan/README.1st | 3 +++ trunk/assuan/assuan-pipe-connect.c | 4 ++++ trunk/doc/ChangeLog | 4 ++++ trunk/doc/gpgme.texi | 30 +++++++++++++++++++++++++ trunk/gpgme/ChangeLog | 5 +++++ trunk/gpgme/io.h | 1 + trunk/gpgme/posix-io.c | 35 +++++++++++++++--------------- trunk/gpgme/version.c | 2 ++ trunk/tests/ChangeLog | 5 +++++ trunk/tests/gpg/t-thread1.c | 5 +---- 10 files changed, 72 insertions(+), 22 deletions(-) diff --git a/trunk/assuan/README.1st b/trunk/assuan/README.1st index 7b6074f..6e8d4ec 100644 --- a/trunk/assuan/README.1st +++ b/trunk/assuan/README.1st @@ -20,3 +20,6 @@ updating this directory, are: * assuan-io.c ** Don't try to support GNU Pth here. + +* assuan-pipe-connect.c +** Do not install SIGPIPE signal handler here. diff --git a/trunk/assuan/assuan-pipe-connect.c b/trunk/assuan/assuan-pipe-connect.c index d30c106..a3ddc22 100644 --- a/trunk/assuan/assuan-pipe-connect.c +++ b/trunk/assuan/assuan-pipe-connect.c @@ -102,7 +102,9 @@ AssuanError assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], int *fd_child_list) { +#ifndef _ASSUAN_IN_GPGME static int fixed_signals = 0; +#endif AssuanError err; int rp[2]; int wp[2]; @@ -110,6 +112,7 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], if (!ctx || !name || !argv || !argv[0]) return ASSUAN_Invalid_Value; +#ifndef _ASSUAN_IN_GPGME if (!fixed_signals) { struct sigaction act; @@ -125,6 +128,7 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], fixed_signals = 1; /* FIXME: This is not MT safe */ } +#endif if (pipe (rp) < 0) return ASSUAN_General_Error; diff --git a/trunk/doc/ChangeLog b/trunk/doc/ChangeLog index de523fe..0064e2d 100644 --- a/trunk/doc/ChangeLog +++ b/trunk/doc/ChangeLog @@ -1,3 +1,7 @@ +2003-10-06 Marcus Brinkmann + + * gpgme.texi (Signal Handling): New section. + 2003-09-14 Marcus Brinkmann * gpgme.texi (Multi Threading): Correct documentation on memory diff --git a/trunk/doc/gpgme.texi b/trunk/doc/gpgme.texi index c76916e..4809454 100644 --- a/trunk/doc/gpgme.texi +++ b/trunk/doc/gpgme.texi @@ -107,6 +107,7 @@ Preparation * Using Automake:: Compiler options to be used the easy way. * Using Libtool:: Avoiding compiler options entirely. * Library Version Check:: Getting and verifying the library version. +* Signal Handling:: How @acronym{GPGME} affects signal handling. * Multi Threading:: How @acronym{GPGME} can be used in an MT environment. Protocols and Engines @@ -322,6 +323,7 @@ of the library are verified. * Using Automake:: Compiler options to be used the easy way. * Using Libtool:: Avoiding compiler options entirely. * Library Version Check:: Getting and verifying the library version. +* Signal Handling:: How @acronym{GPGME} affects signal handling. * Multi Threading:: How @acronym{GPGME} can be used in an MT environment. @end menu @@ -518,6 +520,34 @@ like this. @acronym{GPGME} can not do this for you because it would not be thread safe. +@node Signal Handling +@section Signal Handling +@cindex signals +@cindex signal handling + +The @acronym{GPGME} library communicates with child processes (the +crypto engines). If a child process dies unexpectedly, for example +due to a bug, or system problem, a @code{SIGPIPE} signal will be +delivered to the application. The default action is to abort the +program. To protect against this, @code{gpgme_check_version} sets the +@code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the +signal will be ignored. + +@acronym{GPGME} will only do that if the signal action for +@code{SIGPIPE} is @code{SIG_DEF} at the time +@code{gpgme_check_version} is called. If it is something different, +@code{GPGME} will take no action. + +This means that if your application does not install any signal +handler for @code{SIGPIPE}, you don't need to take any precautions. +If you do install a signal handler for @code{SIGPIPE}, you must be +prepared to handle any @code{SIGPIPE} events that occur due to +@acronym{GPGME} writing to a defunct pipe. Furthermore, if your +application is multi-threaded, and you install a signal action for +@code{SIGPIPE}, you must make sure you do this either before +@code{gpgme_check_version} is called or afterwards. + + @node Multi Threading @section Multi Threading @cindex thread-safeness diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index 18552f6..d2b82bd 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,5 +1,10 @@ 2003-10-06 Marcus Brinkmann + * io.h (_gpgme_io_subsystem_init): New prototype. + * posix-io.c (_gpgme_io_subsystem_init): Add function. + (_gpgme_io_spawn): Do not fixup signal handler here. + * version.c (do_subsystem_inits): Call _gpgme_io_subsystem_init. + * debug.c (debug_init): Drop const qualifier from E. * ath.h (struct ath_ops): Make ADDR argument of CONNECT prototype diff --git a/trunk/gpgme/io.h b/trunk/gpgme/io.h index cb09969..9cc5eb2 100644 --- a/trunk/gpgme/io.h +++ b/trunk/gpgme/io.h @@ -40,6 +40,7 @@ struct io_select_fd_s }; /* These function are either defined in posix-io.c or w32-io.c. */ +void _gpgme_io_subsystem_init (void); int _gpgme_io_read (int fd, void *buffer, size_t count); int _gpgme_io_write (int fd, const void *buffer, size_t count); int _gpgme_io_pipe (int filedes[2], int inherit_idx); diff --git a/trunk/gpgme/posix-io.c b/trunk/gpgme/posix-io.c index 5034468..5c9baac 100644 --- a/trunk/gpgme/posix-io.c +++ b/trunk/gpgme/posix-io.c @@ -39,6 +39,23 @@ #include "ath.h" #include "debug.h" + +void +_gpgme_io_subsystem_init (void) +{ + struct sigaction act; + + sigaction (SIGPIPE, NULL, &act); + if (act.sa_handler == SIG_DFL) + { + act.sa_handler = SIG_IGN; + sigemptyset (&act.sa_mask); + act.sa_flags = 0; + sigaction (SIGPIPE, &act, NULL); + } +} + + static struct { void (*handler) (int,void*); @@ -162,27 +179,9 @@ _gpgme_io_spawn (const char *path, char **argv, struct spawn_fd_item_s *fd_child_list, struct spawn_fd_item_s *fd_parent_list) { - static int fixed_signals; - DEFINE_STATIC_LOCK (fixed_signals_lock); pid_t pid; int i; int status, signo; - LOCK (fixed_signals_lock); - if (!fixed_signals) - { - struct sigaction act; - - sigaction (SIGPIPE, NULL, &act); - if (act.sa_handler == SIG_DFL) - { - act.sa_handler = SIG_IGN; - sigemptyset (&act.sa_mask); - act.sa_flags = 0; - sigaction (SIGPIPE, &act, NULL); - } - fixed_signals = 1; - } - UNLOCK (fixed_signals_lock); pid = fork (); if (pid == -1) diff --git a/trunk/gpgme/version.c b/trunk/gpgme/version.c index d64e67a..e2c4ef8 100644 --- a/trunk/gpgme/version.c +++ b/trunk/gpgme/version.c @@ -46,6 +46,8 @@ do_subsystem_inits (void) return; _gpgme_sema_subsystem_init (); + _gpgme_io_subsystem_init (); + done = 1; } diff --git a/trunk/tests/ChangeLog b/trunk/tests/ChangeLog index 0125667..e48dd6f 100644 --- a/trunk/tests/ChangeLog +++ b/trunk/tests/ChangeLog @@ -1,3 +1,8 @@ +2003-10-06 Marcus Brinkmann + + * gpg/t-thread1.c (thread_one): Do not call initialize_gpgme. + Likewise. + 2003-09-14 Marcus Brinkmann * gpg/t-thread1.c (main): Call init_gpgme here. diff --git a/trunk/tests/gpg/t-thread1.c b/trunk/tests/gpg/t-thread1.c index 4c003b1..5054974 100644 --- a/trunk/tests/gpg/t-thread1.c +++ b/trunk/tests/gpg/t-thread1.c @@ -37,8 +37,6 @@ thread_one (void *name) { int i; - initialize_gpgme (); - for (i = 0; i < ROUNDS; i++) { gpgme_ctx_t ctx; @@ -89,7 +87,6 @@ void * thread_two (void *name) { int i; - initialize_gpgme (); const char *cipher_1_asc = make_filename ("cipher-1.asc"); char *agent_info; @@ -143,7 +140,7 @@ main (int argc, char *argv[]) init_gpgme (GPGME_PROTOCOL_OpenPGP); pthread_create (&tone, NULL, thread_one, "A"); - pthread_create (&ttwo, NULL, thread_two, "A"); + pthread_create (&ttwo, NULL, thread_two, "B"); pthread_join (tone, NULL); pthread_join (ttwo, NULL); -- 2.26.2