1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Initial port to Npth.

This commit is contained in:
Marcus Brinkmann 2011-09-29 03:14:37 +02:00
parent 6cf8890dc1
commit 2959e9e4d1
43 changed files with 1012 additions and 1058 deletions

View file

@ -1,3 +1,8 @@
2011-10-13 Marcus Brinkmann <marcus@g10code.com>
* estream.c, exechelp-posix.c, exechelp-w32.c, exechelp-w32ce.c,
http.c, init.c, sysutils.c: Port to NPth.
2011-08-10 Werner Koch <wk@g10code.com>
* t-exechelp.c (test_close_all_fds): Don't use the DUMMY_FD var.

View file

@ -106,22 +106,22 @@ else
common_sources += exechelp-posix.c
endif
# Sources only useful without PTH.
without_pth_sources = \
# Sources only useful without NPTH.
without_npth_sources = \
get-passphrase.c get-passphrase.h
libcommon_a_SOURCES = $(jnlib_sources) $(common_sources) $(without_pth_sources)
libcommon_a_SOURCES = $(jnlib_sources) $(common_sources) $(without_npth_sources)
if USE_DNS_SRV
libcommon_a_SOURCES += srv.c
endif
libcommon_a_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_CFLAGS) -DWITHOUT_GNU_PTH=1
libcommon_a_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_CFLAGS) -DWITHOUT_NPTH=1
libcommonpth_a_SOURCES = $(jnlib_sources) $(common_sources)
if USE_DNS_SRV
libcommonpth_a_SOURCES += srv.c
endif
libcommonpth_a_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_CFLAGS) $(PTH_CFLAGS)
libcommonpth_a_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_CFLAGS) $(NPTH_CFLAGS)
if !HAVE_W32CE_SYSTEM
libsimple_pwquery_a_SOURCES = \

View file

