Skip to content

Commit

Permalink
Fix exit status when the shell cannot open a script
Browse files Browse the repository at this point in the history
When the shell cannot open a script specified by the command-line
argument, it now returns the exit status of 126 or 127 as required by
POSIX. Previously, it returned the exit status of 2.
  • Loading branch information
magicant committed Jul 21, 2024
1 parent 922e52d commit 5c7916e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
6 changes: 6 additions & 0 deletions yash-cli/CHANGELOG-bin.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`${1abc}` and `${0_1}` are now syntax errors.
- Improved error messages for some parameter expansion errors.

### Fixed

- When the shell cannot open a script specified by the command-line argument,
it now returns the exit status of 126 or 127 as required by POSIX. Previously,
it returned the exit status of 2.

## [0.1.0-beta.2] - 2024-07-13

### Changed
Expand Down
6 changes: 6 additions & 0 deletions yash-cli/CHANGELOG-lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The shell now executes the initialization files on startup if the shell is
interactive.

### Fixed

- When the shell cannot open a script specified by the command-line argument,
it now returns the exit status of 126 or 127 as required by POSIX. Previously,
it returned the exit status of 2.

## [0.1.0-beta.2] - 2024-07-13

### Added
Expand Down
7 changes: 5 additions & 2 deletions yash-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::cell::RefCell;
use std::num::NonZeroU64;
use std::ops::ControlFlow::{Break, Continue};
use yash_env::signal;
use yash_env::system::SignalHandling;
use yash_env::system::{Errno, SignalHandling};
use yash_env::Env;
use yash_env::RealSystem;
use yash_env::System;
Expand Down Expand Up @@ -86,7 +86,10 @@ async fn parse_and_print(mut env: Env) -> i32 {
// instead of reusing `env`.
// env.system.print_error(&message).await;
ref_env.borrow_mut().system.print_error(&message).await;
return ExitStatus::FAILURE.0;
return match e.errno {
Errno::ENOENT | Errno::ENOTDIR | Errno::EILSEQ => ExitStatus::NOT_FOUND.0,
_ => ExitStatus::NOEXEC.0,
};
}
};
let line = NonZeroU64::new(1).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions yash-cli/tests/scripted_test/startup-p.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ __OUT__

)

test_O -d -e 127 'reading non-existing file' ./_no_such_file_
__IN__

(
input=input-2
>"$input"
Expand Down
5 changes: 0 additions & 5 deletions yash-cli/tests/scripted_test/startup-y.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ testcase "$LINENO" -e 2 'options -c and -s are mutually exclusive (-o)' \
$testee: cannot specify both \`-c\` and \`-s\`
__ERR__

# TODO This test case should be in startup-p.sh
: TODO yash is broken: the exit status should be 127, not 2 <<\__IN__
test_O -d -e 127 'reading non-existing file' ./_no_such_file_
__IN__

(
unset YASH_LOADPATH

Expand Down

0 comments on commit 5c7916e

Please sign in to comment.