The reason for that is that on SVR2-based UTS 2.1.2 (which along with many
other old systems implements getcwd by forking "pwd") getcwd hangs when
called when other child processes are running.
I also added a quick return from push_dir if name == NULL so it doesn't
actually have to chdir anywhere when just initializing.
An initializing call to push_dir("/",0) had previously been put in at the
beginning of daemon_main() to avoid calling getcwd after a chroot, but
since that is no longer I needed I removed it and changed the call to
chdir("/") after chroot into a push_dir("/",0) so it will remember the
correct current directory.
return -1;
}
- if (chdir("/")) {
+ if (!push_dir("/", 0)) {
rprintf(FERROR,"chdir %s failed\n", lp_path(i));
io_printf(fd,"@ERROR: chdir failed\n");
return -1;
extern char *config_file;
char *pid_file;
- /* this ensures that we don't call getcwd after the chroot,
- which doesn't work on platforms that use popen("pwd","r")
- for getcwd */
- push_dir("/", 0);
-
if (is_a_socket(STDIN_FILENO)) {
int i;
signal(SIGHUP,SIGNAL_CAST sig_int);
signal(SIGTERM,SIGNAL_CAST sig_int);
+ /* Initialize push_dir here because on some old systems getcwd
+ (implemented by forking "pwd" and reading its output) doesn't
+ work when there are other child processes. Also, on all systems
+ that implement getcwd that way "pwd" can't be found after chroot. */
+ push_dir(NULL,0);
+
if (am_daemon) {
return daemon_main();
}
getcwd(curr_dir, sizeof(curr_dir)-1);
}
+ if (!dir) return NULL; /* this call was probably just to initialize */
+
if (chdir(dir)) return NULL;
if (save) {