*SOLVED* getcwd dows not work on vps after chroot
Hello! I've a little C Script which works perfectly with Kernel from 2.4 - 2.6.17.x on every normal system. On a VPS getcwd returns always NULL. Here is some code - like the script works: chroot("/home"); getcwd(cwd, MAX_LENGTH); on the a normal hardware server getcwd works correkt - on a VPS (same installation / same image) it always returns NULL and cwd is empty. Stefan
Re: getcwd dows not work on vps after chroot
1. To use chroot inside VPS you must grant this capability to VE: vzctl set 200 --capability sys_chroot:on --save 2. However your "testcase" doesn't work even on the host node. So it seems to be a bug. I've posted it in bugzilla: http://bugzilla.openvz.org/show_bug.cgi?id=209 Thanks for report!
Hi! I stopped the VPS, turned sys_chroot on and started the vps again. But the Script still does not work. It works perfectly if i do: chroot("/home"); chdir("/ABC"); getcwd(cwd, MAX_LENGTH); but without chdir it does not work on a VPS. So thanks for the bug report.
This isn't a bug. In OpenVZ such scenario is deliberately prohibited for security reasons: isolation of VEs. This is rather mainstream BUG and the decent patch will be sent to kernel.org soon. One more thing is that such scenario is questionable: you don't get consistent information from getcwd after chroot.
Mhm you're right - but it works normally So i've not modified the script.