From 0ce57d934a20c2814d7a32ca84df8dc9e5e20bc6 Mon Sep 17 00:00:00 2001 From: Josh Abraham Date: Sat, 20 Oct 2018 20:44:26 -0400 Subject: Add acct(2) wrapper API This patch adds a wrapper for the acct(2) syscall, with two functions for enabling and disabling process accounting. --- src/unistd.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/unistd.rs') 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(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` -- cgit v1.2.3