Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
init container id by random ascii chars
Browse files Browse the repository at this point in the history
  • Loading branch information
guni1192 committed Mar 8, 2019
1 parent 0959a2a commit f3360a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ flate2 = "1.0"
dirs = "1.0"
log = "0.4"
env_logger = "0.6.0"
rand = "0.6"
12 changes: 11 additions & 1 deletion src/container.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::ffi::CString;
use std::fs::{self, File};
use std::io::prelude::*;
use std::iter;

use nix::sched::{unshare, CloneFlags};
use nix::sys::wait::{waitpid, WaitStatus};
use nix::unistd::{chdir, chroot, fork, getgid, getpid, getuid, ForkResult, Gid, Uid};
use nix::unistd::{execve, sethostname};

use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};

use log::info;

use super::image::Image;
Expand All @@ -23,8 +27,14 @@ pub struct Container {

impl Container {
pub fn new(name: &str, command: String) -> Container {
let mut rng = thread_rng();
let id: String = iter::repeat(())
.map(|()| rng.sample(Alphanumeric))
.take(16)
.collect();

Container {
id: "hogeeeeeeeeeeeeeeeee".to_string(),
id: id,
name: name.to_string(),
command,
image: Image::new(name),
Expand Down

0 comments on commit f3360a5

Please sign in to comment.