forked from tailhook/vagga
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tailhook#152 Handle Ctrl+C for _run and user commands
- Loading branch information
1 parent
c852be0
commit 82018de
Showing
6 changed files
with
151 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use libc::{c_int, c_ulong, pid_t, sighandler_t}; | ||
use libc::signal; | ||
use nix::sys::ioctl::ioctl; | ||
use nix::sys::signal::{SIGTTIN, SIGTTOU}; | ||
|
||
|
||
static SIG_IGN: sighandler_t = 1; | ||
static SIG_ERR: sighandler_t = !0; | ||
|
||
static TIOCSPGRP: c_ulong = 21520; | ||
|
||
|
||
pub fn give_tty_to(fd: c_int, pid: pid_t) -> Result<(), String> { | ||
let res = unsafe { ioctl(fd, TIOCSPGRP, &pid) }; | ||
match res { | ||
res if res < 0 => Err(format!("Error when giving tty with fd {} to process {}", fd, pid)), | ||
_ => Ok(()), | ||
} | ||
} | ||
|
||
pub fn ignore_tty_signals() -> Result<(), String> { | ||
let tty_signals = vec![SIGTTIN, SIGTTOU]; | ||
for signum in tty_signals { | ||
let res = unsafe { signal(signum, SIG_IGN) }; | ||
if res == SIG_ERR { | ||
return Err(format!("Error when setting signal handler for signum: {}", signum)); | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters