fchroot on unionfs
Nejc Škoberne
nejc at skoberne.net
Mon Aug 11 22:08:46 UTC 2008
Hi,
I have a strange problem with Apache not seeing the lower layer of unionfs. Using
ktrace on Apache I have written this C code:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
int main() {
int fd;
char buf[512];
/* This is what apache does */
fd=open(".",O_RDONLY,0);
fchdir(fd);
close(fd);
/* This is how Apache calls open */
fd=open("/etc/hosts",O_RDONLY,0x1b6);
if(fd < 0) {
printf("error %d,%d\n",fd,errno);
perror(NULL);
exit(-1);
}
read(fd, buf, 511);
buf[511]=0;
printf("%s",buf);
close(fd);
return(0);
}
So without fchdir() call this program just displays (first 511 bytes) of /etc/hosts.
If I uncomment fchdir() call with precedent open(".",...) call, I get this:
root at web:~# ./a
No such file or directory
error -1,2
and also if I list the /etc directory with a php script, I see only those files in
/etc which are on the upper layer of unionfs.
I stumbled upon this problem while trying to figure out why apache can't resolve
hostnames I have defined in /etc/hosts. I have this:
FreeBSD web.jail 7.0-STABLE FreeBSD 7.0-STABLE #5: Sun Aug 10 09:54:42 CEST 2008
root at server.domain.com:/usr/src/sys/amd64/compile/SERVER amd64
So I am running a jail on a unionfs. Everything works now (after MFCing the unix
sockets patch from HEAD to the 7-STABLE (MySQL didn't work)), so I currently have
only this problem.
I also tried to grep the Apache source code for fchdir, but the call seems to be
made implicitely somehow (grep returned no matches).
Thanks,
Nejc
More information about the freebsd-fs
mailing list