forked from oxidecomputer/omicron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(WIP) Put process core dumps onto the U.2 debug zvol
(Part of oxidecomputer#2478)
- Loading branch information
lif
committed
Jul 19, 2023
1 parent
1604e18
commit 17b76f7
Showing
7 changed files
with
360 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use camino::Utf8PathBuf; | ||
use std::ffi::OsString; | ||
use std::os::unix::ffi::OsStringExt; | ||
use std::process::Command; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum CoreAdmError { | ||
#[error("Error obtaining or modifying coreadm configuration. core_dir: {core_dir:?}")] | ||
Execution { core_dir: Utf8PathBuf }, | ||
|
||
#[error("Invalid invocation of coreadm: {0:?} {1:?}")] | ||
InvalidCommand(Vec<String>, OsString), | ||
|
||
#[error("coreadm process was terminated by a signal.")] | ||
TerminatedBySignal, | ||
|
||
#[error("coreadm invocation exited with unexpected return code {0}")] | ||
UnexpectedExitCode(i32), | ||
|
||
#[error("Failed to execute dumpadm process: {0}")] | ||
Exec(std::io::Error), | ||
} | ||
|
||
const COREADM: &str = "/usr/bin/coreadm"; | ||
|
||
pub fn coreadm(core_dir: &Utf8PathBuf) -> Result<(), CoreAdmError> { | ||
let mut cmd = Command::new(COREADM); | ||
cmd.env_clear(); | ||
|
||
// disable per-process core patterns | ||
cmd.arg("-d").arg("process"); | ||
cmd.arg("-d").arg("process-setid"); | ||
|
||
// use the global core pattern | ||
cmd.arg("-e").arg("global"); | ||
cmd.arg("-e").arg("global-setid"); | ||
|
||
// set the global pattern to place all cores into core_dir, | ||
// with filenames of "core.[zone-name].[exe-filename].[pid].[time]" | ||
cmd.arg("-g").arg(core_dir.join("core.%z.%f.%p.%t")); | ||
|
||
// also collect DWARF data from the exe and its library deps | ||
cmd.arg("-G").arg("default+debug"); | ||
|
||
let out = cmd.output().map_err(CoreAdmError::Exec)?; | ||
|
||
match out.status.code() { | ||
Some(0) => Ok(()), | ||
Some(1) => Err(CoreAdmError::Execution { core_dir: core_dir.clone() }), | ||
Some(2) => { | ||
// unwrap: every arg we've provided in this function is UTF-8 | ||
let mut args = | ||
vec![cmd.get_program().to_str().unwrap().to_string()]; | ||
cmd.get_args() | ||
.for_each(|arg| args.push(arg.to_str().unwrap().to_string())); | ||
let stderr = OsString::from_vec(out.stderr); | ||
Err(CoreAdmError::InvalidCommand(args, stderr)) | ||
} | ||
Some(n) => Err(CoreAdmError::UnexpectedExitCode(n)), | ||
None => Err(CoreAdmError::TerminatedBySignal), | ||
} | ||
} |
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 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
Oops, something went wrong.