Skip to content

Commit

Permalink
Fix output issue.
Browse files Browse the repository at this point in the history
Signed-off-by: Klaus Ma <[email protected]>
  • Loading branch information
k82cn committed Oct 16, 2024
1 parent 3a33a96 commit 3af01c7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ nix = { version = "0.29", features = [
"signal",
"mount",
"user",
"process",
] }
oci-spec = "0.7.0"
flate2 = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion busybox.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: busybox
image: busybox
entrypoint: /usr/bin/ls
entrypoint: /bin/ls
43 changes: 16 additions & 27 deletions src/core/cmd/runc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

use std::ffi::CString;
use std::ffi::{CString, CStr};
use std::fs;

use nix::{
fcntl::{open, OFlag},
libc,
mount::{mount, umount2, MntFlags, MsFlags},
sched::CloneFlags,
sys::{stat::Mode, wait::wait},
unistd::{chdir, dup2, execv, getpid, getuid, pivot_root},
sys::{stat::Mode, wait::{wait, WaitStatus}},
unistd::{chdir, dup2, execve, getpid, getuid, pivot_root},
};

use flate2::read::GzDecoder;
Expand Down Expand Up @@ -78,7 +78,18 @@ pub async fn run(cxt: cfg::Context, file: String) -> ChariotResult<()> {

tracing::debug!("Waiting for the child process <{pid}> to finish.");
let status = wait()?;
tracing::debug!("The container <{}> was exited", status.pid().unwrap());
match status {
WaitStatus::Exited(pid, rc) => {
tracing::debug!("The container <{}> was exited in <{}>", pid, rc);
}
WaitStatus::Signaled(pid, sig, _) => {
tracing::debug!("The container <{}> got a signal <{}>", pid, sig);
}
WaitStatus::Stopped(pid, sig) => {
tracing::debug!("The container <{}> was stopped by signal <{}>", pid, sig);
}
_ => {}
}

Ok(())
}
Expand Down Expand Up @@ -139,28 +150,6 @@ fn run_container(cxt: cfg::Context, container: Container) -> ChariotResult<()> {
)?;
umount2("/", MntFlags::MNT_DETACH)?;

tracing::debug!("Try to mout /proc by <{}>", getuid());
mount(
Some("proc"),
"/proc",
Some("proc"),
MsFlags::empty()
.union(MsFlags::MS_NOEXEC)
.union(MsFlags::MS_NODEV)
.union(MsFlags::MS_NOSUID),
None::<&str>,
)?;
tracing::debug!("Try to mout /dev by <{}>", getuid());
mount(
Some("tmpfs"),
"/dev",
Some("tmpfs"),
MsFlags::empty()
.union(MsFlags::MS_STRICTATIME)
.union(MsFlags::MS_NOSUID),
Some("mode=0755"),
)?;

// Change working directory to '/'.
chdir("/")?;

Expand All @@ -170,7 +159,7 @@ fn run_container(cxt: cfg::Context, container: Container) -> ChariotResult<()> {

// execute `container entrypoint`
let cmd = CString::new(container.entrypoint.as_bytes())?;
let _ = execv(cmd.as_c_str(), &[cmd.as_c_str()]);
let _ = execve::<&CStr, &CStr>(cmd.as_c_str(), &[cmd.as_c_str()], &[])?;

Ok(())
}

0 comments on commit 3af01c7

Please sign in to comment.