Mantis - Resin
Viewing Issue Advanced Details
5202 major always 08-30-12 22:45 08-31-12 10:48
ssmax  
ferg  
normal  
closed 4.0.29  
fixed  
none    
none 4.0.31  
0005202: sendfile file permision error return 0 byte.
resin pro 4.0.29 --enable-64bit --enable-jni
jdk: oracle java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
os: centos 5.8 final
kernel: 2.6.18-308.1.1.el5 / 2.6.18-308.13.1.el5 / etc..

start resin pro with config:
setuid_user : nobody
setuid_group : nobody
sendfile : true

visit the regular file using resin-file, for example:
-rw-r--r-- 1 root root 14 Aug 31 12:20 /home/resin/webapps/ROOT/test.txt

http://127.0.0.1/test.txt [^]

if the file havn't the write permission for the user who start the resin, then http response will return the right length but 0 byte like :

--------------------------
HTTP/1.1 200 OK
Server: Resin/4.0.29
ETag: "CXpHhK1fUZd"
Last-Modified: Fri, 31 Aug 2012 04:34:23 GMT
Accept-Ranges: bytes
Content-Type: text/plain; charset=utf-8
Content-Length: 14
Date: Fri, 31 Aug 2012 05:23:42 GMT

(but nothing here , 0 byte)

--------------------------

i trace down the code and found something strange here:
resin-pro-4.0.29/modules/c/src/resin_os/jni_socket.c
line 471 in jni_open_file block:

 flags = O_RDWR|O_CREAT;

this set a read and write flag when opening the file, and sendfile will use this fd to send the file to the socket.

fd = jni_open_file(env, name, name_length);
....
result = sendfile(conn->fd, fd, &sendfile_offset, file_length);

when operate the file which resin has no write permission, i guess there will be a problem here.

so i edit the code like :
 flags = O_RDONLY;

and recompile resin , start it with same config above.
and everythig gets right.

Notes
(0006032)
ferg   
08-31-12 10:48   
server/1c15