Skip to content

Commit

Permalink
Add args to entrypoint.
Browse files Browse the repository at this point in the history
Signed-off-by: Klaus Ma <klausm@nvidia.com>
  • Loading branch information
k82cn committed Oct 17, 2024
1 parent 166c96f commit fa646c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
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: /bin/ls
entrypoint: ["/bin/ls", "/"]
4 changes: 2 additions & 2 deletions src/apis/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ pub type ChariotResult<T> = Result<T, Box<dyn Error>>;
pub struct Sandbox {
pub name: String,
pub image: String,
pub entrypoint: String,
pub entrypoint: Vec<String>,
pub containers: Vec<Container>,
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)]
pub struct Container {
pub name: String,
pub image: String,
pub entrypoint: String,
pub entrypoint: Vec<String>,
}

#[derive(thiserror::Error, Debug)]
Expand Down
17 changes: 11 additions & 6 deletions src/core/cmd/runc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

use std::ffi::{CStr, CString};
use std::ffi::{CString};
use std::fs;
use std::io::{Read, Write};
use std::{thread, time};
Expand Down Expand Up @@ -176,13 +176,18 @@ fn run_container(cxt: cfg::Context, container: Container) -> ChariotResult<()> {
// Setup fstab, e.g. /proc, /dev.
// setup_fstab(cxt.clone(), container.clone())?;

tracing::debug!("Redirect container stdout/stderr to log file.");
dup2(log, 1)?;
dup2(log, 2)?;
let cmd = CString::new(container.entrypoint[0].as_bytes())?;
let args = container
.entrypoint
.iter()
.filter_map(|c| CString::new(c.as_bytes()).ok())
.collect::<Vec<_>>();

// execute `container entrypoint`
let cmd = CString::new(container.entrypoint.as_bytes())?;
execve::<&CStr, &CStr>(cmd.as_c_str(), &[cmd.as_c_str()], &[])?;
tracing::debug!("Redirect container stdout/stderr to log file, and execve the entrypoint.");
dup2(log, 1)?;
dup2(log, 2)?;
execve::<CString, CString>(&cmd, args.as_slice(), &[])?;

Ok(())
}
Expand Down

0 comments on commit fa646c5

Please sign in to comment.