From 32299e33800dc6a78754b5ac2dc0e15caea93e48 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 5 Feb 2011 17:25:41 -0800 Subject: [PATCH] don't ignore chdir failure * sysdep.c (sys_subshell) [!defined DOS_NT]: Diagnose chdir failure and exit. (sys_subshell) [defined DOS_NT]: Mark with a FIXME the two remaining unchecked chdir calls in this function; some DOS/NT expert needs to fix them. * emacs.c (main): Mark with a FIXME the unchecked chdir calls in this function; some NextStep expert needs to fix them. --- src/ChangeLog | 11 +++++++++++ src/emacs.c | 2 ++ src/sysdep.c | 13 +++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d757a89836d..1210b48d98f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2011-02-05 Paul Eggert + + don't ignore chdir failure + * sysdep.c (sys_subshell) [!defined DOS_NT]: Diagnose chdir + failure and exit. + (sys_subshell) [defined DOS_NT]: Mark with a FIXME the two + remaining unchecked chdir calls in this function; some DOS/NT + expert needs to fix them. + * emacs.c (main): Mark with a FIXME the unchecked chdir calls + in this function; some NextStep expert needs to fix them. + 2011-02-05 Glenn Morris * xfaces.c (Finternal_set_lisp_face_attribute): diff --git a/src/emacs.c b/src/emacs.c index 53786b0adae..4455e6b4d9f 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1296,6 +1296,8 @@ main (int argc, char **argv) #ifdef NS_IMPL_COCOA if (skip_args < argc) { + /* FIXME: Do the right thing if getenv returns NULL, or if + chdir fails. */ if (!strncmp(argv[skip_args], "-psn", 4)) { skip_args += 1; diff --git a/src/sysdep.c b/src/sysdep.c index 53b7f39171e..5760d0224eb 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -548,8 +548,13 @@ sys_subshell (void) sh = "sh"; /* Use our buffer's default directory for the subshell. */ - if (str) - chdir ((char *) str); + if (str && chdir ((char *) str) != 0) + { +#ifndef DOS_NT + ignore_value (write (1, "Can't chdir\n", 12)); + _exit (1); +#endif + } close_process_descs (); /* Close Emacs's pipes/ptys */ @@ -567,7 +572,7 @@ sys_subshell (void) setenv ("PWD", str, 1); } st = system (sh); - chdir (oldwd); + chdir (oldwd); /* FIXME: Do the right thing on chdir failure. */ if (epwd) putenv (old_pwd); /* restore previous value */ } @@ -575,7 +580,7 @@ sys_subshell (void) #ifdef WINDOWSNT /* Waits for process completion */ pid = _spawnlp (_P_WAIT, sh, sh, NULL); - chdir (oldwd); + chdir (oldwd); /* FIXME: Do the right thing on chdir failure. */ if (pid == -1) write (1, "Can't execute subshell", 22); #else /* not WINDOWSNT */ -- 2.39.5