summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5d149c6)
raw | patch | inline | side by side (parent: 5d149c6)
author | Max Kellermann <max.kellermann@gmail.com> | |
Sun, 19 Mar 2017 10:11:13 +0000 (11:11 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Sun, 19 Mar 2017 10:11:13 +0000 (11:11 +0100) |
Replaces the fragile if/else in plugin_data().
src/plugin.c | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 55de0d38ced7b8138642e4f4daf841b8218f3bd7..8701d1e02ee8f2ad8eb74722d6676cdddebf38c8 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
#include <sys/wait.h>
struct plugin_pipe {
+ struct plugin_cycle *cycle;
+
/** the pipe to the plugin process, or -1 if none is currently
open */
int fd;
plugin_data(gcc_unused GIOChannel *source,
gcc_unused GIOCondition condition, gpointer data)
{
- struct plugin_cycle *cycle = data;
+ struct plugin_pipe *p = data;
+ assert(p->fd >= 0);
+
+ struct plugin_cycle *cycle = p->cycle;
assert(cycle != NULL);
assert(cycle->pid > 0);
- struct plugin_pipe *p = NULL;
- if (source == cycle->pipe_stdout.channel)
- p = &cycle->pipe_stdout;
- else if (source == cycle->pipe_stderr.channel)
- p = &cycle->pipe_stderr;
- assert(p != NULL);
- assert(p->fd >= 0);
-
char buffer[256];
ssize_t nbytes = condition & G_IO_IN
? read(p->fd, buffer, sizeof(buffer))
static void
plugin_fd_add(struct plugin_cycle *cycle, struct plugin_pipe *p, int fd)
{
+ p->cycle = cycle;
p->fd = fd;
p->data = g_string_new(NULL);
p->channel = g_io_channel_unix_new(fd);