• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pkgxdev / pkgx / 12768583963

14 Jan 2025 01:23PM UTC coverage: 1.643% (-90.3%) from 91.907%
12768583963

Pull #1068

github

web-flow
Merge aab1de74e into 6a195bfb8
Pull Request #1068: v2

13 of 791 new or added lines in 17 files covered. (1.64%)

13 of 791 relevant lines covered (1.64%)

0.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/crates/cli/src/execve.rs
1
use nix::unistd::execve as nix_execve;
2
use std::ffi::CString;
3
use std::{collections::HashMap, error::Error};
4

NEW
5
pub fn execve(
×
6
    cmd: String,
7
    mut args: Vec<String>,
8
    env: HashMap<String, String>,
9
) -> Result<(), Box<dyn Error>> {
10
    // Convert the command to a CString
NEW
11
    let c_command = CString::new(cmd.clone())
×
NEW
12
        .map_err(|e| format!("Failed to convert command to CString: {}", e))?;
×
13

14
    // execve expects the command to be the first argument (yes, as well)
15
    args.insert(0, cmd);
16

17
    // Convert the arguments to CStrings and collect them into a Vec
NEW
18
    let c_args: Vec<CString> = args
×
19
        .iter()
NEW
20
        .map(|arg| {
×
NEW
21
            CString::new(arg.clone())
×
NEW
22
                .map_err(|e| format!("Failed to convert argument to CString: {}", e))
×
23
        })
24
        .collect::<Result<_, _>>()?;
25

26
    // Convert the environment to a Vec of `KEY=VALUE` strings
27
    let env_vars: Vec<String> = env
28
        .iter()
NEW
29
        .map(|(key, value)| format!("{}={}", key, value))
×
30
        .collect();
31

32
    // Convert the environment variables to CStrings and collect them into a Vec
NEW
33
    let c_env: Vec<CString> = env_vars
×
34
        .iter()
NEW
35
        .map(|env| {
×
NEW
36
            CString::new(env.clone())
×
NEW
37
                .map_err(|e| format!("Failed to convert environment variable to CString: {}", e))
×
38
        })
39
        .collect::<Result<_, _>>()?;
40

41
    // Replace the process with the new command, arguments, and environment
42
    let execve_result = nix_execve(&c_command, &c_args, &c_env);
43
    if execve_result.is_err() {
NEW
44
        let errno = execve_result.unwrap_err();
×
NEW
45
        return Err(format!("execve failed with errno: {}", errno).into());
×
46
    }
47

NEW
48
    Ok(())
×
49
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc