[svn] assuan - r323 - trunk/src
svn author marcus
cvs at cvs.gnupg.org
Fri Nov 27 20:12:01 CET 2009
Author: marcus
Date: 2009-11-27 20:12:01 +0100 (Fri, 27 Nov 2009)
New Revision: 323
Modified:
trunk/src/ChangeLog
trunk/src/assuan-defs.h
trunk/src/assuan-listen.c
trunk/src/assuan-logging.c
trunk/src/assuan-pipe-connect.c
trunk/src/assuan-pipe-server.c
trunk/src/assuan-socket-connect.c
trunk/src/assuan-socket-server.c
trunk/src/assuan.h
trunk/src/context.c
trunk/src/libassuan.def
trunk/src/libassuan.vers
trunk/src/system.c
Log:
2009-11-27 Marcus Brinkmann <marcus at g10code.de>
* assuan.h (assuan_set_assuan_log_stream): Add prototype.
* libassuan.def, libassuan.vers: Add back
assuan_set_assuan_log_stream.
* assuan-logging.c (assuan_set_assuan_log_stream): Add back.
* context.c (assuan_get_pointer): Don't output debug info here.
(assuan_get_peercred, assuan_get_pid): But do here.
* system.c: Improve debug output.
* assuan-defs.h (struct assuan_context_s): Rename pipe_mode to
max_accepts.
* assuan-listen.c (assuan_accept): Rework max accepts logic.
* assuan-socket-server.c (assuan_init_socket_server),
assuan-socket-connect.c (assuan_socket_connect),
assuan-pipe-server.c (assuan_init_pipe_server),
assuan-pipe-connect.c (socketpair_connect): Add debug output, set
max_accepts instead of pipe_mode.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/ChangeLog 2009-11-27 19:12:01 UTC (rev 323)
@@ -1,3 +1,21 @@
+2009-11-27 Marcus Brinkmann <marcus at g10code.de>
+
+ * assuan.h (assuan_set_assuan_log_stream): Add prototype.
+ * libassuan.def, libassuan.vers: Add back
+ assuan_set_assuan_log_stream.
+ * assuan-logging.c (assuan_set_assuan_log_stream): Add back.
+ * context.c (assuan_get_pointer): Don't output debug info here.
+ (assuan_get_peercred, assuan_get_pid): But do here.
+ * system.c: Improve debug output.
+ * assuan-defs.h (struct assuan_context_s): Rename pipe_mode to
+ max_accepts.
+ * assuan-listen.c (assuan_accept): Rework max accepts logic.
+ * assuan-socket-server.c (assuan_init_socket_server),
+ assuan-socket-connect.c (assuan_socket_connect),
+ assuan-pipe-server.c (assuan_init_pipe_server),
+ assuan-pipe-connect.c (socketpair_connect): Add debug output, set
+ max_accepts instead of pipe_mode.
+
2009-11-25 Marcus Brinkmann <marcus at g10code.de>
* assuan.h (assuan_init_pipe_server): Change type of filedes to
Modified: trunk/src/assuan-defs.h
===================================================================
--- trunk/src/assuan-defs.h 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/assuan-defs.h 2009-11-27 19:12:01 UTC (rev 323)
@@ -164,8 +164,8 @@
} data;
} outbound;
- int pipe_mode; /* We are in pipe mode, i.e. we can handle just one
- connection and must terminate then. */
+ int max_accepts; /* If we can not handle more than one connection,
+ set this to 1, otherwise to -1. */
pid_t pid; /* The pid of the peer. */
assuan_fd_t listen_fd; /* The fd we are listening on (used by
socket servers) */
Modified: trunk/src/assuan-listen.c
===================================================================
--- trunk/src/assuan-listen.c 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/assuan-listen.c 2009-11-27 19:12:01 UTC (rev 323)
@@ -78,12 +78,16 @@
if (!ctx)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
- if (ctx->pipe_mode > 1)
- return -1; /* second invocation for pipemode -> terminate */
- if (! ctx->pipe_mode)
+ if (ctx->max_accepts != -1)
{
+ if (ctx->max_accepts-- == 0)
+ return -1; /* second invocation for pipemode -> terminate */
+ }
+ if (ctx->accept_handler)
+ {
+ /* FIXME: This should be superfluous, if everything else is
+ correct. */
ctx->finish_handler (ctx);
-
rc = ctx->accept_handler (ctx);
if (rc)
return rc;
@@ -111,10 +115,7 @@
rc = assuan_write_line (ctx, "OK Pleased to meet you");
if (rc)
return rc;
-
- if (ctx->pipe_mode)
- ctx->pipe_mode = 2;
-
+
return 0;
}
Modified: trunk/src/assuan-logging.c
===================================================================
--- trunk/src/assuan-logging.c 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/assuan-logging.c 2009-11-27 19:12:01 UTC (rev 323)
@@ -45,6 +45,16 @@
static int full_logging;
+static FILE *_assuan_log;
+
+void
+assuan_set_assuan_log_stream (FILE *fp)
+{
+ _assuan_log = fp;
+ full_logging = !!getenv ("ASSUAN_FULL_LOGGING");
+}
+
+
/* Set the per context log stream. Also enable the default log stream
if it has not been set. */
void
@@ -96,7 +106,7 @@
if (msg == NULL)
return 1;
- fp = ctx->log_fp;
+ fp = ctx->log_fp ? ctx->log_fp : _assuan_log;
if (!fp)
return 0;
Modified: trunk/src/assuan-pipe-connect.c
===================================================================
--- trunk/src/assuan-pipe-connect.c 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/assuan-pipe-connect.c 2009-11-27 19:12:01 UTC (rev 323)
@@ -196,7 +196,8 @@
ctx->engine.sendfd = NULL;
ctx->engine.receivefd = NULL;
ctx->finish_handler = _assuan_client_finish;
- ctx->pipe_mode = 1;
+ ctx->max_accepts = 1;
+ ctx->accept_handler = NULL;
ctx->inbound.fd = rp[0]; /* Our inbound is read end of read pipe. */
ctx->outbound.fd = wp[1]; /* Our outbound is write end of write pipe. */
ctx->pid = pid;
@@ -341,7 +342,7 @@
ctx->engine.release = _assuan_client_release;
ctx->finish_handler = _assuan_client_finish;
- ctx->pipe_mode = 1;
+ ctx->max_accepts = 1;
ctx->inbound.fd = fds[0];
ctx->outbound.fd = fds[0];
_assuan_init_uds_io (ctx);
@@ -390,8 +391,8 @@
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags)
{
- TRACE2 (ctx, ASSUAN_LOG_CTX, "assuan_pipe_connect_ext", ctx,
- "name=%s,flags=0x%x", name ? name : "(null)", flags);
+ TRACE2 (ctx, ASSUAN_LOG_CTX, "assuan_pipe_connect", ctx,
+ "name=%s, flags=0x%x", name ? name : "(null)", flags);
if (flags & ASSUAN_PIPE_CONNECT_FDPASSING)
{
Modified: trunk/src/assuan-pipe-server.c
===================================================================
--- trunk/src/assuan-pipe-server.c 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/assuan-pipe-server.c 2009-11-27 19:12:01 UTC (rev 323)
@@ -32,8 +32,8 @@
#endif
#include "assuan-defs.h"
+#include "debug.h"
-
/* Returns true if atoi(S) denotes a valid socket. */
#ifndef HAVE_W32_SYSTEM
static int
@@ -59,10 +59,12 @@
assuan_fd_t infd = ASSUAN_INVALID_FD;
assuan_fd_t outfd = ASSUAN_INVALID_FD;
int is_usd = 0;
+ TRACE_BEG2 (ctx, ASSUAN_LOG_CTX, "assuan_init_pipe_server", ctx,
+ "fd[0]=0x%x, fd[1]=0x%x", filedes[0], filedes[1]);
rc = _assuan_register_std_commands (ctx);
if (rc)
- return rc;
+ return TRACE_ERR (rc);
#ifdef HAVE_W32_SYSTEM
infd = filedes[0];
@@ -87,7 +89,10 @@
outfd = filedes[1];
}
else
- return _assuan_error (ctx, GPG_ERR_ASS_SERVER_START);
+ {
+ rc = _assuan_error (ctx, GPG_ERR_ASS_SERVER_START);
+ return TRACE_ERR (rc);
+ }
#endif
ctx->is_server = 1;
@@ -96,7 +101,7 @@
ctx->engine.writefnc = _assuan_simple_write;
ctx->engine.sendfd = NULL;
ctx->engine.receivefd = NULL;
- ctx->pipe_mode = 1;
+ ctx->max_accepts = 1;
s = getenv ("_assuan_pipe_connect_pid");
if (s && (ul=strtoul (s, NULL, 10)) && ul)
@@ -111,5 +116,5 @@
if (is_usd)
_assuan_init_uds_io (ctx);
- return 0;
+ return TRACE_SUC();
}
Modified: trunk/src/assuan-socket-connect.c
===================================================================
--- trunk/src/assuan-socket-connect.c 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/assuan-socket-connect.c 2009-11-27 19:12:01 UTC (rev 323)
@@ -67,6 +67,8 @@
size_t len;
const char *s;
+ TRACE2 (ctx, ASSUAN_LOG_CTX, "assuan_socket_connect", ctx,
+ "name=%s, flags=0x%x", name ? name : "(null)", flags);
if (!ctx || !name)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
@@ -115,6 +117,7 @@
ctx->finish_handler = _assuan_client_finish;
ctx->inbound.fd = fd;
ctx->outbound.fd = fd;
+ ctx->max_accepts = -1;
if (flags & ASSUAN_SOCKET_CONNECT_FDPASSING)
_assuan_init_uds_io (ctx);
Modified: trunk/src/assuan-socket-server.c
===================================================================
--- trunk/src/assuan-socket-server.c 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/assuan-socket-server.c 2009-11-27 19:12:01 UTC (rev 323)
@@ -38,7 +38,7 @@
# include <sys/un.h>
#endif
-
+#include "debug.h"
#include "assuan-defs.h"
static gpg_error_t
@@ -116,10 +116,12 @@
unsigned int flags)
{
gpg_error_t rc;
-
+ TRACE_BEG2 (ctx, ASSUAN_LOG_CTX, "assuan_init_socket_server", ctx,
+ "fd=0x%x, flags=0x%x", fd, flags);
+
rc = _assuan_register_std_commands (ctx);
if (rc)
- return rc;
+ return TRACE_ERR (rc);
ctx->engine.release = _assuan_server_release;
ctx->engine.readfnc = _assuan_simple_read;
@@ -128,7 +130,10 @@
ctx->engine.receivefd = NULL;
ctx->is_server = 1;
if (flags & ASSUAN_SOCKET_SERVER_ACCEPTED)
- ctx->pipe_mode = 1; /* We want a second accept to indicate EOF. */
+ /* We want a second accept to indicate EOF. */
+ ctx->max_accepts = 1;
+ else
+ ctx->max_accepts = -1;
ctx->input_fd = ASSUAN_INVALID_FD;
ctx->output_fd = ASSUAN_INVALID_FD;
@@ -156,7 +161,7 @@
rc = _assuan_register_std_commands (ctx);
if (rc)
_assuan_reset (ctx);
- return rc;
+ return TRACE_ERR (rc);
}
Modified: trunk/src/assuan.h
===================================================================
--- trunk/src/assuan.h 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/assuan.h 2009-11-27 19:12:01 UTC (rev 323)
@@ -298,6 +298,9 @@
string, i.e. "" */
const char *assuan_get_assuan_log_prefix (void);
+/* Global default log stream. */
+void assuan_set_assuan_log_stream (FILE *fp);
+
/* Set the per context log stream for the default log handler. */
void assuan_set_log_stream (assuan_context_t ctx, FILE *fp);
Modified: trunk/src/context.c
===================================================================
--- trunk/src/context.c 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/context.c 2009-11-27 19:12:01 UTC (rev 323)
@@ -42,8 +42,11 @@
void *
assuan_get_pointer (assuan_context_t ctx)
{
+#if 0
+ /* This is called often. */
TRACE1 (ctx, ASSUAN_LOG_CTX, "assuan_get_pointer", ctx,
"ctx->user_pointer=%p", ctx ? ctx->user_pointer : NULL);
+#endif
if (! ctx)
return NULL;
@@ -177,6 +180,9 @@
pid_t
assuan_get_pid (assuan_context_t ctx)
{
+ TRACE1 (ctx, ASSUAN_LOG_CTX, "assuan_get_pid", ctx,
+ "pid=%i", ctx ? ctx->pid : -1);
+
return (ctx && ctx->pid) ? ctx->pid : ASSUAN_INVALID_PID;
}
@@ -186,6 +192,8 @@
gpg_error_t
assuan_get_peercred (assuan_context_t ctx, assuan_peercred_t *peercred)
{
+ TRACE (ctx, ASSUAN_LOG_CTX, "assuan_get_peercred", ctx);
+
if (!ctx)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
if (!ctx->peercred_valid)
Modified: trunk/src/libassuan.def
===================================================================
--- trunk/src/libassuan.def 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/libassuan.def 2009-11-27 19:12:01 UTC (rev 323)
@@ -64,35 +64,36 @@
assuan_send_data @43
assuan_sendfd @44
assuan_set_assuan_log_prefix @45
- assuan_set_error @46
- assuan_set_flag @47
- assuan_set_gpg_err_source @48
- assuan_set_hello_line @49
- assuan_set_io_monitor @50
- assuan_set_log_cb @51
- assuan_set_log_stream @52
- assuan_set_malloc_hooks @53
- assuan_set_okay_line @54
- assuan_set_pointer @55
- assuan_set_system_hooks @56
- assuan_sock_bind @57
- assuan_sock_check_nonce @58
- assuan_sock_close @59
- assuan_sock_connect @60
- assuan_sock_deinit @61
- assuan_sock_get_nonce @62
- assuan_sock_init @63
- assuan_sock_new @64
- assuan_socket_connect @65
- assuan_transact @66
- assuan_write_line @67
- assuan_write_status @68
- __assuan_close @69
- __assuan_pipe @70
- __assuan_socketpair @71
- __assuan_spawn @72
- __assuan_usleep @73
- assuan_fdopen @74
+ assuan_set_assuan_log_stream @46
+ assuan_set_error @47
+ assuan_set_flag @48
+ assuan_set_gpg_err_source @49
+ assuan_set_hello_line @50
+ assuan_set_io_monitor @51
+ assuan_set_log_cb @52
+ assuan_set_log_stream @53
+ assuan_set_malloc_hooks @54
+ assuan_set_okay_line @55
+ assuan_set_pointer @56
+ assuan_set_system_hooks @57
+ assuan_sock_bind @58
+ assuan_sock_check_nonce @59
+ assuan_sock_close @60
+ assuan_sock_connect @61
+ assuan_sock_deinit @62
+ assuan_sock_get_nonce @63
+ assuan_sock_init @64
+ assuan_sock_new @65
+ assuan_socket_connect @66
+ assuan_transact @67
+ assuan_write_line @68
+ assuan_write_status @69
+ __assuan_close @70
+ __assuan_pipe @71
+ __assuan_socketpair @72
+ __assuan_spawn @73
+ __assuan_usleep @74
+ assuan_fdopen @75
; END
Modified: trunk/src/libassuan.vers
===================================================================
--- trunk/src/libassuan.vers 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/libassuan.vers 2009-11-27 19:12:01 UTC (rev 323)
@@ -70,6 +70,7 @@
assuan_send_data;
assuan_sendfd;
assuan_set_assuan_log_prefix;
+ assuan_set_assuan_log_stream;
assuan_set_error;
assuan_set_flag;
assuan_set_gpg_err_source;
Modified: trunk/src/system.c
===================================================================
--- trunk/src/system.c 2009-11-25 17:55:26 UTC (rev 322)
+++ trunk/src/system.c 2009-11-27 19:12:01 UTC (rev 323)
@@ -192,9 +192,6 @@
HANDLE wh;
HANDLE th;
SECURITY_ATTRIBUTES sec_attr;
- TRACE_BEG2 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx,
- "inherit_idx=%i (Assuan uses it for %s)",
- inherit_idx, inherit_idx ? "reading" : "writing");
memset (&sec_attr, 0, sizeof (sec_attr));
sec_attr.nLength = sizeof (sec_attr);
@@ -202,20 +199,22 @@
if (! CreatePipe (&rh, &wh, &sec_attr, 0))
{
- TRACE_LOG1 ("CreatePipe failed: %s", _assuan_w32_strerror (ctx, -1));
+ TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx,
+ "CreatePipe failed: %s", _assuan_w32_strerror (ctx, -1));
errno = EIO;
- return TRACE_SYSRES (-1);
+ return -1;
}
if (! DuplicateHandle (GetCurrentProcess(), (inherit_idx == 0) ? rh : wh,
GetCurrentProcess(), &th, 0,
TRUE, DUPLICATE_SAME_ACCESS ))
{
- TRACE_LOG1 ("DuplicateHandle failed: %s", _assuan_w32_strerror (ctx, -1));
+ TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx,
+ "DuplicateHandle failed: %s", _assuan_w32_strerror (ctx, -1));
CloseHandle (rh);
CloseHandle (wh);
errno = EIO;
- return TRACE_SYSRES (-1);
+ return -1;
}
if (inherit_idx == 0)
{
@@ -231,7 +230,7 @@
fd[0] = rh;
fd[1] = wh;
- return TRACE_SUC ();
+ return 0;
#else
return pipe (fd);
#endif
@@ -242,7 +241,16 @@
int
_assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx)
{
- return (ctx->system.pipe) (ctx, fd, inherit_idx);
+ int err;
+ TRACE_BEG2 (ctx, ASSUAN_LOG_SYSIO, "_assuan_pipe", ctx,
+ "inherit_idx=%i (Assuan uses it for %s)",
+ inherit_idx, inherit_idx ? "reading" : "writing");
+
+ err = (ctx->system.pipe) (ctx, fd, inherit_idx);
+ if (err)
+ return TRACE_SYSRES (err);
+
+ return TRACE_SUC2 ("read=0x%x, write=0x%x", fd[0], fd[1]);
}
@@ -341,7 +349,15 @@
ssize_t
_assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size)
{
+#if 0
+ ssize_t res;
+ TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "_assuan_read", ctx,
+ "fd=0x%x, buffer=%p, size=%i", fd, buffer, size);
+ res = (ctx->system.read) (ctx, fd, buffer, size);
+ return TRACE_SYSRES (res);
+#else
return (ctx->system.read) (ctx, fd, buffer, size);
+#endif
}
@@ -390,7 +406,15 @@
_assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer,
size_t size)
{
+#if 0
+ ssize_t res;
+ TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "_assuan_write", ctx,
+ "fd=0x%x, buffer=%p, size=%i", fd, buffer, size);
+ res = (ctx->system.write) (ctx, fd, buffer, size);
+ return TRACE_SYSRES (res);
+#else
return (ctx->system.write) (ctx, fd, buffer, size);
+#endif
}
More information about the Gnupg-commits
mailing list