aboutsummaryrefslogtreecommitdiffstats
path: root/assuan
diff options
context:
space:
mode:
Diffstat (limited to 'assuan')
-rw-r--r--assuan/ChangeLog8
-rw-r--r--assuan/assuan-logging.c32
-rw-r--r--assuan/assuan-pipe-connect.c21
-rw-r--r--assuan/assuan.h9
4 files changed, 62 insertions, 8 deletions
diff --git a/assuan/ChangeLog b/assuan/ChangeLog
index ada72ffd..29e9ae24 100644
--- a/assuan/ChangeLog
+++ b/assuan/ChangeLog
@@ -1,3 +1,11 @@
+2007-08-02 Werner Koch <[email protected]>
+
+ * assuan-pipe-connect.c (pipe_connect_w32): A bit more debug output.
+ (pipe_connect_w32): Use DETACHED_PROCESS flag.
+ * assuan-logging.c (log_level): New. Use this to disable logging.
+ (assuan_set_assuan_log_level): New.
+ * assuan.h: Add prototype.
+
2007-07-12 Werner Koch <[email protected]>
* assuan-handler.c (assuan_get_active_fds): Use get_osfhandle for
diff --git a/assuan/assuan-logging.c b/assuan/assuan-logging.c
index 5d4f2bb1..41ada915 100644
--- a/assuan/assuan-logging.c
+++ b/assuan/assuan-logging.c
@@ -37,6 +37,23 @@
static char prefix_buffer[80];
static FILE *_assuan_log;
static int full_logging;
+static int log_level = 1; /* Defaults to logging enabled. */
+
+
+/* Set the log level for general assuan commands. 0 is no logging at
+ all, 1 is the standard logging and the default. Higher leveles may
+ be defined in the future. Passing a level of -1 will not change
+ the current log level. Returns previosu log level. */
+int
+assuan_set_assuan_log_level (int level)
+{
+ int old = log_level;
+
+ if (level != -1)
+ log_level = level;
+ return old;
+}
+
void
_assuan_set_default_log_stream (FILE *fp)
@@ -105,6 +122,9 @@ _assuan_log_printf (const char *format, ...)
FILE *fp;
const char *prf;
int save_errno = errno;
+
+ if (!log_level)
+ return;
fp = assuan_get_assuan_log_stream ();
prf = assuan_get_assuan_log_prefix ();
@@ -128,6 +148,9 @@ _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length)
const unsigned char *s;
int n;
+ if (!log_level)
+ return;
+
for (n=length,s=buffer; n; n--, s++)
if ((!isascii (*s) || iscntrl (*s) || !isprint (*s)) && !(*s >= 0x80))
break;
@@ -166,11 +189,16 @@ void
_assuan_log_sanitized_string (const char *string)
{
const unsigned char *s = (const unsigned char *) string;
- FILE *fp = assuan_get_assuan_log_stream ();
+ FILE *fp;
- if (! *s)
+ if (!log_level)
return;
+ if (!*s)
+ return;
+
+ fp = assuan_get_assuan_log_stream ();
+
#ifdef HAVE_FLOCKFILE
flockfile (fp);
#endif
diff --git a/assuan/assuan-pipe-connect.c b/assuan/assuan-pipe-connect.c
index 867dc84f..f21d850f 100644
--- a/assuan/assuan-pipe-connect.c
+++ b/assuan/assuan-pipe-connect.c
@@ -641,6 +641,9 @@ create_inheritable_pipe (int filedes[2], int for_write)
w = h;
}
+ _assuan_log_printf ("created pipe: read=%p%s, write=%p%s\n",
+ r, for_write? " (inherit)":"",
+ w, for_write? "":" (inherit)");
filedes[0] = handle_to_fd (r);
filedes[1] = handle_to_fd (w);
return 0;
@@ -752,6 +755,7 @@ pipe_connect_w32 (assuan_context_t *ctx,
nullfd = CreateFile ("nul", GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
+ _assuan_log_printf ("created nul device, hd=%p\n", nullfd);
if (nullfd == INVALID_HANDLE_VALUE)
{
_assuan_log_printf ("can't open `nul': %s\n", w32_strerror (-1));
@@ -772,14 +776,17 @@ pipe_connect_w32 (assuan_context_t *ctx,
/* Note: We inherit all handles flagged as inheritable. This seems
to be a security flaw but there seems to be no way of selecting
handles to inherit. */
- /* _assuan_log_printf ("CreateProcess, path=`%s' cmdline=`%s'\n", */
- /* name, cmdline); */
+ _assuan_log_printf ("CreateProcess, path=`%s' cmdline=`%s'\n",
+ name, cmdline);
+ _assuan_log_printf (" stdin=%p stdout=%p stderr=%p\n",
+ si.hStdInput, si.hStdOutput, si.hStdError);
if (!CreateProcess (name, /* Program to start. */
cmdline, /* Command line arguments. */
&sec_attr, /* Process security attributes. */
&sec_attr, /* Thread security attributes. */
TRUE, /* Inherit handles. */
(CREATE_DEFAULT_ERROR_MODE
+ | DETACHED_PROCESS
| GetPriorityClass (GetCurrentProcess ())
| CREATE_SUSPENDED), /* Creation flags. */
NULL, /* Environment. */
@@ -807,13 +814,15 @@ pipe_connect_w32 (assuan_context_t *ctx,
nullfd = INVALID_HANDLE_VALUE;
}
+ _assuan_log_printf ("closing handles %p and %p\n",
+ fd_to_handle (rp[1]), fd_to_handle (wp[0]) );
CloseHandle (fd_to_handle (rp[1]));
CloseHandle (fd_to_handle (wp[0]));
- /* _assuan_log_printf ("CreateProcess ready: hProcess=%p hThread=%p" */
- /* " dwProcessID=%d dwThreadId=%d\n", */
- /* pi.hProcess, pi.hThread, */
- /* (int) pi.dwProcessId, (int) pi.dwThreadId); */
+ _assuan_log_printf ("CreateProcess ready: hProcess=%p hThread=%p"
+ " dwProcessID=%d dwThreadId=%d\n",
+ pi.hProcess, pi.hThread,
+ (int) pi.dwProcessId, (int) pi.dwThreadId);
ResumeThread (pi.hThread);
CloseHandle (pi.hThread);
diff --git a/assuan/assuan.h b/assuan/assuan.h
index fd807959..cce9428b 100644
--- a/assuan/assuan.h
+++ b/assuan/assuan.h
@@ -137,6 +137,7 @@ int _gpgme_io_recvmsg (int sock, struct msghdr *msg, int flags);
#define assuan_sendfd _ASSUAN_PREFIX(assuan_sendfd)
#define assuan_receivefd _ASSUAN_PREFIX(assuan_receivefd)
#define assuan_set_malloc_hooks _ASSUAN_PREFIX(assuan_set_malloc_hooks)
+#define assuan_set_assuan_log_level _ASSUAN_PREFIX(assuan_set_assuan_log_level)
#define assuan_set_log_stream _ASSUAN_PREFIX(assuan_set_log_stream)
#define assuan_set_error _ASSUAN_PREFIX(assuan_set_error)
#define assuan_set_pointer _ASSUAN_PREFIX(assuan_set_pointer)
@@ -532,6 +533,14 @@ void assuan_set_assuan_err_source (int errsource);
/*-- assuan-logging.c --*/
+/* Set the log level for general assuan commands. 0 is no logging at
+ all, 1 is the standard logging and the default. Higher leveles may
+ be defined in the future. Passing a level of -1 will not change
+ the current log level. Returns previous log level. Note, that
+ this function is not thread-safe and should in general be used
+ right at startup. */
+int assuan_set_assuan_log_level (int level);
+
/* Set the stream to which assuan should log message not associated
with a context. By default, this is stderr. The default value
will be changed when the first log stream is associated with a