-
Notifications
You must be signed in to change notification settings - Fork 675
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
Add wrapper for acct(2) #952
Conversation
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.
Don't forget to add a CHANGELOG entry.
Also, might I ask what you have in mind for this function? How are you planning to parse the accounting file? Are you writing a separate crate for that, or just planning to use lastcomm(1), or will you be adding that functionality to Nix?
src/unistd.rs
Outdated
/// | ||
/// See also [acct(2)](https://linux.die.net/man/2/acct) | ||
#[cfg(any(target_os = "linux", target_os = "android"))] | ||
pub fn acct(filename: &CString) -> Result<Void> { |
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.
The result type is wrong. Result<Void>
indicates that the function will always fail. Perhaps you mean Result<()>
?
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.
Also, the argument type is wrong. This API doesn't provide anyway to disable process accounting once it's enabled. I suggest creating an acct
module, and giving it two functions enable(filename: &CString)
, and disable()
.
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.
Wonderful ideas. I will definitely work on those changes.
src/unistd.rs
Outdated
/// Switch process accounting on or off | ||
/// | ||
/// See also [acct(2)](https://linux.die.net/man/2/acct) | ||
#[cfg(any(target_os = "linux", target_os = "android"))] |
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.
acct
is available on many more operating systems than this. Please enable it everywhere that it's supported. You may need to submit a separate PR to libc if there are some declarations missing.
src/unistd.rs
Outdated
libc::acct(filename.as_ptr()) | ||
}; | ||
|
||
Err(Error::Sys(Errno::last())) |
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.
This is the wrong way to set the return code. For one thing, it will always indicate an error. For another, errno won't be set if acct
passes. See fchmod
in sys/stat.rs for an example of how to do it right.
src/unistd.rs
Outdated
/// | ||
/// See also [acct(2)](https://linux.die.net/man/2/acct) | ||
#[cfg(any(target_os = "linux", target_os = "android"))] | ||
pub fn acct(filename: &CString) -> Result<Void> { |
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.
Also, the argument type is wrong. In Rust you should rarely use a &CString
reference explicitly. Better to use the borrowed form &CStr
. And in Nix, you should generally use NixPath
instead. See mknod
in sys/stat.rs for an example.
I am currently planning on using |
I added acct(2) to the BSD tree of libc See here.. CI should pass now |
src/unistd.rs
Outdated
@@ -1439,6 +1439,32 @@ pub fn sleep(seconds: c_uint) -> c_uint { | |||
unsafe { libc::sleep(seconds) } | |||
} | |||
|
|||
#[cfg(target_family = "unix")] |
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.
The target_family
should be unnecessary. Nix only runs on unix operating systems.
632a600
to
e030707
Compare
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.
You'll need to rebase, not just merge, the master branch. Merging the master branch into your PR makes the history screwy.
CHANGELOG.md
Outdated
@@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). | |||
([#956](https://github.com/nix-rust/nix/pull/956)) | |||
- Added a `fchownat` wrapper. | |||
([#955](https://github.com/nix-rust/nix/pull/955)) | |||
- Added a `acct` wrapper module for enabling and disabling process accounting ([#952](https://github.com/nix-rust/nix/pull/952)) |
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.
Wrap to 80 columns, please.
837d87c
to
84811a9
Compare
Hm, I tried using Github's online editor to reword a comment, but it seems that doing so creates a separate commit. Can you please squash those commits for me? I can't do it with the merge button, because Nix uses bors to merge. |
c773ea4
to
3d56c27
Compare
This patch adds a wrapper for the acct(2) syscall, with two functions for enabling and disabling process accounting.
Done! |
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.
Thanks for your contribution!
bors r+
This PR aims to add a nix wrapper for acct(2).