From 0befd73596ad3c9f8bd5de77bdc3eaa67b0b47a6 Mon Sep 17 00:00:00 2001
From: Stephen D <webmaster@scd31.com>
Date: Sun, 9 Jul 2023 16:59:11 -0300
Subject: [PATCH] fix zombie ssdv processes

---
 src/ssdv.rs | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/ssdv.rs b/src/ssdv.rs
index 63784d3..f8e7590 100644
--- a/src/ssdv.rs
+++ b/src/ssdv.rs
@@ -1,12 +1,14 @@
 use anyhow::{bail, Context};
+use subprocess::{Popen, PopenConfig, Redirection};
 
 use crate::packet::RawPacket;
 
 // TODO eventually rewrite Ssdv in Rust?
 // Don't want to use FFI because then segfaults can hurt us
 pub fn ssdv_encode(callsign: &str, img: &[u8], img_idx: u8) -> anyhow::Result<Vec<RawPacket>> {
-    let (stdout, stderr) = subprocess::Exec::cmd("ssdv")
-        .args(&[
+    let mut p = Popen::create(
+        &[
+            "ssdv",
             "-e",
             "-c",
             callsign,
@@ -15,10 +17,16 @@ pub fn ssdv_encode(callsign: &str, img: &[u8], img_idx: u8) -> anyhow::Result<Ve
             "6",
             "-i",
             &format!("{}", img_idx),
-        ])
-        .stdin(img.to_vec())
-        .communicate()?
-        .read()?;
+        ],
+        PopenConfig {
+            stdin: Redirection::Pipe,
+            stdout: Redirection::Pipe,
+            stderr: Redirection::Pipe,
+            ..Default::default()
+        },
+    )?;
+
+    let (stdout, stderr) = p.communicate_bytes(Some(img))?;
 
     if let Some(stderr) = stderr {
         if !stderr.is_empty() {
-- 
GitLab