Fix insecure chroot(), CID #54523

Fix Coverity Scan security issue: insecure use of chroot(),
should be followed by chdir("/"), used chdir(".") ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Minor cleanup, no need for else {} when if() returns.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Make sure to reset data_sd to -1 after close(), like we do elsewhere.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>