diff --git a/micro-activate.rs b/micro-activate.rs index 0806e96..776dae4 100644 --- a/micro-activate.rs +++ b/micro-activate.rs @@ -8,6 +8,8 @@ const MS_NODEV: c_ulong = 0x04; const MS_RELATIME: c_ulong = 0x200000; const MS_STRICTATIME: c_ulong = 0x1000000; +const CLONE_NEWTIME: c_int = 0x80; + unsafe extern "C" { fn mount( src: *const c_char, @@ -17,6 +19,7 @@ unsafe extern "C" { data: *const c_void, ) -> c_int; fn getrandom(buf: *mut u8, buflen: usize, flags: u32) -> c_int; + fn unshare(flags: c_int) -> c_int; } fn gen_machine_id() -> String { @@ -133,6 +136,17 @@ fn main() -> Result<(), std::io::Error> { ); } + if let Ok(offset) = std::env::var("BOOT_TIME_OFFSET") { + if unsafe { unshare(CLONE_NEWTIME) } != 0 { + eprintln!("[micro-activate] Could not unshare time!"); + } else { + std::fs::write( + "/proc/self/timens_offsets", + format!("monotonic {offset}\nboottime {offset}\n"), + )?; + } + } + let mut args = std::env::args_os().skip(1); let cmd = args.next().unwrap(); Err(std::process::Command::new(cmd).args(args).exec()) diff --git a/munix b/munix index 89d79c3..4f26980 100755 --- a/munix +++ b/munix @@ -204,6 +204,10 @@ if [ "$USING_PUBLISH" -eq 1 ]; then printf "\n\n\n\e[1mNote: due to a \e[31mBUG\e[39m with port publishing (-p) you have to send the first outgoing packet (e.g. ping -c1 8.8.8.8) before your ports start receiving traffic. Sorry for the inconvenience!\e[39;0m\n\n\n\n" >&2 fi +# xxx: some time is lost to the starting process.. +[[ "$(