From c5003561dda8f027682ebe765178604aedcfb7a6 Mon Sep 17 00:00:00 2001 From: Unbit Date: Sat, 23 Nov 2013 07:35:08 +0100 Subject: [PATCH] added write hook --- core/hooks.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/core/hooks.c b/core/hooks.c index 59b06f82..93af8c9b 100644 --- a/core/hooks.c +++ b/core/hooks.c @@ -78,6 +78,30 @@ static int uwsgi_hook_print(char *arg) { return 0; } +static int uwsgi_hook_write(char *arg) { + char *space = strchr(arg, ' '); + if (!space) { + uwsgi_log("invalid hook write syntax, must be: \n"); + return -1; + } + *space = 0; + int fd = open(arg, O_WRONLY); + if (fd < 0) { + uwsgi_error_open(arg); + *space = ' '; + return -1; + } + *space = ' '; + size_t l = strlen(space+1); + if (write(fd, space+1, l) != (ssize_t) l) { + uwsgi_error("uwsgi_hook_write()/write()"); + close(fd); + return -1; + } + close(fd); + return 0; +} + static int uwsgi_hook_callint(char *arg) { char *space = strchr(arg, ' '); if (space) { @@ -177,6 +201,8 @@ void uwsgi_register_base_hooks() { uwsgi_register_hook("cd", uwsgi_hook_chdir); uwsgi_register_hook("exec", uwsgi_hook_exec); + uwsgi_register_hook("write", uwsgi_hook_write); + uwsgi_register_hook("mount", uwsgi_mount_hook); uwsgi_register_hook("umount", uwsgi_umount_hook);