-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crashtracker receiver is spawned on crash (#692)
Fixes a few things going on with crashtracker * Long-lived child processes are problematic for wait * Can create zombies * Doesn't correctly handle certain signals * General cleanup --------- Co-authored-by: Kevin Gosse <[email protected]> Co-authored-by: Daniel Schwartz-Narbonne <[email protected]> Co-authored-by: bwoebi <[email protected]>
- Loading branch information
1 parent
d92f667
commit 4f324e7
Showing
32 changed files
with
1,722 additions
and
497 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#![cfg(unix)] | ||
use anyhow::{Context, Result}; | ||
use datadog_crashtracker::CrashtrackerConfiguration; | ||
use std::fs::OpenOptions; | ||
use std::io::Write; | ||
use std::path::Path; | ||
use std::sync::atomic::{AtomicPtr, Ordering}; | ||
|
||
use crate::modes::unix::*; | ||
|
||
/// Defines the additional behavior for a given crashtracking test | ||
pub trait Behavior { | ||
fn setup(&self, output_dir: &Path, config: &mut CrashtrackerConfiguration) -> Result<()>; | ||
fn pre(&self, output_dir: &Path) -> Result<()>; | ||
fn post(&self, output_dir: &Path) -> Result<()>; | ||
} | ||
|
||
pub fn fileat_content_equals(dir: &Path, filename: &str, contents: &str) -> anyhow::Result<bool> { | ||
let filepath = dir.join(filename); | ||
file_content_equals(&filepath, contents) | ||
} | ||
|
||
pub fn file_content_equals(filepath: &Path, contents: &str) -> anyhow::Result<bool> { | ||
let file_contents = std::fs::read_to_string(filepath) | ||
.with_context(|| format!("Failed to read file: {}", filepath.display()))?; | ||
Ok(file_contents.trim() == contents) | ||
} | ||
|
||
pub fn file_append_msg(filepath: &Path, contents: &str) -> Result<()> { | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(filepath) | ||
.with_context(|| format!("Failed to open file: {}", filepath.display()))?; | ||
|
||
file.write_all(contents.as_bytes()) | ||
.with_context(|| format!("Failed to write to file: {}", filepath.display()))?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn atom_to_clone<T: Clone>(atom: &AtomicPtr<T>) -> Result<T> { | ||
let ptr = atom.load(Ordering::SeqCst); | ||
anyhow::ensure!(!ptr.is_null(), "Pointer was null"); | ||
|
||
// If not null, clone the referenced value | ||
unsafe { | ||
ptr.as_ref() | ||
.cloned() | ||
.ok_or_else(|| anyhow::anyhow!("Failed to clone")) | ||
} | ||
} | ||
|
||
pub fn set_atomic<T>(atom: &AtomicPtr<T>, value: T) { | ||
let box_ptr = Box::into_raw(Box::new(value)); | ||
let old = atom.swap(box_ptr, Ordering::SeqCst); | ||
if !old.is_null() { | ||
unsafe { | ||
// Drop the previous value safely | ||
let _ = Box::from_raw(old); | ||
} | ||
} | ||
} | ||
|
||
pub fn removeat_permissive(dir: &Path, filename: &str) { | ||
let filepath = dir.join(filename); | ||
remove_permissive(&filepath); | ||
} | ||
|
||
pub fn remove_permissive(filepath: &Path) { | ||
// Removes the file if it exists. If it doesn't exist, it's not an error or anything. | ||
let _ = std::fs::remove_file(filepath); | ||
} | ||
|
||
pub fn get_behavior(mode_str: &str) -> Box<dyn Behavior> { | ||
match mode_str { | ||
"donothing" => Box::new(test_000_donothing::Test), | ||
"sigpipe" => Box::new(test_001_sigpipe::Test), | ||
"sigchld" => Box::new(test_002_sigchld::Test), | ||
"sigchld_exec" => Box::new(test_003_sigchld_with_exec::Test), | ||
"donothing_sigstack" => Box::new(test_004_donothing_sigstack::Test), | ||
"sigpipe_sigstack" => Box::new(test_005_sigpipe_sigstack::Test), | ||
"sigchld_sigstack" => Box::new(test_006_sigchld_sigstack::Test), | ||
"chained" => Box::new(test_007_chaining::Test), | ||
"fork" => Box::new(test_008_fork::Test), | ||
_ => panic!("Unknown mode: {}", mode_str), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pub mod behavior; | ||
#[cfg(unix)] | ||
pub mod unix; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pub mod test_000_donothing; | ||
pub mod test_001_sigpipe; | ||
pub mod test_002_sigchld; | ||
pub mod test_003_sigchld_with_exec; | ||
pub mod test_004_donothing_sigstack; | ||
pub mod test_005_sigpipe_sigstack; | ||
pub mod test_006_sigchld_sigstack; | ||
pub mod test_007_chaining; | ||
pub mod test_008_fork; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// This is a baseline test for the crashtracker. It doesn't really do anything except run the | ||
// crashtracker in a fairly normal configuration, generates a crash, and then ensures that the | ||
// crashtracker has recorded the situation as expected. | ||
use crate::modes::behavior::Behavior; | ||
use datadog_crashtracker::CrashtrackerConfiguration; | ||
use std::path::Path; | ||
|
||
pub struct Test; | ||
|
||
impl Behavior for Test { | ||
fn setup( | ||
&self, | ||
_output_dir: &Path, | ||
_config: &mut CrashtrackerConfiguration, | ||
) -> anyhow::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn pre(&self, _output_dir: &Path) -> anyhow::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn post(&self, _output_dir: &Path) -> anyhow::Result<()> { | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.