From 5bf39bd3044ea0fe1e9c617d5b72cbdb377613a9 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 2 Feb 2006 16:29:20 +0100 Subject: [PATCH] FSP: Check and exit the file 'writer' process if writes to stdout fails This ensures that the 'writer' process will remove itself when the main ELinks process for some reason decides to shutdown the connection. Before the 'writer' process would complete it's task taking up unnecessary system resources. This is mostly an issue when fetching big files. Therefore only file fetching is fixed. FIXME added about also checking return codes for write associated with directory listing. Reported-by: zas --- src/protocol/fsp/fsp.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/protocol/fsp/fsp.c b/src/protocol/fsp/fsp.c index 3136bb04b..6e785ae66 100644 --- a/src/protocol/fsp/fsp.c +++ b/src/protocol/fsp/fsp.c @@ -63,6 +63,11 @@ struct module fsp_protocol_module = struct_module( ); +/* FSP synchronous connection management: */ + +/* FIXME: Although it is probably not so much an issue, check if writes to + * stdout fails for directory listing like we do for file fetching. */ + static void fsp_error(unsigned char *error) { @@ -201,7 +206,8 @@ do_fsp(struct connection *conn) fclose(stderr); while ((r = fsp_fread(buf, 1, READ_SIZE, file)) > 0) - fwrite(buf, 1, r, stdout); + if (safe_write(STDOUT_FILENO, buf, r) <= 0) + break; fsp_fclose(file); fsp_close_session(ses); @@ -209,6 +215,11 @@ do_fsp(struct connection *conn) } } +#undef READ_SIZE + + +/* FSP asynchronous connection management: */ + static void fsp_got_data(struct socket *socket, struct read_buffer *rb) { @@ -271,8 +282,6 @@ fsp_got_header(struct socket *socket, struct read_buffer *rb) read_from_socket(conn->data_socket, buf, S_CONN, fsp_got_data); } -#undef READ_SIZE - void fsp_protocol_handler(struct connection *conn)