Skip to content

Commit

Permalink
fix JVM core becase SIGQUIT
Browse files Browse the repository at this point in the history
  • Loading branch information
yoloyyh committed Jun 6, 2024
1 parent ac9036b commit 4926bf0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
1 change: 0 additions & 1 deletion rasp/librasp/src/jvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use log::*;
use regex::Regex;
use std::process::Command;
use std::fs;
use std::thread;
use std::time::Duration;
use crate::async_command::run_async_process;
use crate::process::ProcessInfo;
Expand Down
3 changes: 1 addition & 2 deletions rasp/librasp/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use std::collections::HashMap;
use std::ffi::OsStr;
use std::fs;
use std::path::Path;
use std::process::Command;

use anyhow::{anyhow, Result, Result as AnyhowResult};
use crossbeam::channel::Sender;
use fs_extra::dir::{copy, create_all, CopyOptions};
use fs_extra::file::{copy as file_copy, remove as file_remove, CopyOptions as FileCopyOptions};
use fs_extra::file::{copy as file_copy, CopyOptions as FileCopyOptions};
use libraspserver::proto::{PidMissingProbeConfig, ProbeConfigData};
use log::*;

Expand Down
15 changes: 15 additions & 0 deletions rasp/librasp/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ impl ProcessInfo {
}
}

pub fn count_uptime(start_time: f32) -> AnyhowResult<u64> {
let ticks = procfs::ticks_per_second()? as f32;
let boottime = procfs::boot_time_secs()?;
let seconds_since_boot = ((start_time / ticks) as i64) as u64;
let timestamp = Clock::now_since_epoch().as_secs();
let uptime = timestamp - seconds_since_boot - boottime;
if uptime <= 0 {
error!(
"uptime <=0: uptime: {} timestamp: {} seconds since boot: {} boot time: {}",
uptime, timestamp, seconds_since_boot, boottime
);
}
return Ok(uptime);
}

fn traverse_proc(pid: i32) -> AnyhowResult<Vec<i32>> {
let mut pids = Vec::new();
for entry in read_dir(format!("/proc/{}/root/proc", pid))? {
Expand Down
11 changes: 10 additions & 1 deletion rasp/librasp/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::ffi::OsString;
use std::fmt::{self, Display, Formatter};
use std::path::PathBuf;
use std::time::Duration;

use anyhow::{anyhow, Result};
use log::*;
Expand All @@ -12,7 +13,7 @@ use crate::golang::golang_bin_inspect;
use crate::jvm::vm_version;
use crate::nodejs::nodejs_version;
use crate::php::{inspect_phpfpm, inspect_phpfpm_version, inspect_phpfpm_zts};
use crate::process::ProcessInfo;
use crate::process::{ProcessInfo, count_uptime};
use serde::{Deserialize, Serialize};

const DEFAULT_JVM_FILTER_JSON_STR: &str = r#"{"exe": ["java"]}"#;
Expand Down Expand Up @@ -72,6 +73,14 @@ pub trait RuntimeInspect {
};

if jvm_process_filter_check_reuslt {
// https://bugs.openjdk.org/browse/JDK-8292695
let uptime = count_uptime(process_info.start_time.unwrap()).unwrap_or(0);
if uptime > 0 && uptime < 5 {
let interval = 5 - uptime;
info!("JVM process {} just start, so sleep {} sec", process_info.pid, interval);
std::thread::sleep(Duration::from_secs(interval));
}

let version = match vm_version(process_info.pid) {
Ok(ver) => {
if ver < 8 {
Expand Down

0 comments on commit 4926bf0

Please sign in to comment.