Nginx-ru mailing list archive (nginx-ru@sysoev.ru)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
не работает fopen в фильтре
- To: nginx-ru@xxxxxxxxx
- Subject: не работает fopen в фильтре
- From: "o1egus" <nginx-forum@xxxxxxxx>
- Date: Wed, 02 Jun 2010 06:11:52 -0400
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mickey.jlkhosting.com; s=x; h=Sender:From:Message-ID:Content-Transfer-Encoding:Content-Type:Subject:To:Date; bh=obW1K6Y1IEMZqcycIcr3D1fSM5nfD9izr5eXGna0VhE=; b=MzjSVdBzqLr4/LYS62V1wZVTcGhwvFGBeFbVWcl8wPeSXZ/idOOCm2916KyDNq6D/hiaEj6E7y+NDpf/O3Db30qPkIbHwo7nGDRj3I070O5t+jhCfekn+20Yh04kfDvL;
Пытаюсь открыть файл в фильтрующей функции, но он почему то не открывается.
[code]
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <stdio.h>
static ngx_int_t ngx_http_pg_filter_init(ngx_conf_t *cf);
static ngx_int_t ngx_http_pg_header_filter(ngx_http_request_t *r);
static ngx_int_t ngx_http_pg_body_filter(ngx_http_request_t *r, ngx_chain_t
*in);
static ngx_http_module_t ngx_http_pg_module_ctx = {
NULL, /* preconfiguration */
ngx_http_pg_filter_init, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
NULL, /* create location
configuration */
NULL /* merge location
configuration */
};
ngx_module_t ngx_http_pg_module = {
NGX_MODULE_V1,
&ngx_http_pg_module_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_int_t ngx_http_pg_header_filter(ngx_http_request_t *r)
{
return ngx_http_next_header_filter(r);
}
//фильтрующая функция
[b]static ngx_int_t ngx_http_pg_body_filter(ngx_http_request_t *r, ngx_chain_t
*in) {
FILE* f = NULL;
f = fopen("/root/Desktop/1.txt", "a");
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "|is_file_open: %s|",
(f == NULL) ? "false" : "true");
if(f != NULL)
fclose(f);
return ngx_http_next_body_filter(r, in);
}[/b]
static ngx_int_t ngx_http_pg_filter_init(ngx_conf_t *cf) {
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_pg_header_filter;
ngx_http_next_body_filter = ngx_http_top_body_filter;
ngx_http_top_body_filter = ngx_http_pg_body_filter;
return NGX_OK;
}
[/code]
error.log
[code]
2010/06/02 16:58:46 [error] 19801#0: *1 [b]|is_file_open: false|[/b] while
sending to client, client: 127.0.0.1, server: localhost, request: "GET /1.html
HTTP/1.1", upstream: "http://127.0.0.1:80/1.html", host: "localhost:8000"
2010/06/02 16:58:46 [error] 19801#0: *1 [b]|is_file_open: false|[/b] while
sending to client, client: 127.0.0.1, server: localhost, request: "GET /1.html
HTTP/1.1", upstream: "http://127.0.0.1:80/1.html", host: "localhost:8000"
2010/06/02 16:58:46 [error] 19801#0: *3 [b]|is_file_open: false|[/b] while
sending to client, client: 127.0.0.1, server: localhost, request: "GET
/favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:80/favicon.ico", host:
"localhost:8000"
2010/06/02 16:58:46 [error] 19801#0: *3 [b]|is_file_open: false|[/b] while
sending to client, client: 127.0.0.1, server: localhost, request: "GET
/favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:80/favicon.ico", host:
"localhost:8000"
[/code]
Также пробовал использовать fstream в отдельной с++ функции, вызываемой в
фильтрующей функции. Тоже не хочет создавать/открывать файл. Почему? И как
тогда работать с файлами?
Posted at Nginx Forum: http://forum.nginx.org/read.php?21,93507,93507#msg-93507
_______________________________________________
nginx-ru mailing list
nginx-ru@xxxxxxxxx
http://nginx.org/mailman/listinfo/nginx-ru
|