diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
commit | a0aa2307322cd47bbf416810ac0292925e03be87 (patch) | |
tree | 37076262a026c4b48c8a0e84f44ff9187556ca35 /rust/vendor/num_threads/src/linux.rs | |
parent | Initial commit. (diff) | |
download | suricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip |
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/vendor/num_threads/src/linux.rs')
-rw-r--r-- | rust/vendor/num_threads/src/linux.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/rust/vendor/num_threads/src/linux.rs b/rust/vendor/num_threads/src/linux.rs new file mode 100644 index 0000000..641b6b1 --- /dev/null +++ b/rust/vendor/num_threads/src/linux.rs @@ -0,0 +1,14 @@ +use std::fs; +use std::num::NonZeroUsize; + +pub(crate) fn num_threads() -> Option<NonZeroUsize> { + fs::read_to_string("/proc/self/stat") + .ok() + .as_ref() + // Skip past the pid and (process name) fields + .and_then(|stat| stat.rsplit(')').next()) + // 20th field, less the two we skipped + .and_then(|rstat| rstat.split_whitespace().nth(17)) + .and_then(|num_threads| num_threads.parse::<usize>().ok()) + .and_then(NonZeroUsize::new) +} |