(&self)
| 56 | } |
| 57 | |
| 58 | pub fn emit(&self) -> Result<()> { |
| 59 | let logline = serde_json::to_string(self).context("failed to serialize event log")?; |
| 60 | |
| 61 | let logfile_path = std::path::Path::new(RUNTIME_EVENT_LOG_FILE); |
| 62 | let logfile_dir = logfile_path |
| 63 | .parent() |
| 64 | .context("failed to get event log directory")?; |
| 65 | fs::create_dir_all(logfile_dir).context("failed to create event log directory")?; |
| 66 | |
| 67 | let mut options = fs::OpenOptions::new(); |
| 68 | options.append(true).create(true); |
| 69 | |
| 70 | // Restrict runtime event log visibility and writability to the owner (root). |
| 71 | // This avoids other processes in the CVM tampering with or reading the log. |
| 72 | #[cfg(unix)] |
| 73 | { |
| 74 | use fs_err::os::unix::fs::OpenOptionsExt; |
| 75 | options.mode(0o600); |
| 76 | } |
| 77 | |
| 78 | let mut logfile = options |
| 79 | .open(logfile_path) |
| 80 | .context("failed to open event log file")?; |
| 81 | |
| 82 | logfile |
| 83 | .write_all(logline.as_bytes()) |
| 84 | .context("failed to write to event log file")?; |
| 85 | logfile |
| 86 | .write_all(b"\n") |
| 87 | .context("failed to write to event log file")?; |
| 88 | Ok(()) |
| 89 | } |
| 90 | |
| 91 | pub fn sha384_digest(&self) -> [u8; 48] { |
| 92 | self.digest::<Sha384>() |
no test coverage detected