casaroli opened a new pull request, #20556:
URL: https://github.com/apache/nuttx/pull/20556

   ## Summary
   
   `load_module()` searched `PATH` for every name that did not start with `/`. 
A path relative to the current directory, such as `./hello` or `bin/hello`, was 
joined to each `PATH` directory. So `./hello` ran `/system/bin/hello` when that 
existed, instead of the `hello` in the current directory, and failed with 
`ENOENT` when it did not.
   
   POSIX searches `PATH` only for a name that contains no `/`; any other name 
is a path and is used as it is. This PR does the same. The VFS resolves a 
relative path against the current working directory.
   
   ## Impact
   
   `exec()`, `posix_spawn()` and NSH file applications, with 
`CONFIG_LIBC_ENVPATH`. A bare name (no `/`) is searched in `PATH` as before, 
and an absolute path is unchanged. Only a relative path with a `/` behaves 
differently: it now names the file relative to the current directory.
   
   ## Testing
   
   `qemu-armv8a:knsh` with a 9P share, QEMU 11. In `/mnt/rel` there is a 
program `hello` (and a copy `sub/prog`) that prints its `argv[0]`; 
`/system/bin/hello` is the NuttX example.
   
   Before:
   ```
   nsh> cd /mnt/rel
   nsh> ./hello
   Hello, World!!
   nsh> sub/prog
   nsh: sub/prog: command not found
   nsh> hello
   Hello, World!!
   ```
   
   After:
   ```
   nsh> cd /mnt/rel
   nsh> ./hello
   relhello: this is ./hello, the program in the current directory
   nsh> sub/prog
   relhello: this is sub/prog, the program in the current directory
   nsh> hello
   Hello, World!!
   ```
   
   Builds with `-Wno-cpp -Werror`: `qemu-armv8a:knsh`, `qemu-armv8a:nsh`, 
`mps2-an500:nsh`, `rv-virt:knsh`, `lm3s6965-ek:qemu-flat`. `tools/checkpatch.sh 
-c -u -m -g` passes.
   


-- 
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]

Reply via email to