Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ jobs:
# run the example
cargo run -p containerd-shim --example skeleton -- -namespace default -id 1234 -address "\\.\pipe\containerd-containerd" -publish-binary ./bin/containerd start
ps skeleton
cargo run -p containerd-shim-protos --example shim-proto-connect \\.\pipe\containerd-shim-17630016127144989388-pipe
cargo run -p containerd-shim-protos --example shim-proto-connect \\.\pipe\containerd-shim-bc764c65e177434fcefe8257dc440be8b8acf7c96156320d965938f7e9ae1a35-pipe
$skeleton = get-process skeleton -ErrorAction SilentlyContinue
if ($skeleton) { exit 1 }
- name: Run client
Expand Down
1 change: 1 addition & 0 deletions crates/shim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ path = "examples/windows_log_reader.rs"
containerd-shim-protos = { path = "../shim-protos", version = "0.7.2" }
go-flag = "0.1.0"
lazy_static = "1.4.0"
sha2 = "0.10.2"
libc.workspace = true
log = { workspace = true, features = ["std", "kv_unstable" ] }
nix = { workspace = true, features = [
Expand Down
6 changes: 3 additions & 3 deletions crates/shim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ $ cat log
$env:TTRPC_ADDRESS="\\.\pipe\containerd-containerd.ttrpc"

$ cargo run --example skeleton -- -namespace default -id 1234 -address "\\.\pipe\containerd-containerd" start
\\.\pipe\containerd-shim-17630016127144989388-pipe
\\.\pipe\containerd-shim-bc764c65e177434fcefe8257dc440be8b8acf7c96156320d965938f7e9ae1a35-pipe

# (Optional) Run the log collector in a separate command window
# note: log reader won't work if containerd is connected to the named pipe, this works when running manually to help debug locally
$ cargo run --example windows-log-reader \\.\pipe\containerd-shim-default-1234-log
Reading logs from: \\.\pipe\containerd-shim-default-1234-log
<logs will appear after next command>

$ cargo run --example shim-proto-connect \\.\pipe\containerd-shim-17630016127144989388-pipe
Connecting to \\.\pipe\containerd-shim-17630016127144989388-pipe...
$ cargo run --example shim-proto-connect \\.\pipe\containerd-shim-bc764c65e177434fcefe8257dc440be8b8acf7c96156320d965938f7e9ae1a35-pipe
Connecting to \\.\pipe\containerd-shim-bc764c65e177434fcefe8257dc440be8b8acf7c96156320d965938f7e9ae1a35-pipe...
Sending `Connect` request...
Connect response: version: "example"
Sending `Shutdown` request...
Expand Down
15 changes: 7 additions & 8 deletions crates/shim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#![cfg_attr(feature = "docs", doc = include_str!("../README.md"))]

use std::{collections::hash_map::DefaultHasher, fs::File, hash::Hasher, path::PathBuf};
use std::{fs::File, path::PathBuf};
#[cfg(unix)]
use std::{
os::unix::{io::RawFd, net::UnixListener},
Expand All @@ -30,6 +30,7 @@ pub use protos::{
shim::shim::DeleteResponse,
ttrpc::{context::Context, Result as TtrpcResult},
};
use sha2::{Digest, Sha256};

#[cfg(unix)]
ioctl_write_ptr_bad!(ioctl_set_winsz, libc::TIOCSWINSZ, libc::winsize);
Expand Down Expand Up @@ -173,17 +174,15 @@ pub fn socket_address(socket_path: &str, namespace: &str, id: &str) -> String {
.join(id)
.display()
.to_string();

let hash = {
let mut hasher = DefaultHasher::new();
hasher.write(path.as_bytes());
hasher.finish()
let mut hasher = Sha256::new();
hasher.update(path);
hasher.finalize()
};

if cfg!(unix) {
format!("unix://{}/{:x}.sock", SOCKET_ROOT, hash)
format!("unix://{}/s/{:x}", SOCKET_ROOT, hash)
} else if cfg!(windows) {
format!(r"\\.\pipe\containerd-shim-{}-pipe", hash)
format!(r"\\.\pipe\containerd-shim-{:x}-pipe", hash)
} else {
panic!("unsupported platform")
}
Expand Down