Skip to content

Conversation

@grisenti
Copy link
Contributor

@grisenti grisenti commented Apr 2, 2025

should fix #389. Also correctly handles SIGINT in interactive mode

@jgarzik
Copy link
Contributor

jgarzik commented Apr 2, 2025

Unfortunately does not fix the issue. Looks like the syscall is returning EINVAL, which suggests some invalid paramters are being passed?

% RUST_BACKTRACE=1 ./target/release/sh
$ ls
CONTRIBUTING.md awk             fs              pathnames       target
Cargo.lock      calc            ftw             plib            text
Cargo.toml      clippy.toml     gettext-rs      process         tree
LICENSE         datetime        i18n            sccs            users
README.md       dev             m4              screen          xform
TODO.md         display         make            sh
WANTED.md       file            misc            sys
$ ls | grep WAN

thread 'main' panicked at sh/src/shell/mod.rs:779:63:
called `Result::unwrap()` on an `Err` value: EINVAL
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: sh::shell::Shell::interpret_and_or_list
   4: sh::shell::Shell::execute_program
   5: sh::interactive_shell
   6: sh::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
% WANTED.md

The line that is failing is

                        // child is a valid group id and is in the same session
                        // as the shell process
                        tcsetpgrp(io::stdin().as_fd(), child).unwrap();

@grisenti
Copy link
Contributor Author

grisenti commented Apr 2, 2025

@jgarzik unfortunately I don't have mac so I can't test it there. I tried it on FreeBSD and it gave EPERM, but it works if I pass the child process group id (although I thought that pgid and pid were the same if child is the group leader, but I guess not on all systems).

@jgarzik
Copy link
Contributor

jgarzik commented Apr 2, 2025

Working now, thanks

@jgarzik jgarzik merged commit 0773ce6 into rustcoreutils:main Apr 2, 2025
2 checks passed
@jgarzik
Copy link
Contributor

jgarzik commented Apr 2, 2025

There is a new warning to fix:

   Compiling posixutils-sh v0.1.7 (/Users/jgarzik/repo/posixutils-rs/sh)
warning: unreachable pattern
   --> sh/src/shell/mod.rs:811:29
    |
811 | ...                   _ => unreachable!(),
    |                       ^ no value can reach this
    |
note: multiple earlier patterns match some of the same values
   --> sh/src/shell/mod.rs:811:29
    |
775 | ...                   WaitStatus::Exited(_, _) => {
    |                       ------------------------ matches some of the same values
...
780 | ...                   WaitStatus::Signaled(_, _, _) => {
    |                       ----------------------------- matches some of the same values
...
784 | ...                   WaitStatus::Continued(_) => {
    |                       ------------------------ matches some of the same values
...
788 | ...                   WaitStatus::Stopped(_, _) => {
    |                       ------------------------- matches some of the same values
...
811 | ...                   _ => unreachable!(),
    |                       ^ ...and 1 other patterns collectively make this unreachable
    = note: `#[warn(unreachable_patterns)]` on by default

warning: `posixutils-sh` (bin "sh") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.25s
   Compiling posixutils-sh v0.1.7 (/Users/jgarzik/repo/posixutils-rs/sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[sh] piped command crashes shell

2 participants