casaroli opened a new pull request, #4061:
URL: https://github.com/apache/nuttx-apps/pull/4061
## Summary
NSH keeps its own copy of the current directory in `PWD`: `pwd`, the prompt,
`cd -` and the relative path arguments of the NSH commands
(`nsh_getfullpath()`) read it. Today `chdir()` of libc writes `PWD` and
`OLDPWD`, so NSH does not set them itself. apache/nuttx#TBD makes the current
directory kernel state of the task group, and `chdir()` does not write the
environment there, as on other systems: the shell sets `PWD`.
This PR makes NSH do it. After a successful `chdir()`, `cd` sets `PWD` to
the new directory from `getcwd()` and `OLDPWD` to the `PWD` from before;
`chroot` sets `PWD` after its `chdir("/")`. Without the environment
(`CONFIG_DISABLE_ENVIRON`), the console state keeps the directory from
`getcwd()`, not the argument of `cd`.
The first commit fixes the indentation of the `CHAR_ESCAPE()` lines in
`nsh_envcmds.c` (white space only): nxstyle reports these older errors for the
whole file.
## Impact
Only `cd` and `chroot` of NSH. With today's nuttx `chdir()` already wrote
the same values, so the result is the same: `PWD` is the canonical path from
`getcwd()` in both cases (`chdir()` wrote `realpath()`). With apache/nuttx#TBD
and without this PR, NSH keeps the old `PWD` after `cd`: `pwd` shows the old
directory and a relative name such as `cat version` after `cd /proc` uses the
old directory. So merge this PR first. No new option, no other app.
## Testing
qemu-armv8a:nsh (flat build, arm64, QEMU with HVF), console session `cd
/proc`, `pwd`, `echo $PWD $OLDPWD`, `cat version`, `cd -`, `pwd`, `cd /dev`,
`ls null`, `cd ..`, `pwd`:
| nuttx | apps | `pwd` after `cd /proc` | `$PWD $OLDPWD` | `cat version` |
`ls null` in `/dev` |
|---|---|---|---|---|---|
| master 46066440966 | this PR | `/proc` | `/proc /` | NuttX version ... |
`/dev/null` |
| apache/nuttx#TBD | master | `/` | `/` and empty | `cat: open failed: 2` |
`ls: stat failed: 2` |
| apache/nuttx#TBD | this PR | `/proc` | `/proc /` | NuttX version ... |
`/dev/null` |
`cd -` and `cd ..` then give `/` in the two right rows. ostest exits with
status 0 on qemu-armv8a:nsh and qemu-armv8a:knsh (kernel build, NSH as a
program) with apache/nuttx#TBD and this PR.
`tools/checkpatch.sh -c -u -m -g` of nuttx passes on both commits.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]