diff options
Diffstat (limited to 'src/rfc2388.c')
-rw-r--r-- | src/rfc2388.c | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/src/rfc2388.c b/src/rfc2388.c index 0548868..32c21df 100644 --- a/src/rfc2388.c +++ b/src/rfc2388.c @@ -1,21 +1,23 @@ /* -------------------------------------------------------------------------- - * multipart/form-data handler functions (obviously, see rfc2388 for info) - * Copyright (c) 2007 Nathan Angelacos (nangel@users.sourceforge.net) + * Copyright 2003-2011 (inclusive) Nathan Angelacos + * (nangel@users.sourceforge.net) + * + * This file is part of haserl. * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 2, as published by the Free - * Software Foundation. + * Haserl is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * Haserl is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License + * along with haserl. If not, see <http://www.gnu.org/licenses/>. * - ------------------------------------------------------------------------- */ + * ------------------------------------------------------------------------ */ + #if HAVE_CONFIG_H #include <config.h> @@ -70,6 +72,7 @@ void mime_var_destroy (mime_var_t * obj) { int status; + struct sigaction new_action; if (obj->name) { @@ -94,10 +97,14 @@ mime_var_destroy (mime_var_t * obj) buffer_destroy (&(obj->value)); if (obj->fh) { - close (obj->fh); + close (abs (obj->fh)); if (global.uploadhandler) { wait (&status); + new_action.sa_handler = SIG_DFL; + sigemptyset (&new_action.sa_mask); + new_action.sa_flags = 0; + sigaction (SIGPIPE, &new_action, NULL); } obj->fh = 0; } @@ -205,6 +212,9 @@ mime_exec (mime_var_t * obj, char *fifo) char *type, *filename, *name; char *c; int fh; + struct sigaction new_action; + + pid = fork (); if (pid == -1) @@ -254,7 +264,11 @@ mime_exec (mime_var_t * obj, char *fifo) } else { - /* I'm parent */ + /* I'm parent - ignore SIGPIPE from the child */ + new_action.sa_handler = SIG_IGN; + sigemptyset (&new_action.sa_mask); + new_action.sa_flags = 0; + sigaction (SIGPIPE, &new_action, NULL); } /* control should get to this point only in the parent. @@ -298,7 +312,9 @@ mime_var_open_target (mime_var_t * obj) close (obj->fh); unlink (tmpname); if (mkfifo (tmpname, 0600)) - ok = 0; + { + ok = 0; + } /* you must open the fifo for reading before writing * on non linux systems */ @@ -336,6 +352,8 @@ mime_var_open_target (mime_var_t * obj) void mime_var_writer (mime_var_t * obj, char *str, int len) { + int err; + /* if not a file upload, then just a normal variable */ if (!obj->filename) { @@ -347,9 +365,15 @@ mime_var_writer (mime_var_t * obj, char *str, int len) mime_var_open_target (obj); /* if we have an open file, write the chunk */ - if (obj->fh) + if (obj->fh > 0) { - write (obj->fh, str, len); + err = write (obj->fh, str, len); + /* if there was an error, invert the filehandle; we need the + handle for later when we close it */ + if (err == -1) + { + obj->fh = abs (obj->fh) * -1; + } } } |