Skip to content

Commit bde5b61

Browse files
authored
fix: remove stderr redirect that suppressed Python logs (#23)
Replace fd 2 redirect to /dev/null with JACK_NO_START_SERVER env var. The stderr redirect was silencing Python's logging and error output. Remove libc dependency (no longer needed).
1 parent 82037f1 commit bde5b61

2 files changed

Lines changed: 4 additions & 29 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ ringbuf = "0.4"
1515
hound = "3.5"
1616
log = "0.4"
1717
env_logger = "0.11"
18-
libc = "0.2"
1918

2019
[build-dependencies]
2120
cc = "1"

src/lib.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ pub(crate) fn init_logging() {
2929
});
3030
}
3131

32-
/// Suppress noisy ALSA/JACK error messages.
33-
/// ALSA: set a no-op error handler (persistent).
34-
/// JACK: redirect stderr to /dev/null during cpal operations.
35-
/// The stderr redirect is done once and stays in effect — JACK re-probes on every
36-
/// cpal call, so we keep fd 2 pointed at /dev/null and route our own output through
37-
/// the saved original stderr fd.
32+
/// Suppress noisy ALSA/JACK error messages without affecting Python's stderr.
33+
/// ALSA: set a no-op error handler (persistent, does not touch stderr).
34+
/// JACK: set JACK_NO_START_SERVER=1 to prevent JACK from trying to start a server.
3835
#[cfg(target_os = "linux")]
3936
fn suppress_backend_noise() {
4037
extern "C" {
@@ -47,36 +44,15 @@ fn suppress_backend_noise() {
4744
snd_lib_error_set_handler(pyspeaker_silent_alsa_handler as *const std::ffi::c_void);
4845
}
4946

50-
// Prevent JACK from trying to start a server
47+
// Prevent JACK from trying to start a server (suppresses connection messages)
5148
if std::env::var("JACK_NO_START_SERVER").is_err() {
5249
std::env::set_var("JACK_NO_START_SERVER", "1");
5350
}
54-
55-
// Redirect fd 2 (stderr) to /dev/null to suppress JACK connection messages.
56-
// Save the original stderr so Python/log can still write to it.
57-
unsafe {
58-
let devnull = libc::open(c"/dev/null".as_ptr(), libc::O_WRONLY);
59-
if devnull >= 0 {
60-
// Save original stderr to a new fd
61-
let saved = libc::dup(2);
62-
// Point fd 2 at /dev/null (suppresses JACK noise)
63-
libc::dup2(devnull, 2);
64-
libc::close(devnull);
65-
// Point fd 1 (stdout) stays as-is, Python print works
66-
// Redirect env_logger to original stderr via saved fd
67-
if saved >= 0 {
68-
SAVED_STDERR_FD.store(saved, std::sync::atomic::Ordering::SeqCst);
69-
}
70-
}
71-
}
7251
}
7352

7453
#[cfg(not(target_os = "linux"))]
7554
fn suppress_backend_noise() {}
7655

77-
#[cfg(target_os = "linux")]
78-
static SAVED_STDERR_FD: std::sync::atomic::AtomicI32 = std::sync::atomic::AtomicI32::new(-1);
79-
8056
/// List all available audio output devices.
8157
#[pyfunction]
8258
fn list_output_devices(py: Python<'_>) -> PyResult<Vec<Py<pyo3::types::PyDict>>> {

0 commit comments

Comments
 (0)