Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
add logging to generic analysis task (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc-msft authored Feb 8, 2021
1 parent 5114332 commit c9455fd
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/agent/onefuzz-agent/src/tasks/analysis/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// Licensed under the MIT License.

use crate::tasks::{config::CommonConfig, heartbeat::HeartbeatSender};
use anyhow::Result;
use anyhow::{Context, Result};
use futures::stream::StreamExt;
use onefuzz::{az_copy, blob::url::BlobUrl};
use onefuzz::{
expand::Expand, fs::set_executable, fs::OwnedDir, jitter::delay_with_jitter, syncdir::SyncedDir,
expand::Expand, fs::set_executable, fs::OwnedDir, jitter::delay_with_jitter,
process::monitor_process, syncdir::SyncedDir,
};
use reqwest::Url;
use serde::Deserialize;
use std::process::Stdio;
use std::{
collections::HashMap,
path::{Path, PathBuf},
Expand Down Expand Up @@ -53,12 +55,15 @@ pub async fn spawn(config: Config) -> Result<()> {
async fn run_existing(config: &Config) -> Result<()> {
if let Some(crashes) = &config.crashes {
crashes.init_pull().await?;
let mut count = 0;
let mut read_dir = fs::read_dir(&crashes.path).await?;
while let Some(file) = read_dir.next().await {
verbose!("Processing file {:?}", file);
let file = file?;
run_tool(file.path(), &config).await?;
count += 1;
}
info!("processed {} initial inputs", count);
config.analysis.sync_push().await?;
}
Ok(())
Expand Down Expand Up @@ -128,8 +133,12 @@ pub async fn run_tool(input: impl AsRef<Path>, config: &Config) -> Result<()> {

let analyzer_path = expand.evaluate_value(&config.analyzer_exe)?;

let mut cmd = Command::new(analyzer_path);
cmd.kill_on_drop(true).env_remove("RUST_LOG");
let mut cmd = Command::new(&analyzer_path);
cmd.kill_on_drop(true)
.env_remove("RUST_LOG")
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());

for arg in expand.evaluate(&config.analyzer_options)? {
cmd.arg(arg);
Expand All @@ -139,6 +148,13 @@ pub async fn run_tool(input: impl AsRef<Path>, config: &Config) -> Result<()> {
cmd.env(k, expand.evaluate_value(v)?);
}

cmd.output().await?;
info!("analyzing input with {:?}", cmd);
let output = cmd
.spawn()
.with_context(|| format!("analyzer failed to start: {}", analyzer_path))?;

monitor_process(output, "analyzer".to_string(), true, None)
.await
.with_context(|| format!("analyzer failed to run: {}", analyzer_path))?;
Ok(())
}

0 comments on commit c9455fd

Please sign in to comment.