From 862731ba91515063b12144b976e9b608a7cbaa63 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sun, 15 Sep 2013 16:47:58 +0900 Subject: [PATCH] Add pipe logger. --- plugins/logpipe/logpipe.c | 49 ++++++++++++++++++++++++++++++++++ plugins/logpipe/uwsgiplugin.py | 6 +++++ 2 files changed, 55 insertions(+) create mode 100644 plugins/logpipe/logpipe.c create mode 100644 plugins/logpipe/uwsgiplugin.py diff --git a/plugins/logpipe/logpipe.c b/plugins/logpipe/logpipe.c new file mode 100644 index 00000000..6d7ad920 --- /dev/null +++ b/plugins/logpipe/logpipe.c @@ -0,0 +1,49 @@ +#include "../../uwsgi.h" + +ssize_t uwsgi_pipe_logger(struct uwsgi_logger *ul, char *message, size_t len) { + if (!ul->configured) { + ul->configured = 1; + if (ul->arg) { + int pipefd[2]; + if (-1 == pipe(pipefd)) { + perror("pipe"); + uwsgi_error("Can't create pipe"); + return 0; + } + if (fork()) { + close(pipefd[0]); + ul->fd = pipefd[1]; + } else { + // child + setsid(); + close(pipefd[1]); + dup2(pipefd[0], STDIN_FILENO); + close(pipefd[0]); + uwsgi_exec_command_with_args(ul->arg); + return 0; // don't come here. + } + } + } + + if (ul->fd) { + int err; + err = write(ul->fd, message, len); + if (err < 0) { + perror("write"); + uwsgi_error("Can't write to pipe."); + close(ul->fd); + ul->fd = 0; + } + return err; + } + return 0; +} + +void uwsgi_pipe_logger_register() { + uwsgi_register_logger("pipe", uwsgi_pipe_logger); +} + +struct uwsgi_plugin logpipe_plugin = { + .name = "logpipe", + .on_load = uwsgi_pipe_logger_register, +}; diff --git a/plugins/logpipe/uwsgiplugin.py b/plugins/logpipe/uwsgiplugin.py new file mode 100644 index 00000000..b87f3f76 --- /dev/null +++ b/plugins/logpipe/uwsgiplugin.py @@ -0,0 +1,6 @@ +NAME='logpipe' + +CFLAGS = [] +LDFLAGS = [] +LIBS = [] +GCC_LIST = ['logpipe']