Skip to content

Commit d3feea2

Browse files
committed
Impl Default for lxc_attach_option_t
1 parent 60297bb commit d3feea2

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ v1_0 = []
2525
v1_1 = ["v1_0"]
2626
v2_0 = ["v1_1"]
2727
v2_1 = ["v2_0"]
28-
v3_0 = ["v2_1"]
28+
v3_0 = ["v2_1", "lxc-sys/v3_0"]
2929
v3_1 = ["v3_0"]
3030
v3_2 = ["v3_1"]
31-
v4_0 = ["v3_2"]
31+
v4_0 = ["v3_2", "lxc-sys/v4_0"]
3232
v4_0_5 = ["v4_0"]

examples/run_command.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
extern crate lxc;
2-
3-
use std::os::unix::io::AsRawFd;
4-
51
fn main() -> std::io::Result<()> {
62
let c =
73
lxc::Container::new("apicontainer", None).expect("Failed to setup lxc_container struct");
@@ -21,25 +17,9 @@ fn main() -> std::io::Result<()> {
2117

2218
c.start(false, &[]).expect("Failed to start the container");
2319

24-
let mut options = lxc::attach::Options {
25-
attach_flags: 0,
26-
env_policy: 0,
27-
extra_env_vars: std::ptr::null_mut(),
28-
gid: 0,
29-
uid: 0,
30-
extra_keep_env: std::ptr::null_mut(),
31-
initial_cwd: std::ptr::null_mut(),
32-
#[cfg(feature = "v3_0")]
33-
log_fd: std::io::stdout().as_raw_fd(),
34-
stdout_fd: std::io::stdout().as_raw_fd(),
35-
stderr_fd: std::io::stderr().as_raw_fd(),
36-
stdin_fd: std::io::stdin().as_raw_fd(),
37-
namespaces: -1,
38-
personality: -1,
39-
};
4020
let prog = "/bin/ps";
4121
let args = [prog, "auxw"];
42-
let r = c.attach_run_wait(&mut options, prog, &args);
22+
let r = c.attach_run_wait(&mut lxc::attach::Options::default(), prog, &args);
4323
match r {
4424
Err(e) => println!("Error: {}", e),
4525
Ok(s) => println!("Ok, waitpid() status={}", s),

lxc-sys/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ libc="0.2"
1616

1717
[build-dependencies]
1818
bindgen = "0.59"
19+
20+
[features]
21+
v3_0 = []
22+
v4_0 = []

lxc-sys/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,31 @@
66
#![allow(clippy::unreadable_literal)]
77

88
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
9+
10+
impl Default for lxc_attach_options_t {
11+
fn default() -> Self {
12+
Self {
13+
attach_flags: LXC_ATTACH_DEFAULT as i32,
14+
namespaces: -1,
15+
personality: LXC_ATTACH_DETECT_PERSONALITY as i64,
16+
initial_cwd: std::ptr::null_mut(),
17+
gid: u32::MAX,
18+
uid: u32::MAX,
19+
env_policy: lxc_attach_env_policy_t_LXC_ATTACH_KEEP_ENV,
20+
extra_env_vars: std::ptr::null_mut(),
21+
extra_keep_env: std::ptr::null_mut(),
22+
stdout_fd: 0,
23+
stdin_fd: 1,
24+
stderr_fd: 2,
25+
#[cfg(feature = "v3_0")]
26+
log_fd: -libc::EBADF,
27+
#[cfg(feature = "v4_0")]
28+
lsm_label: std::ptr::null_mut(),
29+
#[cfg(feature = "v4_0")]
30+
groups: lxc_groups_t {
31+
size: 0,
32+
list: std::ptr::null_mut(),
33+
},
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)