1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Add the '-e' flag to the 'cd' builtin (#358)

This change adds the -e flag to the cd builtin, as specified in
<https://www.austingroupbugs.net/view.php?id=253>. The -e flag is
used to verify if the the current working directory after 'cd -P'
successfully changes the directory, and returns with exit status 1
if the cwd couldn't be determined. Additionally, it causes all
other errors to return with exit status >1 (i.e., status 2 unless
ENOMEM occurs) if -e and -P are both active.

src/cmd/ksh93/bltins/cd_pwd.c:
- Add -e option to the cd builtin command. It verifies $PWD by
  using test_inode() to execute the equivalent of [[ . -ef $PWD ]].
- The check for restricted mode has been moved after optget to
  allow 'cd -eP' to return with exit status 2 when in restricted
  mode. To avoid changing the previous behavior of cd when -e isn't
  passed, extra checks have been added to prevent cd from printing
  usage information in restricted mode.

src/cmd/ksh93/tests/builtins.sh:
- Add regression tests for the exit status when using the cd -P
  flag with and without -e.

src/cmd/ksh93/data/builtins.c,
src/cmd/ksh93/sh.1:
- Document the addition of -e to the cd builtin.
This commit is contained in:
Johnothan King 2021-12-05 21:48:32 -08:00 committed by Martijn Dekker
parent a3f4b5efd1
commit cd8c48cc5a
5 changed files with 111 additions and 25 deletions

View file

@ -441,7 +441,7 @@ const char sh_optbuiltin[] =
;
const char sh_optcd[] =
"[-1c?\n@(#)$Id: cd (ksh 93u+m) 2021-01-19 $\n]"
"[-1c?\n@(#)$Id: cd (ksh 93u+m) 2021-12-02 $\n]"
"[--catalog?" SH_DICT "]"
"[+NAME?cd - change working directory ]"
"[+DESCRIPTION?\bcd\b changes the current working directory of the "
@ -482,13 +482,22 @@ const char sh_optcd[] =
"[P?The present working directory is first converted to an absolute pathname "
"that does not contain symbolic link components and symbolic name "
"components are expanded in the resulting directory name.]"
"[e?If the \b-P\b option is in effect and the correct \bPWD\b cannot be "
"determined, exit with status 1. All other errors encountered while "
"both \b-e\b and \b-P\b are active result in exit status >1 (i.e., "
"exit status 2 unless an out of memory error occurred).]"
"\n"
"\n[directory]\n"
"old new\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Directory successfully changed.]"
"[+>0?An error occurred.]"
"[+0?Directory successfully changed and the \bPWD\b is correct.]"
"[+0?Directory successfully changed, the \bPWD\b couldn't be obtained "
"and a combination of \b-eP\b is not active.]"
"[+>0?An error occurred and a combination of \b-eP\b is not active.]"
"[+1?Directory successfully changed, the \bPWD\b couldn't be obtained "
"and a combination of \b-eP\b is active.]"
"[+>1?An error occurred and a combination of \b-eP\b is active.]"
"}"
"[+SEE ALSO?\bpwd\b(1), \bgetconf\b(1)]"
;