Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 1 | // Copyright 2021, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //! Functions for running instances of `crosvm`. |
| 16 | |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 17 | use crate::aidl::VirtualMachineCallbacks; |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 18 | use crate::Cid; |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 19 | use anyhow::{bail, Error}; |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 20 | use command_fds::CommandFdExt; |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 21 | use log::{debug, error, info}; |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 22 | use shared_child::SharedChild; |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 23 | use std::fs::{remove_dir_all, File}; |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 24 | use std::mem; |
Andrew Walbran | b15cd6e | 2021-07-05 16:38:07 +0000 | [diff] [blame] | 25 | use std::num::NonZeroU32; |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 26 | use std::os::unix::io::{AsRawFd, RawFd}; |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 27 | use std::path::PathBuf; |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 28 | use std::process::Command; |
Inseob Kim | 7f61fe7 | 2021-08-20 20:50:47 +0900 | [diff] [blame] | 29 | use std::sync::{Arc, Mutex}; |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 30 | use std::thread; |
Inseob Kim | 7f61fe7 | 2021-08-20 20:50:47 +0900 | [diff] [blame] | 31 | use vsock::VsockStream; |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 32 | |
| 33 | const CROSVM_PATH: &str = "/apex/com.android.virt/bin/crosvm"; |
| 34 | |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 35 | /// Configuration for a VM to run with crosvm. |
| 36 | #[derive(Debug)] |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 37 | pub struct CrosvmConfig { |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 38 | pub cid: Cid, |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 39 | pub bootloader: Option<File>, |
| 40 | pub kernel: Option<File>, |
| 41 | pub initrd: Option<File>, |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 42 | pub disks: Vec<DiskFile>, |
| 43 | pub params: Option<String>, |
Andrew Walbran | f865042 | 2021-06-09 15:54:09 +0000 | [diff] [blame] | 44 | pub protected: bool, |
Andrew Walbran | b15cd6e | 2021-07-05 16:38:07 +0000 | [diff] [blame] | 45 | pub memory_mib: Option<NonZeroU32>, |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 46 | pub log_fd: Option<File>, |
| 47 | pub indirect_files: Vec<File>, |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /// A disk image to pass to crosvm for a VM. |
| 51 | #[derive(Debug)] |
| 52 | pub struct DiskFile { |
| 53 | pub image: File, |
| 54 | pub writable: bool, |
| 55 | } |
| 56 | |
Andrew Walbran | 6b65066 | 2021-09-07 13:13:23 +0000 | [diff] [blame] | 57 | /// The lifecycle state which the payload in the VM has reported itself to be in. |
| 58 | /// |
| 59 | /// Note that the order of enum variants is significant; only forward transitions are allowed by |
| 60 | /// [`VmInstance::update_payload_state`]. |
| 61 | #[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] |
| 62 | pub enum PayloadState { |
| 63 | Starting, |
| 64 | Started, |
| 65 | Ready, |
| 66 | Finished, |
| 67 | } |
| 68 | |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 69 | /// The current state of the VM itself. |
| 70 | #[derive(Debug)] |
| 71 | pub enum VmState { |
| 72 | /// The VM has not yet tried to start. |
| 73 | NotStarted { |
| 74 | ///The configuration needed to start the VM, if it has not yet been started. |
| 75 | config: CrosvmConfig, |
| 76 | }, |
| 77 | /// The VM has been started. |
| 78 | Running { |
| 79 | /// The crosvm child process. |
| 80 | child: Arc<SharedChild>, |
| 81 | }, |
| 82 | /// The VM died or was killed. |
| 83 | Dead, |
| 84 | /// The VM failed to start. |
| 85 | Failed, |
| 86 | } |
| 87 | |
| 88 | impl VmState { |
| 89 | /// Tries to start the VM, if it is in the `NotStarted` state. |
| 90 | /// |
| 91 | /// Returns an error if the VM is in the wrong state, or fails to start. |
| 92 | fn start(&mut self, instance: Arc<VmInstance>) -> Result<(), Error> { |
| 93 | let state = mem::replace(self, VmState::Failed); |
| 94 | if let VmState::NotStarted { config } = state { |
| 95 | // If this fails and returns an error, `self` will be left in the `Failed` state. |
| 96 | let child = Arc::new(run_vm(config)?); |
| 97 | |
| 98 | let child_clone = child.clone(); |
| 99 | thread::spawn(move || { |
| 100 | instance.monitor(child_clone); |
| 101 | }); |
| 102 | |
| 103 | // If it started correctly, update the state. |
| 104 | *self = VmState::Running { child }; |
| 105 | Ok(()) |
| 106 | } else { |
| 107 | *self = state; |
| 108 | bail!("VM already started or failed") |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /// Information about a particular instance of a VM which may be running. |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 114 | #[derive(Debug)] |
| 115 | pub struct VmInstance { |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 116 | /// The current state of the VM. |
| 117 | pub vm_state: Mutex<VmState>, |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 118 | /// The CID assigned to the VM for vsock communication. |
| 119 | pub cid: Cid, |
Andrew Walbran | f865042 | 2021-06-09 15:54:09 +0000 | [diff] [blame] | 120 | /// Whether the VM is a protected VM. |
| 121 | pub protected: bool, |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 122 | /// Directory of temporary files used by the VM while it is running. |
| 123 | pub temporary_directory: PathBuf, |
Andrew Walbran | f6a1eb9 | 2021-04-01 11:16:02 +0000 | [diff] [blame] | 124 | /// The UID of the process which requested the VM. |
| 125 | pub requester_uid: u32, |
| 126 | /// The SID of the process which requested the VM. |
Andrew Walbran | 0203449 | 2021-04-13 15:05:07 +0000 | [diff] [blame] | 127 | pub requester_sid: String, |
Andrew Walbran | f6a1eb9 | 2021-04-01 11:16:02 +0000 | [diff] [blame] | 128 | /// The PID of the process which requested the VM. Note that this process may no longer exist |
| 129 | /// and the PID may have been reused for a different process, so this should not be trusted. |
Andrew Walbran | 0203449 | 2021-04-13 15:05:07 +0000 | [diff] [blame] | 130 | pub requester_debug_pid: i32, |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 131 | /// Callbacks to clients of the VM. |
| 132 | pub callbacks: VirtualMachineCallbacks, |
Inseob Kim | 7f61fe7 | 2021-08-20 20:50:47 +0900 | [diff] [blame] | 133 | /// Input/output stream of the payload run in the VM. |
| 134 | pub stream: Mutex<Option<VsockStream>>, |
Andrew Walbran | 6b65066 | 2021-09-07 13:13:23 +0000 | [diff] [blame] | 135 | /// The latest lifecycle state which the payload reported itself to be in. |
| 136 | payload_state: Mutex<PayloadState>, |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | impl VmInstance { |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 140 | /// Validates the given config and creates a new `VmInstance` but doesn't start running it. |
| 141 | pub fn new( |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 142 | config: CrosvmConfig, |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 143 | temporary_directory: PathBuf, |
Andrew Walbran | f6a1eb9 | 2021-04-01 11:16:02 +0000 | [diff] [blame] | 144 | requester_uid: u32, |
Andrew Walbran | 0203449 | 2021-04-13 15:05:07 +0000 | [diff] [blame] | 145 | requester_sid: String, |
| 146 | requester_debug_pid: i32, |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 147 | ) -> Result<VmInstance, Error> { |
| 148 | validate_config(&config)?; |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 149 | let cid = config.cid; |
| 150 | let protected = config.protected; |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 151 | Ok(VmInstance { |
| 152 | vm_state: Mutex::new(VmState::NotStarted { config }), |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 153 | cid, |
| 154 | protected, |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 155 | temporary_directory, |
Andrew Walbran | 0203449 | 2021-04-13 15:05:07 +0000 | [diff] [blame] | 156 | requester_uid, |
| 157 | requester_sid, |
| 158 | requester_debug_pid, |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 159 | callbacks: Default::default(), |
| 160 | stream: Mutex::new(None), |
| 161 | payload_state: Mutex::new(PayloadState::Starting), |
| 162 | }) |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 165 | /// Starts an instance of `crosvm` to manage the VM. The `crosvm` instance will be killed when |
| 166 | /// the `VmInstance` is dropped. |
| 167 | pub fn start(self: &Arc<Self>) -> Result<(), Error> { |
| 168 | self.vm_state.lock().unwrap().start(self.clone()) |
| 169 | } |
| 170 | |
| 171 | /// Waits for the crosvm child process to finish, then marks the VM as no longer running and |
| 172 | /// calls any callbacks. |
| 173 | /// |
| 174 | /// This takes a separate reference to the `SharedChild` rather than using the one in |
| 175 | /// `self.vm_state` to avoid holding the lock on `vm_state` while it is running. |
| 176 | fn monitor(&self, child: Arc<SharedChild>) { |
| 177 | match child.wait() { |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 178 | Err(e) => error!("Error waiting for crosvm instance to die: {}", e), |
| 179 | Ok(status) => info!("crosvm exited with status {}", status), |
| 180 | } |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 181 | |
| 182 | let mut vm_state = self.vm_state.lock().unwrap(); |
| 183 | *vm_state = VmState::Dead; |
| 184 | // Ensure that the mutex is released before calling the callbacks. |
| 185 | drop(vm_state); |
| 186 | |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 187 | self.callbacks.callback_on_died(self.cid); |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 188 | |
| 189 | // Delete temporary files. |
| 190 | if let Err(e) = remove_dir_all(&self.temporary_directory) { |
Andrew Walbran | 806f154 | 2021-06-10 14:07:12 +0000 | [diff] [blame] | 191 | error!("Error removing temporary directory {:?}: {}", self.temporary_directory, e); |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 192 | } |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Andrew Walbran | 6b65066 | 2021-09-07 13:13:23 +0000 | [diff] [blame] | 195 | /// Returns the last reported state of the VM payload. |
| 196 | pub fn payload_state(&self) -> PayloadState { |
| 197 | *self.payload_state.lock().unwrap() |
| 198 | } |
| 199 | |
| 200 | /// Updates the payload state to the given value, if it is a valid state transition. |
| 201 | pub fn update_payload_state(&self, new_state: PayloadState) -> Result<(), Error> { |
| 202 | let mut state_locked = self.payload_state.lock().unwrap(); |
| 203 | // Only allow forward transitions, e.g. from starting to started or finished, not back in |
| 204 | // the other direction. |
| 205 | if new_state > *state_locked { |
| 206 | *state_locked = new_state; |
| 207 | Ok(()) |
| 208 | } else { |
| 209 | bail!("Invalid payload state transition from {:?} to {:?}", *state_locked, new_state) |
| 210 | } |
| 211 | } |
| 212 | |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 213 | /// Kills the crosvm instance, if it is running. |
Andrew Walbran | dae0716 | 2021-03-12 17:05:20 +0000 | [diff] [blame] | 214 | pub fn kill(&self) { |
Andrew Walbran | f8d9411 | 2021-09-07 11:45:36 +0000 | [diff] [blame] | 215 | let vm_state = &*self.vm_state.lock().unwrap(); |
| 216 | if let VmState::Running { child } = vm_state { |
| 217 | // TODO: Talk to crosvm to shutdown cleanly. |
| 218 | if let Err(e) = child.kill() { |
| 219 | error!("Error killing crosvm instance: {}", e); |
| 220 | } |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 221 | } |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 225 | /// Starts an instance of `crosvm` to manage a new VM. |
| 226 | fn run_vm(config: CrosvmConfig) -> Result<SharedChild, Error> { |
| 227 | validate_config(&config)?; |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 228 | |
| 229 | let mut command = Command::new(CROSVM_PATH); |
| 230 | // TODO(qwandor): Remove --disable-sandbox. |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 231 | command.arg("run").arg("--disable-sandbox").arg("--cid").arg(config.cid.to_string()); |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 232 | |
Andrew Walbran | f865042 | 2021-06-09 15:54:09 +0000 | [diff] [blame] | 233 | if config.protected { |
| 234 | command.arg("--protected-vm"); |
| 235 | } |
| 236 | |
Andrew Walbran | b15cd6e | 2021-07-05 16:38:07 +0000 | [diff] [blame] | 237 | if let Some(memory_mib) = config.memory_mib { |
| 238 | command.arg("--mem").arg(memory_mib.to_string()); |
| 239 | } |
| 240 | |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 241 | if let Some(log_fd) = config.log_fd { |
Andrew Walbran | a89fc13 | 2021-03-17 17:08:36 +0000 | [diff] [blame] | 242 | command.stdout(log_fd); |
| 243 | } else { |
| 244 | // Ignore console output. |
| 245 | command.arg("--serial=type=sink"); |
| 246 | } |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 247 | |
| 248 | // Keep track of what file descriptors should be mapped to the crosvm process. |
Andrew Walbran | d3a8418 | 2021-09-07 14:48:52 +0000 | [diff] [blame] | 249 | let mut preserved_fds = config.indirect_files.iter().map(|file| file.as_raw_fd()).collect(); |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 250 | |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 251 | if let Some(bootloader) = &config.bootloader { |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 252 | command.arg("--bios").arg(add_preserved_fd(&mut preserved_fds, bootloader)); |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 253 | } |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 254 | |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 255 | if let Some(initrd) = &config.initrd { |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 256 | command.arg("--initrd").arg(add_preserved_fd(&mut preserved_fds, initrd)); |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 257 | } |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 258 | |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 259 | if let Some(params) = &config.params { |
| 260 | command.arg("--params").arg(params); |
| 261 | } |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 262 | |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 263 | for disk in &config.disks { |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 264 | command |
| 265 | .arg(if disk.writable { "--rwdisk" } else { "--disk" }) |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 266 | .arg(add_preserved_fd(&mut preserved_fds, &disk.image)); |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 267 | } |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 268 | |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 269 | if let Some(kernel) = &config.kernel { |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 270 | command.arg(add_preserved_fd(&mut preserved_fds, kernel)); |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 271 | } |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 272 | |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 273 | debug!("Preserving FDs {:?}", preserved_fds); |
| 274 | command.preserved_fds(preserved_fds); |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 275 | |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 276 | info!("Running {:?}", command); |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 277 | let result = SharedChild::spawn(&mut command)?; |
| 278 | Ok(result) |
| 279 | } |
| 280 | |
| 281 | /// Ensure that the configuration has a valid combination of fields set, or return an error if not. |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 282 | fn validate_config(config: &CrosvmConfig) -> Result<(), Error> { |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 283 | if config.bootloader.is_none() && config.kernel.is_none() { |
| 284 | bail!("VM must have either a bootloader or a kernel image."); |
| 285 | } |
| 286 | if config.bootloader.is_some() && (config.kernel.is_some() || config.initrd.is_some()) { |
| 287 | bail!("Can't have both bootloader and kernel/initrd image."); |
| 288 | } |
| 289 | Ok(()) |
| 290 | } |
| 291 | |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 292 | /// Adds the file descriptor for `file` to `preserved_fds`, and returns a string of the form |
| 293 | /// "/proc/self/fd/N" where N is the file descriptor. |
| 294 | fn add_preserved_fd(preserved_fds: &mut Vec<RawFd>, file: &File) -> String { |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 295 | let fd = file.as_raw_fd(); |
Andrew Walbran | 02b8ec0 | 2021-06-22 13:07:02 +0000 | [diff] [blame] | 296 | preserved_fds.push(fd); |
Andrew Walbran | 3a5a921 | 2021-05-04 17:09:08 +0000 | [diff] [blame] | 297 | format!("/proc/self/fd/{}", fd) |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 298 | } |