Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 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 @@ -30,6 +30,7 @@ nix = { version = "0.30.1", features = ["feature", "fs", "mount", "process", "te
getrandom = { version = "0.2.15" }
log = { version = "0.4.21", features = ["std"], default-features = false}
json = { version = "0.12.4", optional = true }
git-version = { version = "0.3.9" }

[features]
default = ["systemd", "dmverity", "usb9pfs", "reboot-on-failure"]
Expand Down
4 changes: 2 additions & 2 deletions src/dmverity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::os::fd::IntoRawFd;
use std::path::Path;

use getrandom::getrandom;
use log::debug;
use log::{debug, info};
use nix::ioctl_readwrite;
use nix::libc::dev_t;
use nix::sys::stat::minor;
Expand Down Expand Up @@ -246,7 +246,7 @@ pub fn prepare_dmverity(options: &mut CmdlineOptions) -> Result<bool> {
let param_data = read_file("/verity-params")?;
let params = VerityParams::from_string(&param_data)?;

debug!(
info!(
"Configuring dm-verity rootfs with root-hash = {}",
params.root_hash
);
Expand Down
17 changes: 8 additions & 9 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use std::os::fd::AsFd;
use std::os::unix::ffi::OsStrExt;
use std::panic::set_hook;

use log::{debug, error, LevelFilter};
use git_version::git_version;
use log::{error, info};
#[cfg(feature = "reboot-on-failure")]
use nix::sys::reboot::{reboot, RebootMode};
use nix::sys::termios::tcdrain;
Expand Down Expand Up @@ -53,12 +54,6 @@ fn setup_console() -> Result<()> {
Ok(())
}

pub fn setup_log() -> Result<()> {
let logger = Logger::new()?;
log::set_boxed_logger(Box::new(logger)).map(|()| log::set_max_level(LevelFilter::Trace))?;
Ok(())
}

fn finalize() {
/* Make sure all output is written before exiting */
let _ = tcdrain(io::stdout().as_fd());
Expand Down Expand Up @@ -182,7 +177,11 @@ impl<'a> InitContext<'a> {
pub fn setup(&mut self) -> Result<()> {
mount_special()?;

setup_log()?;
Logger::enable()?;
info!(
concat!(env!("CARGO_PKG_NAME"), " version {}"),
git_version!(fallback = env!("CARGO_PKG_VERSION"))
);
Comment on lines +181 to +184

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
info!(
concat!(env!("CARGO_PKG_NAME"), " version {}"),
git_version!(fallback = env!("CARGO_PKG_VERSION"))
);
info!(
"{} version {}",
env!("CARGO_PKG_NAME"),
git_version!(fallback = env!("CARGO_PKG_VERSION"))
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not do that.

  1. It adds extra overhead at runtime instead of combining the string literals at compile time
  2. The concat makes it clearer which parts are evaluated at runtime and which at compile time

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, fine with me.


self.options = self.parser.parse_file("/proc/cmdline")?;

Expand Down Expand Up @@ -260,7 +259,7 @@ impl<'a> InitContext<'a> {
write!(buf, "{} ", arg.to_bytes().escape_ascii())?;
}
writeln!(buf, "...")?;
debug!("{}", &buf);
info!("{}", &buf);

execv(&args[0], &args)?;

Expand Down
7 changes: 6 additions & 1 deletion src/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fs::{File, OpenOptions};
use std::io::Write as _;
use std::path::Path;

use log::{Metadata, Record};
use log::{LevelFilter, Metadata, Record};

use crate::kmsg::KmsgLogger;
use crate::util::Result;
Expand Down Expand Up @@ -38,6 +38,11 @@ impl IntegrationLogger {
let kmsg = KmsgLogger::new()?;
Ok(IntegrationLogger { next: kmsg, vport })
}
pub fn enable() -> Result<()> {
let logger = IntegrationLogger::new()?;
log::set_boxed_logger(Box::new(logger)).map(|()| log::set_max_level(LevelFilter::Trace))?;
Ok(())
}
}

impl log::Log for IntegrationLogger {
Expand Down
7 changes: 6 additions & 1 deletion src/kmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::borrow::Borrow;
use std::fs::{File, OpenOptions};
use std::io::Write as _;

use log::{Level, Metadata, Record};
use log::{Level, LevelFilter, Metadata, Record};

use crate::util::Result;

Expand Down Expand Up @@ -38,4 +38,9 @@ impl KmsgLogger {
let kmsg = OpenOptions::new().write(true).open("/dev/kmsg")?;
Ok(KmsgLogger { kmsg })
}
pub fn enable() -> Result<()> {
let logger = KmsgLogger::new()?;
log::set_boxed_logger(Box::new(logger)).map(|()| log::set_max_level(LevelFilter::Trace))?;
Ok(())
}
}
8 changes: 4 additions & 4 deletions src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::fs::{self, remove_dir};
use std::path::{Path, PathBuf};

use log::{debug, warn};
use log::{info, warn};
use nix::{
mount::{mount, umount, MsFlags},
sys::utsname::uname,
Expand All @@ -23,7 +23,7 @@ pub fn do_mount(

mount(src, dst, fstype, flags, data).map_err(|e| {
format!(
"Failed to mount {} -> {} as {} with flags = {:#x}, data = '{}'): {e}",
"Failed to mount {} -> {} as '{}' with flags = {:#x}, data = '{}'): {e}",
src.unwrap_or_default(),
dst,
fstype.unwrap_or_default(),
Expand Down Expand Up @@ -75,8 +75,8 @@ pub fn mount_root(
}
mkdir("/root")?;

debug!(
"Mounting rootfs {} -> /root as {} with flags = {:#x}, data = '{}'",
info!(
"Mounting rootfs {} -> /root as '{}' with flags = {:#x}, data = '{}'",
device.ok_or("No root device argument")?,
fstype.unwrap_or_default(),
fsflags.bits(),
Expand Down
6 changes: 3 additions & 3 deletions src/usbg_9pfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs::{read_dir, write};
use std::os::unix::fs::symlink;
use std::{thread, time};

use log::debug;
use log::info;
use nix::mount::MsFlags;

use crate::cmdline::CmdlineOptions;
Expand All @@ -17,7 +17,7 @@ fn write_file<C: AsRef<[u8]>>(path: &str, content: C) -> Result<()> {
}

fn setup_9pfs_gadget(options: &mut CmdlineOptions) -> Result<()> {
debug!("Initializing USB 9pfs gadget ...");
info!("Initializing USB 9pfs gadget ...");

let device = if let Some(root) = &mut options.root {
if let Some(index) = root.find('/') {
Expand Down Expand Up @@ -71,7 +71,7 @@ fn setup_9pfs_gadget(options: &mut CmdlineOptions) -> Result<()> {
mkdir(&function)?;
symlink(&function, &link)?;

debug!("Attaching 9pfs gatget to UDC {device}");
info!("Attaching 9pfs gatget to UDC {device}");
write_file("/sys/kernel/config/usb_gadget/9pfs/UDC", device)?;

let d = time::Duration::new(1, 0);
Expand Down
2 changes: 1 addition & 1 deletion test/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __ensure_kernel(self, url, file, sha256):

def run(self):
args = [f"qemu-system-{self.__arch}"]
cmdline = "loglevel=8 panic=-1"
cmdline = "loglevel=7 panic=-1"
match self.__arch:
case "x86_64":
args += ["-machine", "q35"]
Expand Down
6 changes: 3 additions & 3 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def test_missing_root(genimage, qemu):
qemu.set_initramfs(genimage.get_initramfs())
qemu.set_cmdline("root=/dev/vda1")
result = qemu.run()
assert result.rsinit_messages == [
{"message": "Timeout reached while waiting for the device"}
]
assert result.rsinit_messages[-1] == {
"message": "Timeout reached while waiting for the device"
}
assert not result.mountinfo


Expand Down
Loading