Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 17 | use anyhow::{anyhow, bail, Context, Result}; |
Victor Hsieh | 616f822 | 2022-01-14 13:06:32 -0800 | [diff] [blame] | 18 | use log::{debug, info, warn}; |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 19 | use minijail::{self, Minijail}; |
Alan Stokes | 9247251 | 2022-01-04 11:48:38 +0000 | [diff] [blame] | 20 | use regex::Regex; |
Alan Stokes | 2d2e4db | 2022-01-28 16:41:52 +0000 | [diff] [blame] | 21 | use rustutils::system_properties; |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 22 | use std::collections::HashMap; |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 23 | use std::env; |
Alan Stokes | 9247251 | 2022-01-04 11:48:38 +0000 | [diff] [blame] | 24 | use std::ffi::OsString; |
Victor Hsieh | 616f822 | 2022-01-14 13:06:32 -0800 | [diff] [blame] | 25 | use std::fs::read_dir; |
Alan Stokes | 35bac3c | 2021-12-16 14:37:24 +0000 | [diff] [blame] | 26 | use std::path::{self, Path, PathBuf}; |
Alan Stokes | 9247251 | 2022-01-04 11:48:38 +0000 | [diff] [blame] | 27 | use std::process::Command; |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 28 | |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 29 | use crate::artifact_signer::ArtifactSigner; |
Alan Stokes | 611cc94 | 2022-02-01 10:16:21 +0000 | [diff] [blame] | 30 | use crate::signing_key::DiceSigner; |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 31 | use authfs_aidl_interface::aidl::com::android::virt::fs::{ |
Victor Hsieh | 015bcb5 | 2021-11-17 17:28:01 -0800 | [diff] [blame] | 32 | AuthFsConfig::{ |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 33 | AuthFsConfig, InputDirFdAnnotation::InputDirFdAnnotation, |
Victor Hsieh | 616f822 | 2022-01-14 13:06:32 -0800 | [diff] [blame] | 34 | OutputDirFdAnnotation::OutputDirFdAnnotation, |
Victor Hsieh | 015bcb5 | 2021-11-17 17:28:01 -0800 | [diff] [blame] | 35 | }, |
Victor Hsieh | 015bcb5 | 2021-11-17 17:28:01 -0800 | [diff] [blame] | 36 | IAuthFsService::IAuthFsService, |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 37 | }; |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 38 | use authfs_aidl_interface::binder::Strong; |
Alan Stokes | 2d2e4db | 2022-01-28 16:41:52 +0000 | [diff] [blame] | 39 | use compos_aidl_interface::aidl::com::android::compos::ICompOsService::CompilationMode::CompilationMode; |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 40 | use compos_common::odrefresh::ExitCode; |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 41 | |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 42 | const FD_SERVER_PORT: i32 = 3264; // TODO: support dynamic port |
| 43 | |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 44 | pub struct OdrefreshContext<'a> { |
Alan Stokes | 2d2e4db | 2022-01-28 16:41:52 +0000 | [diff] [blame] | 45 | compilation_mode: CompilationMode, |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 46 | system_dir_fd: i32, |
| 47 | output_dir_fd: i32, |
Alan Stokes | 9646db9 | 2021-12-14 13:22:33 +0000 | [diff] [blame] | 48 | staging_dir_fd: i32, |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 49 | target_dir_name: &'a str, |
| 50 | zygote_arch: &'a str, |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 51 | system_server_compiler_filter: &'a str, |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | impl<'a> OdrefreshContext<'a> { |
| 55 | pub fn new( |
Alan Stokes | 2d2e4db | 2022-01-28 16:41:52 +0000 | [diff] [blame] | 56 | compilation_mode: CompilationMode, |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 57 | system_dir_fd: i32, |
| 58 | output_dir_fd: i32, |
| 59 | staging_dir_fd: i32, |
| 60 | target_dir_name: &'a str, |
| 61 | zygote_arch: &'a str, |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 62 | system_server_compiler_filter: &'a str, |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 63 | ) -> Result<Self> { |
Alan Stokes | 2d2e4db | 2022-01-28 16:41:52 +0000 | [diff] [blame] | 64 | if compilation_mode != CompilationMode::NORMAL_COMPILE { |
| 65 | let debuggable = system_properties::read_bool("ro.boot.microdroid.debuggable", false)?; |
| 66 | if !debuggable { |
| 67 | bail!("Requested compilation mode only available in debuggable VMs"); |
| 68 | } |
| 69 | } |
| 70 | |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 71 | if system_dir_fd < 0 || output_dir_fd < 0 || staging_dir_fd < 0 { |
| 72 | bail!("The remote FDs are expected to be non-negative"); |
| 73 | } |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 74 | if !matches!(zygote_arch, "zygote64" | "zygote64_32") { |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 75 | bail!("Invalid zygote arch"); |
| 76 | } |
Alan Stokes | 35bac3c | 2021-12-16 14:37:24 +0000 | [diff] [blame] | 77 | // Disallow any sort of path traversal |
| 78 | if target_dir_name.contains(path::MAIN_SEPARATOR) { |
| 79 | bail!("Invalid target directory {}", target_dir_name); |
| 80 | } |
| 81 | |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 82 | // We're not validating/allowlisting the compiler filter, and just assume the compiler will |
| 83 | // reject an invalid string. We need to accept "verify" filter anyway, and potential |
| 84 | // performance degration by the attacker is not currently in scope. This also allows ART to |
| 85 | // specify new compiler filter and configure through system property without change to |
| 86 | // CompOS. |
| 87 | |
| 88 | Ok(Self { |
Alan Stokes | 2d2e4db | 2022-01-28 16:41:52 +0000 | [diff] [blame] | 89 | compilation_mode, |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 90 | system_dir_fd, |
| 91 | output_dir_fd, |
| 92 | staging_dir_fd, |
| 93 | target_dir_name, |
| 94 | zygote_arch, |
| 95 | system_server_compiler_filter, |
| 96 | }) |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | pub fn odrefresh( |
| 101 | odrefresh_path: &Path, |
| 102 | context: OdrefreshContext, |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 103 | authfs_service: Strong<dyn IAuthFsService>, |
Alan Stokes | 611cc94 | 2022-02-01 10:16:21 +0000 | [diff] [blame] | 104 | signer: DiceSigner, |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 105 | ) -> Result<ExitCode> { |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 106 | // Mount authfs (via authfs_service). The authfs instance unmounts once the `authfs` variable |
| 107 | // is out of scope. |
| 108 | let authfs_config = AuthFsConfig { |
| 109 | port: FD_SERVER_PORT, |
| 110 | inputDirFdAnnotations: vec![InputDirFdAnnotation { |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 111 | fd: context.system_dir_fd, |
Victor Hsieh | 9978257 | 2022-01-05 15:38:33 -0800 | [diff] [blame] | 112 | // 0 is the index of extra_apks in vm_config_extra_apk.json |
| 113 | manifestPath: "/mnt/extra-apk/0/assets/build_manifest.pb".to_string(), |
| 114 | prefix: "system/".to_string(), |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 115 | }], |
Alan Stokes | 9646db9 | 2021-12-14 13:22:33 +0000 | [diff] [blame] | 116 | outputDirFdAnnotations: vec![ |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 117 | OutputDirFdAnnotation { fd: context.output_dir_fd }, |
| 118 | OutputDirFdAnnotation { fd: context.staging_dir_fd }, |
Alan Stokes | 9646db9 | 2021-12-14 13:22:33 +0000 | [diff] [blame] | 119 | ], |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 120 | ..Default::default() |
| 121 | }; |
| 122 | let authfs = authfs_service.mount(&authfs_config)?; |
| 123 | let mountpoint = PathBuf::from(authfs.getMountPoint()?); |
| 124 | |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 125 | // Make a copy of our environment as the basis of the one we will give odrefresh |
| 126 | let mut odrefresh_vars = EnvMap::from_current_env(); |
| 127 | |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 128 | let mut android_root = mountpoint.clone(); |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 129 | android_root.push(context.system_dir_fd.to_string()); |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 130 | android_root.push("system"); |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 131 | odrefresh_vars.set("ANDROID_ROOT", path_to_str(&android_root)?); |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 132 | debug!("ANDROID_ROOT={:?}", &android_root); |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 133 | |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 134 | let art_apex_data = mountpoint.join(context.output_dir_fd.to_string()); |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 135 | odrefresh_vars.set("ART_APEX_DATA", path_to_str(&art_apex_data)?); |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 136 | debug!("ART_APEX_DATA={:?}", &art_apex_data); |
Victor Hsieh | 64df53d | 2021-11-30 17:09:51 -0800 | [diff] [blame] | 137 | |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 138 | let staging_dir = mountpoint.join(context.staging_dir_fd.to_string()); |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 139 | |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 140 | set_classpaths(&mut odrefresh_vars, &android_root)?; |
Alan Stokes | 9247251 | 2022-01-04 11:48:38 +0000 | [diff] [blame] | 141 | |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 142 | let mut args = vec![ |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 143 | "odrefresh".to_string(), |
Alan Stokes | 48c1d2b | 2022-01-10 15:54:04 +0000 | [diff] [blame] | 144 | "--compilation-os-mode".to_string(), |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 145 | format!("--zygote-arch={}", context.zygote_arch), |
| 146 | format!("--dalvik-cache={}", context.target_dir_name), |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 147 | format!("--staging-dir={}", staging_dir.display()), |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 148 | "--no-refresh".to_string(), |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 149 | ]; |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 150 | |
| 151 | if !context.system_server_compiler_filter.is_empty() { |
| 152 | args.push(format!( |
| 153 | "--system-server-compiler-filter={}", |
| 154 | context.system_server_compiler_filter |
| 155 | )); |
| 156 | } |
Alan Stokes | 48c1d2b | 2022-01-10 15:54:04 +0000 | [diff] [blame] | 157 | |
Alan Stokes | 2d2e4db | 2022-01-28 16:41:52 +0000 | [diff] [blame] | 158 | let compile_flag = match context.compilation_mode { |
| 159 | CompilationMode::NORMAL_COMPILE => "--compile", |
| 160 | CompilationMode::TEST_COMPILE => "--force-compile", |
| 161 | other => bail!("Unknown compilation mode {:?}", other), |
| 162 | }; |
| 163 | args.push(compile_flag.to_string()); |
Victor Hsieh | 9bfbc5f | 2021-12-16 11:45:10 -0800 | [diff] [blame] | 164 | |
Alan Stokes | 9646db9 | 2021-12-14 13:22:33 +0000 | [diff] [blame] | 165 | debug!("Running odrefresh with args: {:?}", &args); |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 166 | let jail = spawn_jailed_task(odrefresh_path, &args, &odrefresh_vars.into_env()) |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 167 | .context("Spawn odrefresh")?; |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 168 | let exit_code = match jail.wait() { |
Alan Stokes | 2d2e4db | 2022-01-28 16:41:52 +0000 | [diff] [blame] | 169 | Ok(_) => 0, |
| 170 | Err(minijail::Error::ReturnCode(exit_code)) => exit_code, |
| 171 | Err(e) => bail!("Unexpected minijail error: {}", e), |
| 172 | }; |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 173 | |
Alan Stokes | 126fd51 | 2021-12-16 15:00:01 +0000 | [diff] [blame] | 174 | let exit_code = ExitCode::from_i32(exit_code.into())?; |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 175 | info!("odrefresh exited with {:?}", exit_code); |
| 176 | |
| 177 | if exit_code == ExitCode::CompilationSuccess { |
| 178 | // authfs only shows us the files we created, so it's ok to just sign everything under |
| 179 | // the target directory. |
| 180 | let target_dir = art_apex_data.join(context.target_dir_name); |
| 181 | let mut artifact_signer = ArtifactSigner::new(&target_dir); |
| 182 | add_artifacts(&target_dir, &mut artifact_signer)?; |
| 183 | |
| 184 | artifact_signer.write_info_and_signature(signer, &target_dir.join("compos.info"))?; |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 185 | } |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 186 | |
| 187 | Ok(exit_code) |
| 188 | } |
| 189 | |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 190 | fn path_to_str(path: &Path) -> Result<&str> { |
| 191 | path.to_str().ok_or_else(|| anyhow!("Bad path {:?}", path)) |
| 192 | } |
| 193 | |
| 194 | fn set_classpaths(odrefresh_vars: &mut EnvMap, android_root: &Path) -> Result<()> { |
Alan Stokes | 9247251 | 2022-01-04 11:48:38 +0000 | [diff] [blame] | 195 | let export_lines = run_derive_classpath(android_root)?; |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 196 | load_classpath_vars(odrefresh_vars, &export_lines) |
Alan Stokes | 9247251 | 2022-01-04 11:48:38 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | fn run_derive_classpath(android_root: &Path) -> Result<String> { |
| 200 | let classpaths_root = android_root.join("etc/classpaths"); |
| 201 | |
| 202 | let mut bootclasspath_arg = OsString::new(); |
| 203 | bootclasspath_arg.push("--bootclasspath-fragment="); |
| 204 | bootclasspath_arg.push(classpaths_root.join("bootclasspath.pb")); |
| 205 | |
| 206 | let mut systemserverclasspath_arg = OsString::new(); |
| 207 | systemserverclasspath_arg.push("--systemserverclasspath-fragment="); |
| 208 | systemserverclasspath_arg.push(classpaths_root.join("systemserverclasspath.pb")); |
| 209 | |
| 210 | let result = Command::new("/apex/com.android.sdkext/bin/derive_classpath") |
| 211 | .arg(bootclasspath_arg) |
| 212 | .arg(systemserverclasspath_arg) |
| 213 | .arg("/proc/self/fd/1") |
| 214 | .output() |
| 215 | .context("Failed to run derive_classpath")?; |
| 216 | |
| 217 | if !result.status.success() { |
| 218 | bail!("derive_classpath returned {}", result.status); |
| 219 | } |
| 220 | |
| 221 | String::from_utf8(result.stdout).context("Converting derive_classpath output") |
| 222 | } |
| 223 | |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 224 | fn load_classpath_vars(odrefresh_vars: &mut EnvMap, export_lines: &str) -> Result<()> { |
Alan Stokes | 9247251 | 2022-01-04 11:48:38 +0000 | [diff] [blame] | 225 | // Each line should be in the format "export <var name> <value>" |
| 226 | let pattern = Regex::new(r"^export ([^ ]+) ([^ ]+)$").context("Failed to construct Regex")?; |
| 227 | for line in export_lines.lines() { |
| 228 | if let Some(captures) = pattern.captures(line) { |
| 229 | let name = &captures[1]; |
| 230 | let value = &captures[2]; |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 231 | odrefresh_vars.set(name, value); |
Alan Stokes | 9247251 | 2022-01-04 11:48:38 +0000 | [diff] [blame] | 232 | } else { |
| 233 | warn!("Malformed line from derive_classpath: {}", line); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | Ok(()) |
| 238 | } |
| 239 | |
Alan Stokes | 46a1dff | 2021-12-14 10:56:05 +0000 | [diff] [blame] | 240 | fn add_artifacts(target_dir: &Path, artifact_signer: &mut ArtifactSigner) -> Result<()> { |
| 241 | for entry in |
| 242 | read_dir(&target_dir).with_context(|| format!("Traversing {}", target_dir.display()))? |
| 243 | { |
| 244 | let entry = entry?; |
| 245 | let file_type = entry.file_type()?; |
| 246 | if file_type.is_dir() { |
| 247 | add_artifacts(&entry.path(), artifact_signer)?; |
| 248 | } else if file_type.is_file() { |
| 249 | artifact_signer.add_artifact(&entry.path())?; |
| 250 | } else { |
| 251 | // authfs shouldn't create anything else, but just in case |
| 252 | bail!("Unexpected file type in artifacts: {:?}", entry); |
| 253 | } |
| 254 | } |
| 255 | Ok(()) |
Victor Hsieh | f996869 | 2021-11-18 11:34:39 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 258 | fn spawn_jailed_task(executable: &Path, args: &[String], env_vars: &[String]) -> Result<Minijail> { |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 259 | // TODO(b/185175567): Run in a more restricted sandbox. |
| 260 | let jail = Minijail::new()?; |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 261 | let keep_fds = []; |
| 262 | let command = minijail::Command::new_for_path(executable, &keep_fds, args, Some(env_vars))?; |
| 263 | let _pid = jail.run_command(command)?; |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 264 | Ok(jail) |
| 265 | } |
Alan Stokes | fadcef2 | 2022-01-24 17:00:59 +0000 | [diff] [blame] | 266 | |
| 267 | struct EnvMap(HashMap<String, String>); |
| 268 | |
| 269 | impl EnvMap { |
| 270 | fn from_current_env() -> Self { |
| 271 | Self(env::vars().collect()) |
| 272 | } |
| 273 | |
| 274 | fn set(&mut self, key: &str, value: &str) { |
| 275 | self.0.insert(key.to_owned(), value.to_owned()); |
| 276 | } |
| 277 | |
| 278 | fn into_env(self) -> Vec<String> { |
| 279 | // execve() expects an array of "k=v" strings, rather than a list of (k, v) pairs. |
| 280 | self.0.into_iter().map(|(k, v)| k + "=" + &v).collect() |
| 281 | } |
| 282 | } |