fixes cgi cleanup

Mon, 16 Jan 2017 14:41:20 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 16 Jan 2017 14:41:20 +0100
changeset 149
aa016efb9ad7
parent 148
d861ee1455bf
child 150
89af278b7dbb

fixes cgi cleanup

src/server/safs/cgi.c file | annotate | diff | comparison | revisions
src/server/safs/cgi.h file | annotate | diff | comparison | revisions
src/server/util/pblock.h file | annotate | diff | comparison | revisions
--- a/src/server/safs/cgi.c	Sun Jan 15 18:27:09 2017 +0100
+++ b/src/server/safs/cgi.c	Mon Jan 16 14:41:20 2017 +0100
@@ -32,6 +32,10 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <sys/types.h>
+#include <signal.h>
+#include <sys/wait.h>
+
 #include "../util/util.h"
 #include "../util/pblock.h"
 #include "../../ucx/string.h"
@@ -100,6 +104,7 @@
             r = netbuf_getbytes(sn->inbuf, buf, 4096);
             if(r <= 0) {
                 // TODO: handleerror
+                kill(cgip.pid, SIGTERM);
                 cgi_close(&cgip);
                 return REQ_ABORTED; 
             }
@@ -148,7 +153,7 @@
         }
     }
     
-    cgi_close(&cgip);
+    cgi_close(&cgip); // TODO: check return value
       
     cgi_parser_free(parser);
     return result;
@@ -209,7 +214,10 @@
     return REQ_PROCEED;
 }
 
-void cgi_close(CGIProcess *p) {
+int cgi_close(CGIProcess *p) {
+    int status = -1;
+    waitpid(p->pid, &status, 0);
+    
     if(p->in[0] != -1) {
         close(p->in[0]);
     }
@@ -222,6 +230,8 @@
     if(p->out[1] != -1) {
         close(p->out[1]);
     }
+    
+    return 0;
 }
 
 CGIResponseParser* cgi_parser_new(Session *sn, Request *rq) {
--- a/src/server/safs/cgi.h	Sun Jan 15 18:27:09 2017 +0100
+++ b/src/server/safs/cgi.h	Mon Jan 16 14:41:20 2017 +0100
@@ -56,7 +56,7 @@
 
 int cgi_start(CGIProcess *p, char *path, char *const argv[], char *const envp[]);
 
-void cgi_close(CGIProcess *p);
+int cgi_close(CGIProcess *p);
 
 CGIResponseParser* cgi_parser_new(Session *sn, Request *rq);
 void cgi_parser_free(CGIResponseParser *parser);
--- a/src/server/util/pblock.h	Sun Jan 15 18:27:09 2017 +0100
+++ b/src/server/util/pblock.h	Mon Jan 16 14:41:20 2017 +0100
@@ -109,199 +109,198 @@
 
 typedef struct pb_key pb_key;
 
-const pb_key *const pb_key_accept;
-const pb_key *const pb_key_accept_charset;
-const pb_key *const pb_key_accept_encoding;
-const pb_key *const pb_key_accept_language;
-const pb_key *const pb_key_accept_ranges;
-const pb_key *const pb_key_actual_route;
-const pb_key *const pb_key_age;
-const pb_key *const pb_key_always_allow_chunked;
-const pb_key *const pb_key_always_use_keep_alive;
-const pb_key *const pb_key_auth_cert;
-const pb_key *const pb_key_auth_expiring;
-const pb_key *const pb_key_auth_group;
-const pb_key *const pb_key_auth_type;
-const pb_key *const pb_key_auth_user;
-const pb_key *const pb_key_authorization;
-const pb_key *const pb_key_browser;
-const pb_key *const pb_key_c2p_cl;
-const pb_key *const pb_key_c2p_hl;
-const pb_key *const pb_key_cache_info;
-const pb_key *const pb_key_charset;
-const pb_key *const pb_key_check_http_server;
-const pb_key *const pb_key_ChunkedRequestBufferSize;
-const pb_key *const pb_key_ChunkedRequestTimeout;
-const pb_key *const pb_key_cipher;
-const pb_key *const pb_key_clf_request;
-const pb_key *const pb_key_cli_status;
-const pb_key *const pb_key_client_cert_nickname;
-const pb_key *const pb_key_client_ip;
-const pb_key *const pb_key_close;
-const pb_key *const pb_key_connect_timeout;
-const pb_key *const pb_key_connection;
-const pb_key *const pb_key_cont;
-const pb_key *const pb_key_content_encoding;
-const pb_key *const pb_key_content_language;
-const pb_key *const pb_key_content_length;
-const pb_key *const pb_key_content_location;
-const pb_key *const pb_key_content_md5;
-const pb_key *const pb_key_content_range;
-const pb_key *const pb_key_content_type;
-const pb_key *const pb_key_cookie;
-const pb_key *const pb_key_date;
-const pb_key *const pb_key_DATE_GMT;
-const pb_key *const pb_key_DATE_LOCAL;
-const pb_key *const pb_key_dir;
-const pb_key *const pb_key_Directive;
-const pb_key *const pb_key_dns;
-const pb_key *const pb_key_DOCUMENT_NAME;
-const pb_key *const pb_key_DOCUMENT_URI;
-const pb_key *const pb_key_domain;
-const pb_key *const pb_key_enc;
-const pb_key *const pb_key_engine;
-const pb_key *const pb_key_error_action;
-const pb_key *const pb_key_error_desc;
-const pb_key *const pb_key_error_fn;
-const pb_key *const pb_key_escape;
-const pb_key *const pb_key_escaped;
-const pb_key *const pb_key_etag;
-const pb_key *const pb_key_expect;
-const pb_key *const pb_key_expires;
-const pb_key *const pb_key_expr;
-const pb_key *const pb_key_filter;
-const pb_key *const pb_key_find_pathinfo_forward;
-const pb_key *const pb_key_flushTimer;
-const pb_key *const pb_key_fn;
-const pb_key *const pb_key_from;
-const pb_key *const pb_key_full_headers;
-const pb_key *const pb_key_hdr;
-const pb_key *const pb_key_host;
-const pb_key *const pb_key_hostname;
-const pb_key *const pb_key_if_match;
-const pb_key *const pb_key_if_modified_since;
-const pb_key *const pb_key_if_none_match;
-const pb_key *const pb_key_if_range;
-const pb_key *const pb_key_if_unmodified_since;
-const pb_key *const pb_key_ip;
-const pb_key *const pb_key_iponly;
-const pb_key *const pb_key_issuer_dn;
-const pb_key *const pb_key_jroute;
-const pb_key *const pb_key_keep_alive;
-const pb_key *const pb_key_keep_alive_timeout;
-const pb_key *const pb_key_keysize;
-const pb_key *const pb_key_lang;
-const pb_key *const pb_key_LAST_MODIFIED;
-const pb_key *const pb_key_last_modified;
-const pb_key *const pb_key_level;
-const pb_key *const pb_key_location;
-const pb_key *const pb_key_lock_owner;
-const pb_key *const pb_key_magnus_charset;
-const pb_key *const pb_key_magnus_internal;
-const pb_key *const pb_key_magnus_internal_dav_src;
-const pb_key *const pb_key_magnus_internal_default_acls_only;
-const pb_key *const pb_key_magnus_internal_error_j2ee;
-const pb_key *const pb_key_magnus_internal_j2ee_nsapi;
-const pb_key *const pb_key_magnus_internal_preserve_srvhdrs;
-const pb_key *const pb_key_magnus_internal_set_request_status;
-const pb_key *const pb_key_magnus_internal_set_response_status;
-const pb_key *const pb_key_magnus_internal_webapp_errordesc;
-const pb_key *const pb_key_matched_browser;
-const pb_key *const pb_key_max_age;
-const pb_key *const pb_key_max_forwards;
-const pb_key *const pb_key_message;
-const pb_key *const pb_key_method;
-const pb_key *const pb_key_name;
-const pb_key *const pb_key_nocache;
-const pb_key *const pb_key_nostat;
-const pb_key *const pb_key_ntrans_base;
-const pb_key *const pb_key_offline_origin_addr;
-const pb_key *const pb_key_offline_proxy_addr;
-const pb_key *const pb_key_origin_addr;
-const pb_key *const pb_key_p2c_cl;
-const pb_key *const pb_key_p2c_hl;
-const pb_key *const pb_key_p2r_cl;
-const pb_key *const pb_key_p2r_hl;
-const pb_key *const pb_key_parse_timeout;
-const pb_key *const pb_key_password;
-const pb_key *const pb_key_path;
-const pb_key *const pb_key_PATH_INFO;
-const pb_key *const pb_key_path_info;
-const pb_key *const pb_key_pblock;
-const pb_key *const pb_key_poll_interval;
-const pb_key *const pb_key_pool; // new
-const pb_key *const pb_key_port;
-const pb_key *const pb_key_ppath;
-const pb_key *const pb_key_pragma;
-const pb_key *const pb_key_process_request_body;
-const pb_key *const pb_key_process_response_body;
-const pb_key *const pb_key_protocol;
-const pb_key *const pb_key_proxy_addr;
-const pb_key *const pb_key_proxy_agent;
-const pb_key *const pb_key_proxy_auth_cert;
-const pb_key *const pb_key_proxy_authorization;
-const pb_key *const pb_key_proxy_cipher;
-const pb_key *const pb_key_proxy_issuer_dn;
-const pb_key *const pb_key_proxy_jroute;
-const pb_key *const pb_key_proxy_keysize;
-const pb_key *const pb_key_proxy_ping;
-const pb_key *const pb_key_proxy_request;
-const pb_key *const pb_key_proxy_secret_keysize;
-const pb_key *const pb_key_proxy_ssl_id;
-const pb_key *const pb_key_proxy_user_dn;
-const pb_key *const pb_key_query;
-const pb_key *const pb_key_QUERY_STRING;
-const pb_key *const pb_key_QUERY_STRING_UNESCAPED;
-const pb_key *const pb_key_r2p_cl;
-const pb_key *const pb_key_r2p_hl;
-const pb_key *const pb_key_range;
-const pb_key *const pb_key_referer;
-const pb_key *const pb_key_reformat_request_headers;
-const pb_key *const pb_key_remote_status;
-const pb_key *const pb_key_request_jroute;
-const pb_key *const pb_key_required_rights;
-const pb_key *const pb_key_retries;
-const pb_key *const pb_key_rewrite_content_location;
-const pb_key *const pb_key_rewrite_host;
-const pb_key *const pb_key_rewrite_location;
-const pb_key *const pb_key_rewrite_set_cookie;
-const pb_key *const pb_key_root;
-const pb_key *const pb_key_route;
-const pb_key *const pb_key_route_cookie;
-const pb_key *const pb_key_route_hdr;
-const pb_key *const pb_key_route_offline;
-const pb_key *const pb_key_script_name;
-const pb_key *const pb_key_secret_keysize;
-const pb_key *const pb_key_secure;
-const pb_key *const pb_key_server;
-const pb_key *const pb_key_set_cookie;
-const pb_key *const pb_key_socks_addr;
-const pb_key *const pb_key_ssl_id;
-const pb_key *const pb_key_ssl_unclean_shutdown;
-const pb_key *const pb_key_status;
-const pb_key *const pb_key_sticky_cookie;
-const pb_key *const pb_key_sticky_param;
-const pb_key *const pb_key_suppress_request_headers;
-const pb_key *const pb_key_svr_status;
-const pb_key *const pb_key_timeout;
-const pb_key *const pb_key_to;
-const pb_key *const pb_key_transfer_encoding;
-const pb_key *const pb_key_transmit_timeout;
-const pb_key *const pb_key_tunnel_non_http_response;
-const pb_key *const pb_key_type;
-const pb_key *const pb_key_upstream_jroute;
-const pb_key *const pb_key_uri;
-const pb_key *const pb_key_url;
-const pb_key *const pb_key_url_prefix;
-const pb_key *const pb_key_UseOutputStreamSize;
-const pb_key *const pb_key_user;
-const pb_key *const pb_key_user_agent;
-const pb_key *const pb_key_user_dn;
-const pb_key *const pb_key_validate_server_cert;
-const pb_key *const pb_key_value;
-const pb_key *const pb_key_vary;
-const pb_key *const pb_key_via;
-const pb_key *const pb_key_warning;
+extern const pb_key *const pb_key_accept;
+extern const pb_key *const pb_key_accept_charset;
+extern const pb_key *const pb_key_accept_encoding;
+extern const pb_key *const pb_key_accept_language;
+extern const pb_key *const pb_key_accept_ranges;
+extern const pb_key *const pb_key_actual_route;
+extern const pb_key *const pb_key_age;
+extern const pb_key *const pb_key_always_allow_chunked;
+extern const pb_key *const pb_key_always_use_keep_alive;
+extern const pb_key *const pb_key_auth_cert;
+extern const pb_key *const pb_key_auth_expiring;
+extern const pb_key *const pb_key_auth_group;
+extern const pb_key *const pb_key_auth_type;
+extern const pb_key *const pb_key_auth_user;
+extern const pb_key *const pb_key_authorization;
+extern const pb_key *const pb_key_browser;
+extern const pb_key *const pb_key_c2p_cl;
+extern const pb_key *const pb_key_c2p_hl;
+extern const pb_key *const pb_key_cache_info;
+extern const pb_key *const pb_key_charset;
+extern const pb_key *const pb_key_check_http_server;
+extern const pb_key *const pb_key_ChunkedRequestBufferSize;
+extern const pb_key *const pb_key_ChunkedRequestTimeout;
+extern const pb_key *const pb_key_cipher;
+extern const pb_key *const pb_key_clf_request;
+extern const pb_key *const pb_key_cli_status;
+extern const pb_key *const pb_key_client_cert_nickname;
+extern const pb_key *const pb_key_client_ip;
+extern const pb_key *const pb_key_close;
+extern const pb_key *const pb_key_connect_timeout;
+extern const pb_key *const pb_key_connection;
+extern const pb_key *const pb_key_cont;
+extern const pb_key *const pb_key_content_encoding;
+extern const pb_key *const pb_key_content_language;
+extern const pb_key *const pb_key_content_length;
+extern const pb_key *const pb_key_content_location;
+extern const pb_key *const pb_key_content_md5;
+extern const pb_key *const pb_key_content_range;
+extern const pb_key *const pb_key_content_type;
+extern const pb_key *const pb_key_cookie;
+extern const pb_key *const pb_key_date;
+extern const pb_key *const pb_key_DATE_GMT;
+extern const pb_key *const pb_key_DATE_LOCAL;
+extern const pb_key *const pb_key_dir;
+extern const pb_key *const pb_key_Directive;
+extern const pb_key *const pb_key_dns;
+extern const pb_key *const pb_key_DOCUMENT_NAME;
+extern const pb_key *const pb_key_DOCUMENT_URI;
+extern const pb_key *const pb_key_domain;
+extern const pb_key *const pb_key_enc;
+extern const pb_key *const pb_key_engine;
+extern const pb_key *const pb_key_error_action;
+extern const pb_key *const pb_key_error_desc;
+extern const pb_key *const pb_key_error_fn;
+extern const pb_key *const pb_key_escape;
+extern const pb_key *const pb_key_escaped;
+extern const pb_key *const pb_key_etag;
+extern const pb_key *const pb_key_expect;
+extern const pb_key *const pb_key_expires;
+extern const pb_key *const pb_key_expr;
+extern const pb_key *const pb_key_filter;
+extern const pb_key *const pb_key_find_pathinfo_forward;
+extern const pb_key *const pb_key_flushTimer;
+extern const pb_key *const pb_key_fn;
+extern const pb_key *const pb_key_from;
+extern const pb_key *const pb_key_full_headers;
+extern const pb_key *const pb_key_hdr;
+extern const pb_key *const pb_key_host;
+extern const pb_key *const pb_key_hostname;
+extern const pb_key *const pb_key_if_match;
+extern const pb_key *const pb_key_if_modified_since;
+extern const pb_key *const pb_key_if_none_match;
+extern const pb_key *const pb_key_if_range;
+extern const pb_key *const pb_key_if_unmodified_since;
+extern const pb_key *const pb_key_ip;
+extern const pb_key *const pb_key_iponly;
+extern const pb_key *const pb_key_issuer_dn;
+extern const pb_key *const pb_key_jroute;
+extern const pb_key *const pb_key_keep_alive;
+extern const pb_key *const pb_key_keep_alive_timeout;
+extern const pb_key *const pb_key_keysize;
+extern const pb_key *const pb_key_lang;
+extern const pb_key *const pb_key_last_modified;
+extern const pb_key *const pb_key_level;
+extern const pb_key *const pb_key_location;
+extern const pb_key *const pb_key_lock_owner;
+extern const pb_key *const pb_key_magnus_charset;
+extern const pb_key *const pb_key_magnus_internal;
+extern const pb_key *const pb_key_magnus_internal_dav_src;
+extern const pb_key *const pb_key_magnus_internal_default_acls_only;
+extern const pb_key *const pb_key_magnus_internal_error_j2ee;
+extern const pb_key *const pb_key_magnus_internal_j2ee_nsapi;
+extern const pb_key *const pb_key_magnus_internal_preserve_srvhdrs;
+extern const pb_key *const pb_key_magnus_internal_set_request_status;
+extern const pb_key *const pb_key_magnus_internal_set_response_status;
+extern const pb_key *const pb_key_magnus_internal_webapp_errordesc;
+extern const pb_key *const pb_key_matched_browser;
+extern const pb_key *const pb_key_max_age;
+extern const pb_key *const pb_key_max_forwards;
+extern const pb_key *const pb_key_message;
+extern const pb_key *const pb_key_method;
+extern const pb_key *const pb_key_name;
+extern const pb_key *const pb_key_nocache;
+extern const pb_key *const pb_key_nostat;
+extern const pb_key *const pb_key_ntrans_base;
+extern const pb_key *const pb_key_offline_origin_addr;
+extern const pb_key *const pb_key_offline_proxy_addr;
+extern const pb_key *const pb_key_origin_addr;
+extern const pb_key *const pb_key_p2c_cl;
+extern const pb_key *const pb_key_p2c_hl;
+extern const pb_key *const pb_key_p2r_cl;
+extern const pb_key *const pb_key_p2r_hl;
+extern const pb_key *const pb_key_parse_timeout;
+extern const pb_key *const pb_key_password;
+extern const pb_key *const pb_key_path;
+extern const pb_key *const pb_key_PATH_INFO;
+extern const pb_key *const pb_key_path_info;
+extern const pb_key *const pb_key_pblock;
+extern const pb_key *const pb_key_poll_interval;
+extern const pb_key *const pb_key_pool; // new
+extern const pb_key *const pb_key_port;
+extern const pb_key *const pb_key_ppath;
+extern const pb_key *const pb_key_pragma;
+extern const pb_key *const pb_key_process_request_body;
+extern const pb_key *const pb_key_process_response_body;
+extern const pb_key *const pb_key_protocol;
+extern const pb_key *const pb_key_proxy_addr;
+extern const pb_key *const pb_key_proxy_agent;
+extern const pb_key *const pb_key_proxy_auth_cert;
+extern const pb_key *const pb_key_proxy_authorization;
+extern const pb_key *const pb_key_proxy_cipher;
+extern const pb_key *const pb_key_proxy_issuer_dn;
+extern const pb_key *const pb_key_proxy_jroute;
+extern const pb_key *const pb_key_proxy_keysize;
+extern const pb_key *const pb_key_proxy_ping;
+extern const pb_key *const pb_key_proxy_request;
+extern const pb_key *const pb_key_proxy_secret_keysize;
+extern const pb_key *const pb_key_proxy_ssl_id;
+extern const pb_key *const pb_key_proxy_user_dn;
+extern const pb_key *const pb_key_query;
+extern const pb_key *const pb_key_QUERY_STRING;
+extern const pb_key *const pb_key_QUERY_STRING_UNESCAPED;
+extern const pb_key *const pb_key_r2p_cl;
+extern const pb_key *const pb_key_r2p_hl;
+extern const pb_key *const pb_key_range;
+extern const pb_key *const pb_key_referer;
+extern const pb_key *const pb_key_reformat_request_headers;
+extern const pb_key *const pb_key_remote_status;
+extern const pb_key *const pb_key_request_jroute;
+extern const pb_key *const pb_key_required_rights;
+extern const pb_key *const pb_key_retries;
+extern const pb_key *const pb_key_rewrite_content_location;
+extern const pb_key *const pb_key_rewrite_host;
+extern const pb_key *const pb_key_rewrite_location;
+extern const pb_key *const pb_key_rewrite_set_cookie;
+extern const pb_key *const pb_key_root;
+extern const pb_key *const pb_key_route;
+extern const pb_key *const pb_key_route_cookie;
+extern const pb_key *const pb_key_route_hdr;
+extern const pb_key *const pb_key_route_offline;
+extern const pb_key *const pb_key_script_name;
+extern const pb_key *const pb_key_secret_keysize;
+extern const pb_key *const pb_key_secure;
+extern const pb_key *const pb_key_server;
+extern const pb_key *const pb_key_set_cookie;
+extern const pb_key *const pb_key_socks_addr;
+extern const pb_key *const pb_key_ssl_id;
+extern const pb_key *const pb_key_ssl_unclean_shutdown;
+extern const pb_key *const pb_key_status;
+extern const pb_key *const pb_key_sticky_cookie;
+extern const pb_key *const pb_key_sticky_param;
+extern const pb_key *const pb_key_suppress_request_headers;
+extern const pb_key *const pb_key_svr_status;
+extern const pb_key *const pb_key_timeout;
+extern const pb_key *const pb_key_to;
+extern const pb_key *const pb_key_transfer_encoding;
+extern const pb_key *const pb_key_transmit_timeout;
+extern const pb_key *const pb_key_tunnel_non_http_response;
+extern const pb_key *const pb_key_type;
+extern const pb_key *const pb_key_upstream_jroute;
+extern const pb_key *const pb_key_uri;
+extern const pb_key *const pb_key_url;
+extern const pb_key *const pb_key_url_prefix;
+extern const pb_key *const pb_key_UseOutputStreamSize;
+extern const pb_key *const pb_key_user;
+extern const pb_key *const pb_key_user_agent;
+extern const pb_key *const pb_key_user_dn;
+extern const pb_key *const pb_key_validate_server_cert;
+extern const pb_key *const pb_key_value;
+extern const pb_key *const pb_key_vary;
+extern const pb_key *const pb_key_via;
+extern const pb_key *const pb_key_warning;
 
 NSAPI_PUBLIC pool_handle_t *pblock_pool(pblock *pb);
 

mercurial