}
int setdir(char *rootdir) {
+ if (chdir(rootdir ? rootdir : "/") == -1) {
+ perror("can not chdir to rootdir");
+ return 0;
+ }
+#if 0
if (rootdir && strcmp(rootdir, "/")) {
- if (chdir(rootdir) == -1) {
- perror("can not chdir to rootdir");
- return 0;
- }
if (geteuid() == 0) {
/* chroot is deprecated, and not in posix. need to use
* OS/kernel specific code.
} else {
fprintf(stderr, "unable to chroot as non root user\n");
}
- } else {
- if (chdir("/") == -1) {
- perror("can not chdir to /");
- return 0;
- }
}
+#endif
return 1;
}