Skip to content

Commit 8f21d19

Browse files
fix: Support creating file with open_file_nonblock
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]>
1 parent 1a2c6ad commit 8f21d19

File tree

4 files changed

+1
-18
lines changed

4 files changed

+1
-18
lines changed

docs/getting-started.md

-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ sudo iptables -I FORWARD 1 -i tap0 -o eth0 -j ACCEPT
134134
API_SOCKET="/tmp/firecracker.socket"
135135
LOGFILE="./firecracker.log"
136136

137-
# Create log file
138-
touch $LOGFILE
139-
140137
# Set log file
141138
curl -X PUT --unix-socket "${API_SOCKET}" \
142139
--data "{

src/vmm/src/vmm_config/logger.rs

-9
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,6 @@ mod tests {
152152
fn test_init_logger() {
153153
let default_instance_info = InstanceInfo::default();
154154

155-
// Error case: initializing logger with invalid pipe returns error.
156-
let desc = LoggerConfig {
157-
log_path: PathBuf::from("not_found_file_log"),
158-
level: LoggerLevel::Debug,
159-
show_level: false,
160-
show_log_origin: false,
161-
};
162-
assert!(init_logger(desc, &default_instance_info).is_err());
163-
164155
// Initializing logger with valid pipe is ok.
165156
let log_file = TempFile::new().unwrap();
166157
let desc = LoggerConfig {

src/vmm/src/vmm_config/metrics.rs

-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ mod tests {
4343

4444
#[test]
4545
fn test_init_metrics() {
46-
// Error case: initializing metrics with invalid pipe returns error.
47-
let desc = MetricsConfig {
48-
metrics_path: PathBuf::from("not_found_file_metrics"),
49-
};
50-
assert!(init_metrics(desc).is_err());
51-
5246
// Initializing metrics with valid pipe is ok.
5347
let metrics_file = TempFile::new().unwrap();
5448
let desc = MetricsConfig {

src/vmm/src/vmm_config/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ impl RateLimiterConfig {
172172
fn open_file_nonblock(path: &Path) -> Result<File, std::io::Error> {
173173
OpenOptions::new()
174174
.custom_flags(O_NONBLOCK)
175+
.create(true)
175176
.read(true)
176177
.write(true)
177178
.open(path)

0 commit comments

Comments
 (0)