<commit_before>use super::Signal;
use crate::error::{Error,
                   Result};
use libc::{self,
           pid_t};
use std::{ffi::OsString,
          io,
          os::unix::process::CommandExt,
          path::PathBuf,
          process::Command};

pub type Pid = libc::pid_t;
pub(crate) type SignalCode = libc::c_int;

pub fn become_command(command: PathBuf, args: &[OsString]) -> Result<()> {
    become_exec_command(command, args)
}

/// Get process identifier of calling process.
pub fn current_pid() -> Pid { unsafe { libc::getpid() as pid_t } }

/// Determines if a process is running with the given process identifier.
pub fn is_alive(pid: Pid) -> bool {
    // Sending a signal to 0 is sending a signal to yourself, so this
    // would just be checking that the current process itself is alive,
    // which... *duh*.
    //
    // (This is in service of discovering how we would ever end up
    // with pid == 0 down here in the first place.  I think places
    // where a PID of 0 would be generated have been addressed in the
    // code, but this is belt-and-suspenders code at the moment.)
    if pid == 0 {
        warn!(target: "pidfile_tracing","Trying to determine if PID 0 is alive; this is an unexpected situation; returning false!");
        return false;
    }

    match unsafe { libc::kill(pid as pid_t, 0) } {
        0 => true,
        _ => {
            match io::Error::last_os_error().raw_os_error() {
                Some(libc::EPERM) => true,
                Some(libc::ESRCH) => false,
                _ => false,
            }
        }
    }
}

pub fn signal(pid: Pid, signal: Signal) -> Result<()> {
    unsafe {
        match libc::kill(pid as pid_t, signal.into()) {
            0 => Ok(()),<commit_msg>[PR Feedback] warn! -> error!, and remove a superfluous cast<commit_after>use super::Signal;
use crate::error::{Error,
                   Result};
use libc::{self,
           pid_t};
use std::{ffi::OsString,
          io,
          os::unix::process::CommandExt,
          path::PathBuf,
          process::Command};

pub type Pid = libc::pid_t;
pub(crate) type SignalCode = libc::c_int;

pub fn become_command(command: PathBuf, args: &[OsString]) -> Result<()> {
    become_exec_command(command, args)
}

/// Get process identifier of calling process.
pub fn current_pid() -> Pid { unsafe { libc::getpid() as pid_t } }

/// Determines if a process is running with the given process identifier.
pub fn is_alive(pid: Pid) -> bool {
    // Sending a signal to 0 is sending a signal to yourself, so this
    // would just be checking that the current process itself is alive,
    // which... *duh*.
    //
    // (This is in service of discovering how we would ever end up
    // with pid == 0 down here in the first place.  I think places
    // where a PID of 0 would be generated have been addressed in the
    // code, but this is belt-and-suspenders code at the moment.)
    if pid == 0 {
        error!(target: "pidfile_tracing","Trying to determine if PID 0 is alive; this is an unexpected situation; returning false!");
        return false;
    }

    match unsafe { libc::kill(pid, 0) } {
        0 => true,
        _ => {
            match io::Error::last_os_error().raw_os_error() {
                Some(libc::EPERM) => true,
                Some(libc::ESRCH) => false,
                _ => false,
            }
        }
    }
}

pub fn signal(pid: Pid, signal: Signal) -> Result<()> {
    unsafe {
        match libc::kill(pid as pid_t, signal.into()) {
            0 => Ok(()),
{'fraction_non_alphanumeric': 0.12687199773947444, 'fraction_numerical': 0.004521051144391071, 'mean_word_length': 2.2930232558139534, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2477388', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1053, 'n_words': 373}