You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am pretty sure that I am not understanding this correctly...I am trying to open a pty for the sh shell using the nix libary with this code:
let fd = unsafe {
let res = nix::pty::forkpty(None, None).unwrap();
match res.fork_result {
ForkResult::Parent { child } => {
println!("NOOO!")
}
ForkResult::Child => {
let shell_name =
CStr::from_bytes_with_nul(b"sh\0").expect("Should always have null terminator");
nix::unistd::execvp::<CString>(shell_name, &[]).unwrap();
return;
}
};
res.master
};
However, it always returns the parent. What am I doing wrong here? I want to get forkpty to return the child, not the parent.
Note: I took a look at the src code and man page of forkpty and, from what I can make out, the function returns the parent if it runs into an error? Does that have anything to do with it?
The text was updated successfully, but these errors were encountered:
The child process will be spawned in your code and execute sh, you should be able to see it in your monitor app (search the process name sh), would you like to elaborate on it a bit what do you mean by "it always returns the parent"?
Here is a program to prove that the child process exists:
I am using Nix from git, where the return value of forkpty() differs from the one in Nix 0.28.0
use std::{thread::sleep, time::Duration};use nix::pty::{forkpty,ForkptyResult};fnmain(){matchunsafe{forkpty(None,None)}.unwrap(){ForkptyResult::Parent{child: _child,master: _master} => {// don't drop the master side for 1 second so that child process can// get its job donesleep(Duration::from_secs(1));}ForkptyResult::Child => {
std::fs::write("hello_from_child","Hi").unwrap();}};}
I am pretty sure that I am not understanding this correctly...I am trying to open a pty for the sh shell using the nix libary with this code:
However, it always returns the parent. What am I doing wrong here? I want to get forkpty to return the child, not the parent.
Note: I took a look at the src code and man page of forkpty and, from what I can make out, the function returns the parent if it runs into an error? Does that have anything to do with it?
The text was updated successfully, but these errors were encountered: