diff --git a/patches/nginx-1.2.1-dtrace.patch b/patches/nginx-1.2.1-dtrace.patch index a9936b2..2413a3b 100644 --- a/patches/nginx-1.2.1-dtrace.patch +++ b/patches/nginx-1.2.1-dtrace.patch @@ -329,10 +329,10 @@ index 45ea154..332c011 100755 echo "checking for OS" diff --git a/src/dtrace/nginx.stp b/src/dtrace/nginx.stp new file mode 100644 -index 0000000..648a962 +index 0000000..64903e8 --- /dev/null +++ b/src/dtrace/nginx.stp -@@ -0,0 +1,46 @@ +@@ -0,0 +1,150 @@ +/* tapset for nginx */ + +/* retrieve the request uri string from the ngx_http_request_t pointer */ @@ -379,17 +379,122 @@ index 0000000..648a962 + return user_string_n(@cast(cmds, "ngx_command_t", "NGX_SBIN_PATH")->name->data, len) +} + ++ ++function ngx_chain_buf(cl) ++{ ++ return @cast(cl, "ngx_chain_t", "NGX_SBIN_PATH")->buf ++} ++ ++ ++function ngx_buf_in_memory(b) ++{ ++ return @cast(b, "ngx_buf_t", "NGX_SBIN_PATH")->temporary ++ || @cast(b, "ngx_buf_t", "NGX_SBIN_PATH")->memory ++ || @cast(b, "ngx_buf_t", "NGX_SBIN_PATH")->mmap ++} ++ ++ ++function ngx_buf_pos(b) ++{ ++ return @cast(b, "ngx_buf_t", "NGX_SBIN_PATH")->pos ++} ++ ++ ++function ngx_buf_file_pos(b) ++{ ++ return @cast(b, "ngx_buf_t", "NGX_SBIN_PATH")->file_pos ++} ++ ++ ++function ngx_buf_last(b) ++{ ++ return @cast(b, "ngx_buf_t", "NGX_SBIN_PATH")->last ++} ++ ++ ++function ngx_buf_file_last(b) ++{ ++ return @cast(b, "ngx_buf_t", "NGX_SBIN_PATH")->file_last ++} ++ ++ ++function ngx_buf_end(b) ++{ ++ return @cast(b, "ngx_buf_t", "NGX_SBIN_PATH")->end ++} ++ ++ ++function ngx_buf_size(b) ++{ ++ if (ngx_buf_in_memory(b)) { ++ return ngx_buf_last(b) - ngx_buf_pos(b) ++ } ++ ++ return ngx_buf_file_last(b) - ngx_buf_file_pos(b) ++} ++ ++ ++function ngx_buf_data(b) ++{ ++ return user_string_n(ngx_buf_pos(b), ngx_buf_last(b) - ngx_buf_pos(b)) ++} ++ ++ ++function ngx_pool_cleanup_file_name(c) ++{ ++ return user_string(@cast(c, "ngx_pool_cleanup_file_t", "NGX_SBIN_PATH")->name) ++} ++ ++ ++function ngx_http_req_content_length(r) ++{ ++ return @cast(r, "ngx_http_request_t", "NGX_SBIN_PATH")->headers_in->content_length_n ++} ++ ++ ++function ngx_http_req_body_temp_file_name(r) ++{ ++ rb = @cast(r, "ngx_http_request_t", "NGX_SBIN_PATH")->request_body ++ if (!rb) { ++ return "" ++ } ++ ++ tf = @cast(rb, "ngx_http_request_body_t", "NGX_SBIN_PATH")->temp_file ++ if (!tf) { ++ return "" ++ } ++ ++ return user_string(@cast(tf, "ngx_temp_file_t", "NGX_SBIN_PATH")->file->name) ++} ++ ++ ++function ngx_table_elt_key(e) ++{ ++ len = @cast(e, "ngx_table_elt_t", "NGX_SBIN_PATH")->key->len ++ ++ return user_string_n(@cast(e, "ngx_table_elt_t", "NGX_SBIN_PATH")->key->data, len) ++} ++ ++ ++function ngx_table_elt_value(e) ++{ ++ len = @cast(e, "ngx_table_elt_t", "NGX_SBIN_PATH")->value->len ++ ++ return user_string_n(@cast(e, "ngx_table_elt_t", "NGX_SBIN_PATH")->value->data, len) ++} ++ diff --git a/src/dtrace/nginx_provider.d b/src/dtrace/nginx_provider.d new file mode 100644 -index 0000000..ff7a4e8 +index 0000000..6fcc994 --- /dev/null +++ b/src/dtrace/nginx_provider.d -@@ -0,0 +1,27 @@ +@@ -0,0 +1,32 @@ +typedef struct { int dummy; } ngx_http_request_t; +typedef struct { int dummy; } ngx_str_t; +typedef int64_t ngx_int_t; +typedef struct { int dummy; } ngx_module_t; +typedef struct { int dummy; } ngx_http_module_t; ++typedef struct { int dummy; } ngx_table_elt_t; + + +provider nginx { @@ -403,6 +508,10 @@ index 0000000..ff7a4e8 + probe http__subrequest__post__start(ngx_http_request_t *r, ngx_int_t rc); + probe http__subrequest__post__done(ngx_http_request_t *r, ngx_int_t rc); + probe http__module__post__config(ngx_module_t *m); ++ probe http__read__body__abort(ngx_request_t *r, char *reason); ++ probe http__read__body__done(ngx_request_t *r); ++ probe http__read__req__line__done(ngx_request_t *r); ++ probe http__read__req__header__done(ngx_request_t *r, ngx_table_elt_t *h); +}; + + @@ -447,7 +556,7 @@ index 3e077fb..b7edb7b 100644 return NGX_CONF_ERROR; } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c -index 31832ce..9c5ebf3 100644 +index c5db18f..f23ba51 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -8,6 +8,7 @@ @@ -467,7 +576,7 @@ index 31832ce..9c5ebf3 100644 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "subrequests cycle while processing \"%V\"", uri); r->main->subrequests = 1; -@@ -2489,6 +2492,8 @@ ngx_http_subrequest(ngx_http_request_t *r, +@@ -2491,6 +2494,8 @@ ngx_http_subrequest(ngx_http_request_t *r, *psr = sr; @@ -478,10 +587,10 @@ index 31832ce..9c5ebf3 100644 diff --git a/src/http/ngx_http_probe.h b/src/http/ngx_http_probe.h new file mode 100644 -index 0000000..0727968 +index 0000000..d7d2d45 --- /dev/null +++ b/src/http/ngx_http_probe.h -@@ -0,0 +1,59 @@ +@@ -0,0 +1,75 @@ +#ifndef _NGX_HTTP_PROBE_H_INCLUDED_ +#define _NGX_HTTP_PROBE_H_INCLUDED_ + @@ -525,6 +634,18 @@ index 0000000..0727968 +#define ngx_http_probe_module_post_config(m) \ + NGINX_HTTP_MODULE_POST_CONFIG(m) + ++#define ngx_http_probe_read_body_abort(r, reason) \ ++ NGINX_HTTP_READ_BODY_ABORT(r, reason) ++ ++#define ngx_http_probe_read_body_done(r) \ ++ NGINX_HTTP_READ_BODY_DONE(r) ++ ++#define ngx_http_probe_read_req_line_done(r) \ ++ NGINX_HTTP_READ_REQ_LINE_DONE(r) ++ ++#define ngx_http_probe_read_req_header_done(r, h) \ ++ NGINX_HTTP_READ_REQ_HEADER_DONE(r, h) ++ +#else /* !(NGX_DTRACE) */ + +#define ngx_http_probe_subrequest_cycle(pr, uri, args) @@ -536,13 +657,17 @@ index 0000000..0727968 +#define ngx_http_probe_subrequest_post_start(r, rc) +#define ngx_http_probe_subrequest_post_done(r, rc) +#define ngx_http_probe_module_post_config(m) ++#define ngx_http_probe_read_body_abort(r, reason) ++#define ngx_http_probe_read_body_done(r) ++#define ngx_http_probe_read_req_line_done(r) ++#define ngx_http_probe_read_req_header_done(r, h) + +#endif /* NGX_DTRACE */ + + +#endif /* _NGX_HTTP_PROBE_H_INCLUDED_ */ diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c -index b187713..383dc2c 100644 +index 436e17d..6dc5cb2 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -8,6 +8,7 @@ @@ -553,7 +678,25 @@ index b187713..383dc2c 100644 static void ngx_http_init_request(ngx_event_t *ev); -@@ -1959,7 +1960,11 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) +@@ -864,6 +865,8 @@ ngx_http_process_request_line(ngx_event_t *rev) + } + #endif + ++ ngx_http_probe_read_req_line_done(r); ++ + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http request line: \"%V\"", &r->request_line); + +@@ -1109,6 +1112,8 @@ ngx_http_process_request_headers(ngx_event_t *rev) + return; + } + ++ ngx_http_probe_read_req_header_done(r, h); ++ + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http header: \"%V: %V\"", + &h->key, &h->value); +@@ -1963,7 +1968,11 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) } if (r != r->main && r->post_subrequest) { @@ -565,7 +708,7 @@ index b187713..383dc2c 100644 } if (rc == NGX_ERROR -@@ -2009,6 +2014,8 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) +@@ -2013,6 +2022,8 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) if (r->buffered || r->postponed) { @@ -574,7 +717,7 @@ index b187713..383dc2c 100644 if (ngx_http_set_write_handler(r) != NGX_OK) { ngx_http_terminate_request(r, 0); } -@@ -2045,10 +2052,14 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) +@@ -2049,10 +2060,14 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) pr->postponed = pr->postponed->next; } @@ -589,7 +732,7 @@ index b187713..383dc2c 100644 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "http finalize non-active request: \"%V?%V\"", &r->uri, &r->args); -@@ -2060,6 +2071,8 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) +@@ -2064,6 +2079,8 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) } } @@ -598,3 +741,110 @@ index b187713..383dc2c 100644 if (ngx_http_post_request(pr, NULL) != NGX_OK) { r->main->count++; ngx_http_terminate_request(r, 0); +diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c +index f0e671a..37ec5d2 100644 +--- a/src/http/ngx_http_request_body.c ++++ b/src/http/ngx_http_request_body.c +@@ -8,6 +8,7 @@ + #include + #include + #include ++#include + + + static void ngx_http_read_client_request_body_handler(ngx_http_request_t *r); +@@ -40,11 +41,15 @@ ngx_http_read_client_request_body(ngx_http_request_t *r, + r->main->count++; + + if (r->request_body || r->discard_body || r->content_length_n == 0) { ++ ngx_http_probe_read_body_abort(r, ++ r->request_body ? "body exists" ++ : "body discarded"); + post_handler(r); + return NGX_OK; + } + + if (ngx_http_test_expect(r) != NGX_OK) { ++ ngx_http_probe_read_body_abort(r, "test expect failed"); + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + +@@ -56,6 +61,7 @@ ngx_http_read_client_request_body(ngx_http_request_t *r, + r->request_body = rb; + + if (r->headers_in.content_length_n < 0) { ++ ngx_http_probe_read_body_abort(r, "no content length"); + post_handler(r); + return NGX_OK; + } +@@ -89,10 +95,13 @@ ngx_http_read_client_request_body(ngx_http_request_t *r, + tf->persistent, tf->clean, tf->access) + != NGX_OK) + { ++ ngx_http_probe_read_body_abort(r, "create temp file failed"); + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + } + ++ ngx_http_probe_read_body_done(r); ++ + post_handler(r); + + return NGX_OK; +@@ -148,10 +157,13 @@ ngx_http_read_client_request_body(ngx_http_request_t *r, + + if (r->request_body_in_file_only) { + if (ngx_http_write_request_body(r, rb->bufs) != NGX_OK) { ++ ngx_http_probe_read_body_abort(r, "write temp file failed"); + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + } + ++ ngx_http_probe_read_body_done(r); ++ + post_handler(r); + + return NGX_OK; +@@ -245,6 +257,7 @@ ngx_http_read_client_request_body_handler(ngx_http_request_t *r) + ngx_int_t rc; + + if (r->connection->read->timedout) { ++ ngx_http_probe_read_body_abort(r, "timed out"); + r->connection->timedout = 1; + ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT); + return; +@@ -279,6 +292,7 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r) + if (rb->buf->last == rb->buf->end) { + + if (ngx_http_write_request_body(r, rb->to_write) != NGX_OK) { ++ ngx_http_probe_read_body_abort(r, "write temp file failed"); + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + +@@ -302,6 +316,9 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r) + } + + if (n == 0) { ++ ++ ngx_http_probe_read_body_abort(r, "connection closed"); ++ + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "client prematurely closed connection"); + } +@@ -352,6 +369,7 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r) + /* save the last part */ + + if (ngx_http_write_request_body(r, rb->to_write) != NGX_OK) { ++ ngx_http_probe_read_body_abort(r, "write temp file failed"); + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + +@@ -381,6 +399,8 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r) + + r->read_event_handler = ngx_http_block_reading; + ++ ngx_http_probe_read_body_done(r); ++ + rb->post_handler(r); + + return NGX_OK;