summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
authorJosh Abraham <sinisterpatrician@gmail.com>2018-10-20 20:44:26 -0400
committerJosh Abraham <sinisterpatrician@gmail.com>2018-10-21 15:48:52 -0400
commit0ce57d934a20c2814d7a32ca84df8dc9e5e20bc6 (patch)
treeae2f2fafdbfbb2dd27fd91cd23cb4d3db24110b5 /src/unistd.rs
parent9ed9a1dccb98e6a2f91269c09e49641c4ff395b8 (diff)
downloadnix-0ce57d934a20c2814d7a32ca84df8dc9e5e20bc6.zip
Add acct(2) wrapper API
This patch adds a wrapper for the acct(2) syscall, with two functions for enabling and disabling process accounting.
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index d5192977..c9c129c9 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1508,6 +1508,31 @@ pub fn sleep(seconds: c_uint) -> c_uint {
unsafe { libc::sleep(seconds) }
}
+pub mod acct {
+ use libc;
+ use {Result, NixPath};
+ use errno::Errno;
+ use std::ptr;
+
+ /// Enable process accounting
+ ///
+ /// See also [acct(2)](https://linux.die.net/man/2/acct)
+ pub fn enable<P: ?Sized + NixPath>(filename: &P) -> Result<()> {
+ let res = try!(filename.with_nix_path(|cstr| {
+ unsafe { libc::acct(cstr.as_ptr()) }
+ }));
+
+ Errno::result(res).map(drop)
+ }
+
+ /// Disable process accounting
+ pub fn disable() -> Result<()> {
+ let res = unsafe { libc::acct(ptr::null()) };
+
+ Errno::result(res).map(drop)
+ }
+}
+
/// Creates a regular file which persists even after process termination
///
/// * `template`: a path whose 6 rightmost characters must be X, e.g. `/tmp/tmpfile_XXXXXX`