Created
June 16, 2019 22:02
-
-
Save giuseppe/723ef3db03b66be8caf3ce76d3e2869f to your computer and use it in GitHub Desktop.
crun rust hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::env; | |
use std::process::Command; | |
use std::path::Path; | |
fn main() { | |
let out_dir = env::var("OUT_DIR").unwrap(); | |
Command::new("make").current_dir(&Path::new("../..")).arg("install").arg(&format!("DESTDIR={}", out_dir)).status().unwrap(); | |
println!("cargo:rustc-link-search=native={}/usr/local/lib", out_dir); | |
println!("cargo:rustc-link-lib=static=crun"); | |
println!("cargo:rustc-link-lib=yajl"); | |
println!("cargo:rustc-link-lib=seccomp"); | |
println!("cargo:rustc-link-lib=systemd"); | |
println!("cargo:rustc-link-lib=selinux"); | |
println!("cargo:rustc-link-lib=cap"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod libcrun; | |
use std::ptr; | |
use crate::libcrun::libcrun_context_s; | |
use crate::libcrun::libcrun_context_t; | |
use crate::libcrun::libcrun_error_s; | |
use crate::libcrun::libcrun_error_t; | |
use crate::libcrun::libcrun_container_start; | |
use crate::libcrun::log_write_to_stderr; | |
use std::ffi::CString; | |
fn get_context(cid: *const ::std::os::raw::c_char) -> libcrun_context_s { | |
let mut ctx = libcrun_context_s { | |
state_root: ::std::ptr::null(), | |
id: cid, | |
bundle: ::std::ptr::null(), | |
console_socket: ::std::ptr::null(), | |
pid_file: ::std::ptr::null(), | |
notify_socket: ::std::ptr::null(), | |
preserve_fds: 0, | |
output_handler: Some(log_write_to_stderr), | |
output_handler_arg: ::std::ptr::null_mut(), | |
fifo_exec_wait_fd: -1, | |
systemd_cgroup: false, | |
detach: false, | |
no_subreaper: false, | |
no_new_keyring: false, | |
}; | |
ctx | |
} | |
fn main() { | |
let c = CString::new("foo").expect("CString failed").into_raw(); | |
let mut err = ::std::ptr::null_mut::<libcrun_error_s>(); | |
let mut ctx = get_context(c); | |
unsafe { | |
libcrun_container_start(&mut ctx, c, &mut err); | |
if err != ::std::ptr::null_mut::<libcrun_error_s>() { | |
print!("Got {:#?} \n", CString::from_raw((*err).msg)); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment