Add a bit more tracing.
+2007-09-28 Werner Koch <wk@g10code.com>
+
+ * w32-glib-io.c (find_channel): Add a new primary flag.
+ (_gpgme_io_close): Close channel only if primary.
+ (_gpgme_io_dup): Put newfd into the table as shallow copy.
+
+ * priv-io.h (struct io_select_fd_s): Remove member FROZEN.
+ * w32-io.c (_gpgme_io_select): Ditto.
+ * w32-glib-io.c (_gpgme_io_select): Ditto.
+
+ * posix-io.c (_gpgme_io_select): Ditto.
+ * rungpg.c (read_status): Ditto.
+ * wait.c (fd_table_put): Ditto.
+
+ * rungpg.c (gpg_io_event): Add tracing.
+ (start): Use gpg_io_event for sending the start event.
+ * engine-gpgsm.c (gpgsm_io_event): Add tracing.
+ (start): Use gpgsm_io_event for sending the start event.
+ * wait.c (_gpgme_add_io_cb, _gpgme_run_io_cb): Add tracing.
+
2007-09-28 Marcus Brinkmann <marcus@g10code.de>
* kdpipeiodevice.moc, w32-qt-io.cpp, kdpipeiodevice.cpp: New
typedef struct engine_gpgsm *engine_gpgsm_t;
+
+static void gpgsm_io_event (void *engine,
+ gpgme_event_io_t type, void *type_data);
+
+
\f
static char *
gpgsm_get_version (const char *file_name)
gpgsm->colon.any = 0;
err = gpgsm->colon.fnc (gpgsm->colon.fnc_value, NULL);
}
- _gpgme_io_close (gpgsm->status_cb.fd);
TRACE2 (DEBUG_CTX, "gpgme:status_handler", gpgsm,
"fd 0x%x: OK line - final status: %s",
fd, err ? gpg_strerror (err) : "ok");
+ _gpgme_io_close (gpgsm->status_cb.fd);
return err;
}
else if (linelen > 2
{
gpgme_error_t err;
+ TRACE_BEG2 (DEBUG_ENGINE, "engine-gpgsm:add_io_cb", gpgsm,
+ "fd %d, dir %d", iocbd->fd, iocbd->dir);
err = (*gpgsm->io_cbs.add) (gpgsm->io_cbs.add_priv,
iocbd->fd, iocbd->dir,
handler, iocbd->data, &iocbd->tag);
if (err)
- return err;
+ return TRACE_ERR (err);
if (!iocbd->dir)
/* FIXME Kludge around poll() problem. */
err = _gpgme_io_set_nonblocking (iocbd->fd);
- return err;
+ return TRACE_ERR (err);
}
err = map_assuan_error (assuan_write_line (gpgsm->assuan_ctx, command));
if (!err)
- (*gpgsm->io_cbs.event) (gpgsm->io_cbs.event_priv, GPGME_EVENT_START, NULL);
+ gpgsm_io_event (gpgsm, GPGME_EVENT_START, NULL);
return err;
}
{
engine_gpgsm_t gpgsm = engine;
+ TRACE3 (DEBUG_ENGINE, "gpgme:gpgsm_io_event", gpgsm,
+ "event %p, type %d, type_data %p",
+ gpgsm->io_cbs.event, type, type_data);
if (gpgsm->io_cbs.event)
(*gpgsm->io_cbs.event) (gpgsm->io_cbs.event_priv, type, type_data);
}
AM_PATH_GPGME macro) check that this header matches the installed
library. Warning: Do not edit the next line. configure will do
that for you! */
-#define GPGME_VERSION "1.1.6-svn1264"
+#define GPGME_VERSION "1.1.6-svn1258"
\f
{
if (fds[i].fd == -1)
continue;
- if (fds[i].frozen)
- TRACE_ADD1 (dbg_help, "f0x%x ", fds[i].fd);
- else if (fds[i].for_read)
+ if (fds[i].for_read)
{
assert (!FD_ISSET (fds[i].fd, &readfds));
FD_SET (fds[i].fd, &readfds);
int for_read;
int for_write;
int signaled;
- int frozen;
void *opaque;
};
{
engine_gpg_t gpg = engine;
+ TRACE3 (DEBUG_ENGINE, "gpgme:gpg_io_event", gpg,
+ "event %p, type %d, type_data %p",
+ gpg->io_cbs.event, type, type_data);
if (gpg->io_cbs.event)
(*gpg->io_cbs.event) (gpg->io_cbs.event_priv, type, type_data);
}
gpg->fd_data_map[gpg->cmd.linked_idx].fd;
fds.for_read = 1;
fds.for_write = 0;
- fds.frozen = 0;
fds.opaque = NULL;
do
{
}
}
- (*gpg->io_cbs.event) (gpg->io_cbs.event_priv, GPGME_EVENT_START, NULL);
+ gpg_io_event (gpg, GPGME_EVENT_START, NULL);
/* fixme: check what data we can release here */
return 0;
\f
#define MAX_SLAFD 256
-GIOChannel *giochannel_table[MAX_SLAFD];
+static struct
+{
+ GIOChannel *chan;
+ int primary; /* Set if CHAN is the one we used to create the channel. */
+} giochannel_table[MAX_SLAFD];
static GIOChannel *
if (fd < 0 || fd >= MAX_SLAFD)
return NULL;
- if (create && !giochannel_table[fd])
+ if (create && !giochannel_table[fd].chan)
{
- giochannel_table[fd] = g_io_channel_win32_new_fd (fd);
- g_io_channel_set_encoding (giochannel_table[fd], NULL, NULL);
- g_io_channel_set_buffered (giochannel_table[fd], FALSE);
+ giochannel_table[fd].chan = g_io_channel_win32_new_fd (fd);
+ giochannel_table[fd].primary = 1;
+ g_io_channel_set_encoding (giochannel_table[fd].chan, NULL, NULL);
+ g_io_channel_set_buffered (giochannel_table[fd].chan, FALSE);
}
- return giochannel_table[fd];
+ return giochannel_table[fd].chan;
}
int
_gpgme_io_close (int fd)
{
- GIOChannel *chan;
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_close", fd);
if (fd < 0 || fd >= MAX_SLAFD)
}
/* Then do the close. */
- chan = giochannel_table[fd];
- if (chan)
+ if (giochannel_table[fd].chan)
{
- g_io_channel_shutdown (chan, 1, NULL);
- g_io_channel_unref (chan);
- giochannel_table[fd] = NULL;
+ if (giochannel_table[fd].primary)
+ {
+ g_io_channel_shutdown (giochannel_table[fd].chan, 1, NULL);
+ g_io_channel_unref (giochannel_table[fd].chan);
+ }
+ giochannel_table[fd].chan = NULL;
}
else
_close (fd);
+ TRACE_SUC ();
return 0;
}
any = 0;
for (i = 0; i < nfds; i++)
{
+ GIOChannel *chan = NULL;
+
if (fds[i].fd == -1)
continue;
- if (fds[i].frozen)
- TRACE_ADD1 (dbg_help, "f0x%x ", fds[i].fd);
+
+ if ((fds[i].for_read || fds[i].for_write)
+ && !(chan = find_channel (fds[i].fd, 0)))
+ {
+ TRACE_ADD1 (dbg_help, "[BAD0x%x ", fds[i].fd);
+ TRACE_END (dbg_help, "]");
+ assert (!"see log file");
+ }
else if (fds[i].for_read )
{
- GIOChannel *chan = find_channel (fds[i].fd, 0);
- assert (chan);
+ assert(chan);
g_io_channel_win32_make_pollfd (chan, G_IO_IN, pollfds + npollfds);
pollfds_map[npollfds] = i;
TRACE_ADD2 (dbg_help, "r0x%x<%d> ", fds[i].fd, pollfds[npollfds].fd);
}
else if (fds[i].for_write)
{
- GIOChannel *chan = find_channel (fds[i].fd, 0);
- assert (chan);
+ assert(chan);
g_io_channel_win32_make_pollfd (chan, G_IO_OUT, pollfds + npollfds);
pollfds_map[npollfds] = i;
TRACE_ADD2 (dbg_help, "w0x%x<%d> ", fds[i].fd, pollfds[npollfds].fd);
int
_gpgme_io_dup (int fd)
{
- return _dup (fd);
+ int newfd;
+ GIOChannel *chan;
+
+ TRACE_BEG1 (DEBUG_SYSIO, "_gpgme_io_dup", fd, "dup (%d)", fd);
+
+ newfd =_dup (fd);
+ if (newfd == -1)
+ return TRACE_SYSRES (-1);
+ if (newfd < 0 || newfd >= MAX_SLAFD)
+ {
+ /* New fd won't fit into our table. */
+ _close (newfd);
+ errno = EIO;
+ return TRACE_SYSRES (-1);
+ }
+
+ chan = find_channel (fd, 0);
+ if (!chan)
+ {
+ /* No channel exists for the original fd, thus we create one for
+ our new fd. */
+ if ( !find_channel (newfd, 1) )
+ {
+ _close (newfd);
+ errno = EIO;
+ return TRACE_SYSRES (-1);
+ }
+ }
+ else
+ {
+ /* There is already a channel for the original one. Copy that
+ channel into a new table entry unless we already did so. */
+ if ( !giochannel_table[newfd].chan)
+ {
+ giochannel_table[newfd].chan = chan;
+ giochannel_table[newfd].primary = 0;
+ }
+ assert (giochannel_table[newfd].chan == chan);
+ }
+
+ return TRACE_SYSRES (newfd);
}
fds[i].signaled = 0;
if (fds[i].for_read || fds[i].for_write)
{
- if (fds[i].frozen)
- TRACE_ADD1 (dbg_help, "f0x%x ", fds[i].fd);
- else if (fds[i].for_read)
+ if (fds[i].for_read)
{
struct reader_context_s *ctx = find_reader (fds[i].fd,1);
fdt->fds[i].fd = fd;
fdt->fds[i].for_read = (dir == 1);
fdt->fds[i].for_write = (dir == 0);
- fdt->fds[i].frozen = 0;
fdt->fds[i].signaled = 0;
fdt->fds[i].opaque = opaque;
*idx = i;
return err;
}
+ TRACE3 (DEBUG_CTX, "_gpgme_add_io_cb", ctx,
+ "fd %d, dir=%d -> tag=%p", fd, dir, tag);
+
*r_tag = tag;
return 0;
}
int nr;
struct io_select_fd_s fds;
+ TRACE0 (DEBUG_CTX, "_gpgme_run_io_cb", item, "need to check");
fds = *an_fds;
fds.signaled = 0;
/* Just give it a quick poll. */
return 0;
}
+ TRACE2 (DEBUG_CTX, "_gpgme_run_io_cb", item, "handler (%p, %d)",
+ item->handler_value, an_fds->fd);
return item->handler (item->handler_value, an_fds->fd);
}