-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use cmdline instead of comm, in terminal detection #130
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,6 +379,15 @@ impl GeneralReadout for LinuxGeneralReadout { | |
shared::window_manager() | ||
} | ||
|
||
// fn terminal(&self) -> Result<String, ReadoutError> { | ||
// use terminfo::Database; | ||
// | ||
// let db = Database::from_env() | ||
// let term = db.name(); | ||
// | ||
// Ok(term.to_string()) | ||
// } | ||
|
||
Comment on lines
+382
to
+390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please remove this commented function? |
||
fn terminal(&self) -> Result<String, ReadoutError> { | ||
// This function returns the PPID of a given PID: | ||
// - The file used to extract this data: /proc/<pid>/status | ||
|
@@ -404,35 +413,50 @@ impl GeneralReadout for LinuxGeneralReadout { | |
} | ||
} | ||
|
||
fn terminal_exec(pid: i32) -> String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let data_path = PathBuf::from("/proc").join(pid.to_string()).join("cmdline"); | ||
let empty = "".to_string(); | ||
let raw_path = match fs::read_to_string(data_path) { | ||
Ok(v) => v, | ||
Err(_) => return empty, | ||
}; | ||
let exec_name = match PathBuf::from(raw_path).file_name() { | ||
Some(v) => match v.to_str() { | ||
Some(v) => v.to_string(), | ||
None => return empty, | ||
}, | ||
None => return empty, | ||
}; | ||
exec_name | ||
} | ||
|
||
// This function returns the name associated with a given PPID | ||
fn terminal_name() -> String { | ||
let mut terminal_pid = get_parent(unsafe { libc::getppid() }); | ||
|
||
let path = PathBuf::from("/proc") | ||
.join(terminal_pid.to_string()) | ||
.join("comm"); | ||
|
||
let mut terminal_name = terminal_exec(terminal_pid); | ||
if terminal_name.is_empty() { | ||
return "".to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use |
||
}; | ||
// The below loop will traverse /proc to find the | ||
// terminal inside of which the user is operating | ||
if let Ok(mut terminal_name) = fs::read_to_string(path) { | ||
while extra::common_shells().contains(&terminal_name.replace('\n', "").as_str()) { | ||
// Any command_name we find that matches | ||
// one of the elements within this table | ||
// is effectively ignored | ||
while extra::common_shells().contains(&terminal_name.replace('\n', "").as_str()) { | ||
let ppid = get_parent(terminal_pid); | ||
terminal_pid = ppid; | ||
let ppid = get_parent(terminal_pid); | ||
terminal_pid = ppid; | ||
|
||
let path = PathBuf::from("/proc").join(ppid.to_string()).join("comm"); | ||
let exec_name = terminal_exec(terminal_pid); | ||
|
||
if let Ok(comm) = fs::read_to_string(path) { | ||
terminal_name = comm; | ||
} | ||
if !exec_name.is_empty() { | ||
terminal_name = exec_name; | ||
} else { | ||
return "".to_string(); | ||
} | ||
|
||
return terminal_name; | ||
} | ||
|
||
String::new() | ||
terminal_name | ||
} | ||
|
||
let terminal = terminal_name(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you forgot to remove this dependency.