Skip to content

Commit 763816f

Browse files
Move API docs into module code doc comments. Link to docs.rs from README.md (#124)
Fixes #119
1 parent d8e47a8 commit 763816f

File tree

2 files changed

+94
-98
lines changed

2 files changed

+94
-98
lines changed

README.md

Lines changed: 48 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
# libproc-rs
55
This is a library for getting information about running processes for Mac OS X and Linux.
66

7-
# Using it
7+
Add it to your project's `Cargo.toml`:
8+
```toml
9+
libproc = "0.14.4"
810
```
9-
extern crate libproc;
11+
12+
And then use it in your code:
13+
```rust
1014
use libproc::libproc::proc_pid;
1115

1216
match proc_pid::pidpath(pid) {
@@ -15,66 +19,13 @@ match proc_pid::pidpath(pid) {
1519
}
1620
```
1721

18-
# Experiment in OSS funding
19-
I am exploring the ideas around Open Source Software funding from [RadWorks Foundation]([https://radworks.org/) via the [Drips Project](https://www.drips.network/)
20-
21-
This project is in Drips [here](https://www.drips.network/app/projects/github/andrewdavidmackenzie/libproc-rs)
22-
23-
# Documentation
24-
[Online code docs](https://andrewdavidmackenzie.github.io/libproc-rs/libproc/)
25-
26-
# API
27-
At the moment these methods have been implemented:
28-
29-
## Process / PID related
30-
```
31-
pub fn listpids(proc_types: ProcType) -> Result<Vec<u32>, String> (macos) (linux)
32-
```
33-
```
34-
pub fn listpidspath(proc_types: ProcType, path: &str) -> Result<Vec<u32>, String> (macos) (linux)
35-
```
36-
```
37-
pub fn pidinfo<T: PIDInfo>(pid : i32, arg: u64) -> Result<T, String> (macos)
38-
```
39-
```
40-
pub fn regionfilename(pid: i32, address: u64) -> Result<String, String> (macos)
41-
```
42-
```
43-
pub fn pidpath(pid : i32) -> Result<String, String> (macos) (linux)
44-
```
45-
```
46-
pub fn libversion() -> Result<(i32, i32), String> (macos)
47-
```
48-
```
49-
pub fn name(pid: i32) -> Result<String, String> (linux) (macos)
50-
```
51-
```
52-
pub fn listpidinfo<T: ListPIDInfo>(pid : i32, max_len: usize) -> Result<Vec<T::Item>, String> (macos)
53-
```
54-
```
55-
pub fn pidcwd(pid: pid_t) -> Result<PathBuf, String> (linux)
56-
```
57-
```
58-
pub fn cwdself() -> Result<PathBuf, String> (linux)
59-
```
60-
61-
## File and FileDescriptor related
62-
```
63-
pub fn pidfdinfo<T: PIDFDInfo>(pid : i32, fd: i32) -> Result<T, String> (macos)
64-
```
22+
You can find the latest published release on [crates.io](https://crates.io/crates/libproc)
6523

66-
## PID Resource Usage related
67-
(Added in Mac OS X 10.9 - under "macosx_10_9" feature)
68-
```
69-
pub fn pidrusage<T: PIDRUsage>(pid : i32) -> Result<T, String> (macos)
70-
```
24+
You can find the browseable docs for the latest release on [docs.rs](https://docs.rs/libproc/latest/libproc/).
7125

72-
## Kernel Message Buffer - kmsgbuf
73-
```
74-
pub fn kmsgbuf() -> Result<String, String>
75-
```
26+
NOTE: `master` branch (code and docs) can differ from those docs prior to a new release.
7627

77-
# Rust Versions
28+
# Rust Channels Tested
7829
The Github Actions CI matrix tests for rust `stable`, `beta` and `nightly` on all platforms
7930

8031
# Platforms
@@ -108,45 +59,22 @@ Two simple examples are included to show libproc-rs working.
10859

10960
These can be ran thus:
11061
`sudo cargo run --example procinfo` or
111-
`sudo cargo run --example dmesg`
112-
113-
# Build and Test Locally
114-
`cargo test` should build and test as usual for rust projects.
62+
`sudo cargo run --example dmesg`
11563

116-
However, as some functions need to be run as `root` to work, CI tests are run as `root`.
117-
So, when developing in local it's best if you use `sudo cargo test`.
118-
119-
NOTE: This can get you into permissions problems when switching back and for
120-
between using `cargo test` and `sudo cargo test`.
121-
To fix that run `sudo cargo clean` and then build or test as you prefer.
122-
123-
In order to have tests pass when run as `root` or not, some tests need to check if they are `root`
124-
at run-time (using our own `am_root()` function is handy) and avoid failing if *not* run as `root`.
125-
126-
## Using "act" to run GH Actions CI workflows locally
127-
If you develop on macos but want to ensure code builds and tests pass on linux while making changes,
128-
you can use the [act](https://github.com/nektos/act) tool to run the Github Actions Workflows on
129-
the test matrix.
130-
131-
Just install "act" (`brew install act`) (previously install docker if you don't have it already,
132-
and make sure the daemon is running) then run `act` at the command line
64+
# Contributing
65+
You are welcome to fork this repo and make a pull request, or write an issue.
13366

134-
## Macos: clang detection and header file finding
135-
Newer versions of `bindgen` have improved the detection of `clang` and hence macos header files.
136-
If you also have llvm/clang installed directly or via `brew` this may cause the build to fail saying it
137-
cannot find `libproc.h`. This can be fixed by setting `CLANG_PATH="/usr/bin/clang"` so that `bindgen`
138-
detects the Xcode version and hence can fidn the correct header files.
67+
## Experiment in OSS funding
68+
I am exploring the ideas around Open Source Software funding from [RadWorks Foundation]([https://radworks.org/) via the [Drips Project](https://www.drips.network/)
13969

140-
# CI Testing
141-
Continuous Integration testing has been moved from travis-ci to GitHub Actions. For details see the
142-
[rust.yml](`.github/workflows/rust.yml`) GitHub Actions workflow
70+
This project is in Drips [here](https://www.drips.network/app/projects/github/andrewdavidmackenzie/libproc-rs)
14371

144-
# Input Requested
72+
## Input Requested
14573
* Suggestions for API, module re-org and cross-platform abstractions are welcome.
14674
* How to do error reporting? Define own new Errors, or keep simple with Strings?
14775
* Would like Path/PathBuf returned when it makes sense instead of String?
14876

149-
# TODO
77+
## TODO
15078
See the [list of issues](https://github.com/andrewdavidmackenzie/libproc-rs/issues).
15179
I put the "help wanted" label where I need help from others.
15280

@@ -155,8 +83,36 @@ I put the "help wanted" label where I need help from others.
15583
- Add more documentation (including samples with documentation test)
15684
- Add own custom error type and implement From::from to ease reporting of multiple error types in clients
15785

86+
## Build and Test Locally
87+
If you're feeling lucky today, start with
88+
`make`
89+
90+
`cargo test` will build and test as usual.
91+
92+
However, as some functions need to be run as `root` to work, CI tests are run as `root`.
93+
So, when developing in local it's best if you use `sudo cargo test`.
94+
95+
[!NOTE] This can get you into permissions problems when switching back and for
96+
between using `cargo test` and `sudo cargo test`.
97+
To fix that run `sudo cargo clean` and then build or test as you prefer.
98+
99+
In order to have tests pass when run as `root` or not, some tests need to check if they are `root`
100+
at run-time (using our own `am_root()` function is handy) and avoid failing if *not* run as `root`.
101+
102+
### Using "act" to run GH Actions CI workflows locally
103+
If you develop on macos but want to ensure code builds and tests pass on linux while making changes,
104+
you can use the [act](https://github.com/nektos/act) tool to run the Github Actions Workflows on
105+
the test matrix.
106+
107+
Just install "act" (`brew install act`) (previously install docker if you don't have it already,
108+
and make sure the daemon is running) then run `act` at the command line
109+
110+
### Macos: clang detection and header file finding
111+
Newer versions of `bindgen` have improved the detection of `clang` and hence macos header files.
112+
If you also have llvm/clang installed directly or via `brew` this may cause the build to fail saying it
113+
cannot find `libproc.h`. This can be fixed by setting `CLANG_PATH="/usr/bin/clang"` so that `bindgen`
114+
detects the Xcode version and hence can fidn the correct header files.
115+
158116
# LICENSE
159117
This code is licensed under MIT license (see LICENCE).
160118

161-
# CONTRIBUTING
162-
You are welcome to fork this repo and make a pull request, or write an issue.

src/lib.rs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,58 @@
33

44
//! `libproc` is a library for getting information about running processes on Mac and Linux.
55
//!
6-
//! Not all methods are available on both Operating Systems yet, but more will
7-
//! be made cross-platform over time.
8-
//!
9-
extern crate libc;
6+
//! Not all methods are available on both Operating Systems yet, but more will be made
7+
//! cross-platform over time.
8+
109
extern crate errno;
10+
extern crate libc;
1111

12+
/// Get information (such as name, path, process info, fd) about running processes by pid, process type, etc.
13+
/// At the moment these methods have been implemented, most of which have examples in their docs:
14+
///
15+
/// # `libproc::libproc` (names that way for bad, historical reasons!)
16+
/// ## Process / PID related
17+
/// `pub fn listpids(proc_types: ProcType) -> Result<Vec<u32>, String> (macos) (linux)`
18+
///
19+
/// `pub fn listpidspath(proc_types: ProcType, path: &str) -> Result<Vec<u32>, String> (macos) (linux)`
20+
///
21+
/// `pub fn pidinfo<T: PIDInfo>(pid : i32, arg: u64) -> Result<T, String> (macos)`
22+
///
23+
/// `pub fn regionfilename(pid: i32, address: u64) -> Result<String, String> (macos)`
24+
///
25+
/// `pub fn pidpath(pid : i32) -> Result<String, String> (macos) (linux)`
26+
///
27+
/// `pub fn libversion() -> Result<(i32, i32), String> (macos)`
28+
///
29+
/// `pub fn name(pid: i32) -> Result<String, String> (linux) (macos)`
30+
///
31+
/// `pub fn listpidinfo<T: ListPIDInfo>(pid : i32, max_len: usize) -> Result<Vec<T::Item>, String> (macos)`
32+
///
33+
/// `pub fn pidcwd(pid: pid_t) -> Result<PathBuf, String> (linux)`
34+
///
35+
/// `pub fn cwdself() -> Result<PathBuf, String> (linux)`
36+
///
37+
/// ## File and FileDescriptor related
38+
/// `pub fn pidfdinfo<T: PIDFDInfo>(pid : i32, fd: i32) -> Result<T, String> (macos)`
39+
///
40+
/// ## PID Resource Usage related
41+
/// (Added in Mac OS X 10.9 - under "macosx_10_9" feature)
42+
/// `pub fn pidrusage<T: PIDRUsage>(pid : i32) -> Result<T, String> (macos)`
43+
///
44+
/// ## Kernel Message Buffer - kmsgbuf
45+
/// `pub fn kmsgbuf() -> Result<String, String>`
1246
pub mod libproc;
13-
/// List processes by type and / or by path
47+
/// List processes by type, path or by type and path.
48+
///
49+
/// `pub fn pids_by_type(filter: ProcFilter)` (macos) (linux)
50+
///
51+
/// `pub fn pids_by_path(path: &Path, is_volume: bool, exclude_event_only: bool)` (macos)
52+
///
53+
/// `pub fn pids_by_type_and_path(filter: ProcFilter, path: &Path, is_volume: bool, exclude_event_only: bool)` (macos)
1454
pub mod processes;
1555

1656
#[cfg(target_os = "macos")]
1757
#[allow(warnings, missing_docs)]
1858
mod osx_libproc_bindings {
19-
include!(concat!(env!("OUT_DIR"), "/osx_libproc_bindings.rs"));
59+
include!(concat!(env!("OUT_DIR"), "/osx_libproc_bindings.rs"));
2060
}

0 commit comments

Comments
 (0)