Skip to content

Commit

Permalink
fix(process): Don't kill the host process. (#19)
Browse files Browse the repository at this point in the history
* fix(process): Don't kill the host process.

Ref: tauri-apps/tauri#7637

* clippy
  • Loading branch information
FabianLars committed Aug 18, 2023
1 parent 604f4bd commit 92f9264
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changes/skip-host-process.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"nsis_tauri_utils": "patch"
"nsis_process": "patch"
---

Skip processes with the same pid as the current installer's process to prevent the installer from killing itself.
16 changes: 9 additions & 7 deletions crates/nsis-process/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use windows_sys::Win32::{
},
};

/// Test if there is a running process with the given name. The input and process names are case-insensitive.
/// Test if there is a running process with the given name, skipping processes with the host's pid. The input and process names are case-insensitive.
///
/// # Safety
///
Expand All @@ -36,7 +36,7 @@ pub unsafe extern "C" fn FindProcess(
}
}

/// Kill all running process with the given name. The input and process names are case-insensitive.
/// Kill all running process with the given name, skipping processes with the host's pid. The input and process names are case-insensitive.
///
/// # Safety
///
Expand Down Expand Up @@ -71,6 +71,7 @@ fn kill(pid: u32) -> bool {
}

fn get_processes(name: &str) -> Vec<u32> {
let current_pid = std::process::id();
let mut processes = Vec::new();

unsafe {
Expand All @@ -83,11 +84,12 @@ fn get_processes(name: &str) -> Vec<u32> {

if Process32FirstW(handle, &mut process) != 0 {
while Process32NextW(handle, &mut process) != 0 {
if decode_wide(&process.szExeFile)
.to_str()
.unwrap_or_default()
.to_lowercase()
== name.to_lowercase()
if current_pid != process.th32ProcessID
&& decode_wide(&process.szExeFile)
.to_str()
.unwrap_or_default()
.to_lowercase()
== name.to_lowercase()
{
processes.push(process.th32ProcessID);
}
Expand Down

0 comments on commit 92f9264

Please sign in to comment.