From 970c6bd122cf06851597a5c1e32b27e60c215b12 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 20 Oct 2023 08:27:39 +0800 Subject: [PATCH] fix: delegate the `SIGINT` signal of processes with `orphan=true` to their parent --- core/src/external/shell.rs | 12 +++++++++--- cspell.json | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/external/shell.rs b/core/src/external/shell.rs index 5011b7074..fa4cc948d 100644 --- a/core/src/external/shell.rs +++ b/core/src/external/shell.rs @@ -30,7 +30,7 @@ impl ShellOpt { pub fn shell(opt: ShellOpt) -> Result { #[cfg(unix)] - return Ok( + return Ok(unsafe { Command::new("sh") .arg("-c") .stdin(opt.stdio()) @@ -40,8 +40,14 @@ pub fn shell(opt: ShellOpt) -> Result { .arg("") // $0 is the command name .args(opt.args) .kill_on_drop(!opt.orphan) - .spawn()?, - ); + .pre_exec(move || { + if opt.orphan && libc::setpgid(0i32, 0i32) < 0 { + libc::perror(std::ptr::null()); + } + Ok(()) + }) + .spawn()? + }); #[cfg(windows)] { diff --git a/cspell.json b/cspell.json index 6837af571..c0ce849e2 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"version":"0.2","language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan"]} +{"version":"0.2","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","setpgid","setsid","perror","setpgid","setpgid"],"language":"en"}