Skip to content

Commit

Permalink
Fixed ENAMETOOLONG error in setup_console_socket (#2915)
Browse files Browse the repository at this point in the history
* Fixed ENAMETOOLONG error in setup_console_socket

Signed-off-by: morganllewellynjones <morganjones.gm@gmail.com>

* Update crates/libcontainer/src/tty.rs

Co-authored-by: Toru Komatsu <k0ma@utam0k.jp>

---------

Signed-off-by: morganllewellynjones <morganjones.gm@gmail.com>
Co-authored-by: Toru Komatsu <k0ma@utam0k.jp>
  • Loading branch information
morganllewellynjones and utam0k authored Sep 30, 2024
1 parent 44ca398 commit 3aa41cf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/libcontainer/src/tty.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! tty (teletype) for user-system interaction

use std::env;
use std::io::IoSlice;
use std::os::unix::fs::symlink;
use std::os::unix::io::AsRawFd;
Expand Down Expand Up @@ -75,7 +76,14 @@ pub fn setup_console_socket(
console_socket_path: &Path,
socket_name: &str,
) -> Result<RawFd> {
let linked = container_dir.join(socket_name);
// Move into the container directory to avoid sun family conflicts with long socket path names.
// ref: https://github.com/containers/youki/issues/2910

let prev_dir = env::current_dir().unwrap();
let _ = env::set_current_dir(container_dir);

let linked = PathBuf::from(socket_name);

symlink(console_socket_path, &linked).map_err(|err| TTYError::Symlink {
source: err,
linked: linked.to_path_buf().into(),
Expand Down Expand Up @@ -105,6 +113,8 @@ pub fn setup_console_socket(
})?,
Ok(()) => csocketfd.as_raw_fd(),
};

let _ = env::set_current_dir(prev_dir);
Ok(csocketfd)
}

Expand Down

0 comments on commit 3aa41cf

Please sign in to comment.