Skip to content

Commit

Permalink
fix: Support creating file with open_file_nonblock
Browse files Browse the repository at this point in the history
Updates the `OpenOptions` with `.create(true)` to support creating a
file when if it doesn't exist. This also brings the functionality
inline with the documentation which notes
`Create and opens a File for writing to it.`. This improves usability
simplifying setting up the logger.

Signed-off-by: Jonathan Woollett-Light <[email protected]>
  • Loading branch information
Jonathan Woollett-Light committed Aug 11, 2023
1 parent 1a2c6ad commit 564f44b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 12 deletions.
3 changes: 0 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ sudo iptables -I FORWARD 1 -i tap0 -o eth0 -j ACCEPT
API_SOCKET="/tmp/firecracker.socket"
LOGFILE="./firecracker.log"

# Create log file
touch $LOGFILE

# Set log file
curl -X PUT --unix-socket "${API_SOCKET}" \
--data "{
Expand Down
9 changes: 0 additions & 9 deletions src/vmm/src/vmm_config/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,6 @@ mod tests {
fn test_init_logger() {
let default_instance_info = InstanceInfo::default();

// Error case: initializing logger with invalid pipe returns error.
let desc = LoggerConfig {
log_path: PathBuf::from("not_found_file_log"),
level: LoggerLevel::Debug,
show_level: false,
show_log_origin: false,
};
assert!(init_logger(desc, &default_instance_info).is_err());

// Initializing logger with valid pipe is ok.
let log_file = TempFile::new().unwrap();
let desc = LoggerConfig {
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/vmm_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl RateLimiterConfig {
fn open_file_nonblock(path: &Path) -> Result<File, std::io::Error> {
OpenOptions::new()
.custom_flags(O_NONBLOCK)
.create(true)
.read(true)
.write(true)
.open(path)
Expand Down

0 comments on commit 564f44b

Please sign in to comment.