@ -85,13 +85,13 @@
# include <gpg-error.h> /* ERRNO replacement. */
#endif
#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */
# undef HAVE_PTH
# undef USE_GNU_PTH
#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
# undef HAVE_NPTH
# undef USE_NPTH
#endif
#ifdef HAVE_PTH
# include <pth.h>
#ifdef HAVE_NPTH
# include <npth.h>
#endif
/* This is for the special hack to use estream.c in GnuPG. */
@ -159,7 +159,7 @@ typedef void (*func_free_t) (void *mem);
/* Locking. */
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
typedef pth_mutex_t estream_mutex_t;
# define ESTREAM_MUTEX_INITIALIZER PTH_MUTEX_INIT
@ -197,7 +197,7 @@ dummy_mutex_call_int (estream_mutex_t mutex)
/* Primitive system I/O. */
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
# define ESTREAM_SYS_READ do_pth_read
# define ESTREAM_SYS_WRITE do_pth_write
# define ESTREAM_SYS_YIELD() pth_yield (NULL)
@ -438,7 +438,7 @@ do_list_remove (estream_t stream, int with_locked_list)
* write, assuming that we do I/O on a plain file where the operation
* can't block.
*/
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
static int
do_pth_read (int fd, void *buffer, size_t size)
{
@ -464,7 +464,7 @@ do_pth_write (int fd, const void *buffer, size_t size)
return pth_write (fd, buffer, size);
# endif /* !HAVE_W32_SYSTEM*/
}
#endif /*HAVE_PTH*/
#endif /*HAVE_NPTH*/
@ -495,7 +495,7 @@ do_init (void)
if (!initialized)
{
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
if (!pth_init () && errno != EPERM )
return -1;
if (pth_mutex_init (&estream_list_lock))
@ -983,7 +983,7 @@ es_func_w32_read (void *cookie, void *buffer, size_t size)
{
do
{
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
/* Note: Our pth_read actually uses HANDLE! */
bytes_read = pth_read ((int)w32_cookie->hd, buffer, size);
#else
@ -1028,7 +1028,7 @@ es_func_w32_write (void *cookie, const void *buffer, size_t size)
{
do
{
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
/* Note: Our pth_write actually uses HANDLE! */
bytes_written = pth_write ((int)w32_cookie->hd, buffer, size);
#else

View file

@ -35,13 +35,13 @@
#include <unistd.h>
#include <fcntl.h>
#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */
#undef HAVE_PTH
#undef USE_GNU_PTH
#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
#undef HAVE_NPTH
#undef USE_NPTH
#endif
#ifdef USE_GNU_PTH
#include <pth.h>
#ifdef USE_NPTH
#include <npth.h>
#endif
#include <sys/wait.h>
@ -388,11 +388,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
}
#ifdef USE_GNU_PTH
*pid = pth_fork? pth_fork () : fork ();
#else
*pid = fork ();
#endif
if (*pid == (pid_t)(-1))
{
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
@ -454,11 +450,7 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[],
{
gpg_error_t err;
#ifdef USE_GNU_PTH
*pid = pth_fork? pth_fork () : fork ();
#else
*pid = fork ();
#endif
if (*pid == (pid_t)(-1))
{
err = gpg_error_from_syserror ();
@ -491,16 +483,12 @@ gnupg_wait_process (const char *pgmname, pid_t pid, int hang, int *r_exitcode)
if (pid == (pid_t)(-1))
return gpg_error (GPG_ERR_INV_VALUE);
#ifdef USE_GNU_PTH
if (pth_waitpid)
i = pth_waitpid (pid, &status, hang? 0:WNOHANG);
else
#ifdef USE_NPTH
i = npth_waitpid (pid, &status, hang? 0:WNOHANG);
#else
while ((i=waitpid (pid, &status, hang? 0:WNOHANG)) == (pid_t)(-1)
&& errno == EINTR);
#endif
{
while ((i=waitpid (pid, &status, hang? 0:WNOHANG)) == (pid_t)(-1)
&& errno == EINTR)
;
}
if (i == (pid_t)(-1))
{
@ -569,11 +557,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
if (access (pgmname, X_OK))
return gpg_error_from_syserror ();
#ifdef USE_GNU_PTH
pid = pth_fork? pth_fork () : fork ();
#else
pid = fork ();
#endif
if (pid == (pid_t)(-1))
{
log_error (_("error forking process: %s\n"), strerror (errno));

View file

@ -35,13 +35,13 @@
#include <unistd.h>
#include <fcntl.h>
#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */
#undef HAVE_PTH
#undef USE_GNU_PTH
#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
#undef HAVE_NPTH
#undef USE_NPTH
#endif
#ifdef USE_GNU_PTH
#include <pth.h>
#ifdef USE_NPTH
#include <npth.h>
#endif
#ifdef HAVE_STAT

View file

@ -35,13 +35,13 @@
#include <unistd.h>
#include <fcntl.h>
#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */
#undef HAVE_PTH
#undef USE_GNU_PTH
#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
#undef HAVE_NPTH
#undef USE_NPTH
#endif
#ifdef USE_GNU_PTH
#include <pth.h>
#ifdef USE_NPTH
#include <npth.h>
#endif
#ifdef HAVE_STAT
@ -73,7 +73,7 @@
#define handle_to_pid(a) ((int)(a))
#ifdef USE_GNU_PTH
#ifdef USE_NPTH
/* The data passed to the feeder_thread. */
struct feeder_thread_parms
{
@ -171,9 +171,9 @@ leave:
xfree (parm);
return NULL;
}
#endif /*USE_GNU_PTH*/
#endif /*USE_NPTH*/
#ifdef USE_GNU_PTH
#ifdef USE_NPTH
static void
feeder_onclose_notification (estream_t stream, void *opaque)
{
@ -182,7 +182,7 @@ feeder_onclose_notification (estream_t stream, void *opaque)
log_debug ("feeder(%p): received onclose note\n", parm->hd);
parm->stream_valid = 0;
}
#endif /*USE_GNU_PTH*/
#endif /*USE_NPTH*/
/* Fire up a thread to copy data between STREAM and a pipe's
descriptor FD. With DIRECTION set to true the copy takes place
@ -191,7 +191,7 @@ feeder_onclose_notification (estream_t stream, void *opaque)
static gpg_error_t
start_feeder (estream_t stream, HANDLE hd, int direction)
{
#ifdef USE_GNU_PTH
#ifdef USE_NPTH
gpg_error_t err;
struct feeder_thread_parms *parm;
pth_attr_t tattr;

View file

@ -59,13 +59,13 @@
# include <netdb.h>
#endif /*!HAVE_W32_SYSTEM*/
#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */
# undef HAVE_PTH
# undef USE_GNU_PTH
#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
# undef HAVE_NPTH
# undef USE_NPTH
#endif
#ifdef HAVE_PTH
# include <pth.h>
#ifdef HAVE_NPTH
# include <npth.h>
#endif
@ -105,7 +105,7 @@ struct srventry
#endif/*!USE_DNS_SRV*/
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
# define my_select(a,b,c,d,e) pth_select ((a), (b), (c), (d), (e))
# define my_connect(a,b,c) pth_connect ((a), (b), (c))
# define my_accept(a,b,c) pth_accept ((a), (b), (c))
@ -1887,15 +1887,15 @@ write_server (int sock, const char *data, size_t length)
nleft = length;
while (nleft > 0)
{
#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_PTH)
#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_NPTH)
nwritten = send (sock, data, nleft, 0);
if ( nwritten == SOCKET_ERROR )
{
log_info ("network write failed: ec=%d\n", (int)WSAGetLastError ());
return gpg_error (GPG_ERR_NETWORK);
}
#else /*!HAVE_W32_SYSTEM || HAVE_PTH*/
# ifdef HAVE_PTH
#else /*!HAVE_W32_SYSTEM || HAVE_NPTH*/
# ifdef HAVE_NPTH
nwritten = pth_write (sock, data, nleft);
# else
nwritten = write (sock, data, nleft);
@ -1916,7 +1916,7 @@ write_server (int sock, const char *data, size_t length)
log_info ("network write failed: %s\n", strerror (errno));
return gpg_error_from_syserror ();
}
#endif /*!HAVE_W32_SYSTEM || HAVE_PTH*/
#endif /*!HAVE_W32_SYSTEM || HAVE_NPTH*/
nleft -= nwritten;
data += nwritten;
}
@ -1971,7 +1971,7 @@ cookie_read (void *cookie, void *buffer, size_t size)
{
do
{
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
nread = pth_read (c->sock->fd, buffer, size);
#elif defined(HAVE_W32_SYSTEM)
/* Under Windows we need to use recv for a socket. */

View file

@ -19,16 +19,16 @@
#include <config.h>
#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */
#undef HAVE_PTH
#undef USE_GNU_PTH
#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
#undef HAVE_NPTH
#undef USE_NPTH
#endif
#ifdef HAVE_W32_SYSTEM
#include <windows.h>
#endif
#ifdef HAVE_PTH
#include <pth.h>
#ifdef HAVE_NPTH
#include <npth.h>
#endif
#ifdef HAVE_W32CE_SYSTEM
# include <assuan.h> /* For _assuan_w32ce_finish_pipe. */
@ -87,7 +87,7 @@ init_common_subsystems (int *argcp, char ***argvp)
places. If we are building with PTH we let pth_init do it. We
can't do much on error so we ignore them. An error would anyway
later pop up if one of the socket functions is used. */
# ifdef HAVE_PTH
# ifdef HAVE_NPTH
pth_init ();
# else
{
@ -95,7 +95,7 @@ init_common_subsystems (int *argcp, char ***argvp)
WSAStartup (0x202, &wsadat);
}
# endif /*!HAVE_PTH*/
# endif /*!HAVE_NPTH*/
#endif
#ifdef HAVE_W32CE_SYSTEM

View file

@ -20,9 +20,9 @@
#include <config.h>
#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */
# undef HAVE_PTH
# undef USE_GNU_PTH
#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
# undef HAVE_NPTH
# undef USE_NPTH
#endif
#include <stdio.h>
@ -46,8 +46,8 @@
# define WINVER 0x0500 /* Required for AllowSetForegroundWindow. */
# include <windows.h>
#endif
#ifdef HAVE_PTH
# include <pth.h>
#ifdef HAVE_NPTH
# include <npth.h>
#endif
#include <fcntl.h>
@ -259,7 +259,7 @@ check_permissions(const char *path,int extension,int checkonly)
void
gnupg_sleep (unsigned int seconds)
{
#ifdef HAVE_PTH
#ifdef HAVE_NPTH
/* With Pth we force a regular sleep for seconds == 0 so that also
the process will give up its timeslot. */
if (!seconds)