Skip to content

Commit

Permalink
Fix log file and disable LSAN usage in sidecar (#602)
Browse files Browse the repository at this point in the history
* Use hard libc::_exit to prevent side effects

Like leak sanitizer running here; we definitely do not have cleaned up anything at this point.

* Hard-disable LSAN in sidecar process

Signed-off-by: Bob Weinand <[email protected]>

* Explicitly disable log_method when it could not be opened

Signed-off-by: Bob Weinand <[email protected]>

---------

Signed-off-by: Bob Weinand <[email protected]>
  • Loading branch information
bwoebi authored Aug 29, 2024
1 parent d910738 commit 3b99aa7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions sidecar/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,12 @@ where
.map_err(|e| e.into())
}

pub fn daemonize(listener: IpcServer, cfg: Config) -> anyhow::Result<()> {
pub fn daemonize(listener: IpcServer, mut cfg: Config) -> anyhow::Result<()> {
#[allow(unused_unsafe)] // the unix method is unsafe
let mut spawn_cfg = unsafe { spawn_worker::SpawnWorker::new() };

spawn_cfg.target(entrypoint!(ddog_daemon_entry_point));

for (env, val) in cfg.to_env().into_iter() {
spawn_cfg.append_env(env, val);
}

match cfg.log_method {
config::LogMethod::File(ref path) => {
match File::options()
Expand All @@ -164,6 +160,7 @@ pub fn daemonize(listener: IpcServer, cfg: Config) -> anyhow::Result<()> {
}
Err(e) => {
tracing::warn!("Failed to open logfile for sidecar: {:?}", e);
cfg.log_method = config::LogMethod::Disabled;
spawn_cfg.stdout(Stdio::Null);
spawn_cfg.stderr(Stdio::Null);
}
Expand All @@ -176,6 +173,11 @@ pub fn daemonize(listener: IpcServer, cfg: Config) -> anyhow::Result<()> {
_ => {}
}

for (env, val) in cfg.to_env().into_iter() {
spawn_cfg.append_env(env, val);
}
spawn_cfg.append_env("LSAN_OPTIONS", "detect_leaks=0");

setup_daemon_process(listener, &mut spawn_cfg)?;

let mut lib_deps = cfg.library_dependencies;
Expand Down
2 changes: 1 addition & 1 deletion spawn_worker/src/unix/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@ impl SpawnWorker {
}
unsafe {
libc::close(skip_close_fd);
libc::_exit(0);
}
std::process::exit(0);
}
}

Expand Down

0 comments on commit 3b99aa7

Please sign in to comment.