Skip to content
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

Merged
merged 1 commit into from Oct 24, 2018
Merged

Add wrapper for acct(2) #952

merged 1 commit into from Oct 24, 2018

Conversation

@jabedude
Copy link
Contributor

@jabedude jabedude commented Oct 12, 2018

This PR aims to add a nix wrapper for acct(2).

Copy link
Member

@asomers asomers left a comment

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?

///
/// 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> {

This comment has been minimized.

@asomers

asomers Oct 12, 2018
Member

The result type is wrong. Result<Void> indicates that the function will always fail. Perhaps you mean Result<()>?

This comment has been minimized.

@asomers

asomers Oct 12, 2018
Member

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().

This comment has been minimized.

@jabedude

jabedude Oct 12, 2018
Author Contributor

Wonderful ideas. I will definitely work on those changes.

/// 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"))]

This comment has been minimized.

@asomers

asomers Oct 12, 2018
Member

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.

libc::acct(filename.as_ptr())
};

Err(Error::Sys(Errno::last()))

This comment has been minimized.

@asomers

asomers Oct 12, 2018
Member

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.

test/test_unistd.rs Show resolved Hide resolved
///
/// 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> {

This comment has been minimized.

@asomers

asomers Oct 12, 2018
Member

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.

@jabedude jabedude force-pushed the jabedude:acct-api branch from 01e6a00 to 2ef9333 Oct 13, 2018
@jabedude
Copy link
Contributor Author

@jabedude jabedude commented Oct 13, 2018

I am currently planning on using lastcomm, but I might make a separate crate for parsing pacct files.

@jabedude
Copy link
Contributor Author

@jabedude jabedude commented Oct 15, 2018

I added acct(2) to the BSD tree of libc See here.. CI should pass now

@@ -1439,6 +1439,32 @@ pub fn sleep(seconds: c_uint) -> c_uint {
unsafe { libc::sleep(seconds) }
}

#[cfg(target_family = "unix")]

This comment has been minimized.

@asomers

asomers Oct 15, 2018
Member

The target_family should be unnecessary. Nix only runs on unix operating systems.

test/test_unistd.rs Show resolved Hide resolved
test/test_unistd.rs Outdated Show resolved Hide resolved
@jabedude jabedude force-pushed the jabedude:acct-api branch 2 times, most recently from 632a600 to e030707 Oct 15, 2018
test/test_unistd.rs Show resolved Hide resolved
Copy link
Member

@asomers asomers left a comment

You'll need to rebase, not just merge, the master branch. Merging the master branch into your PR makes the history screwy.

test/test_unistd.rs Show resolved Hide resolved
@@ -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))

This comment has been minimized.

@asomers

asomers Oct 20, 2018
Member

Wrap to 80 columns, please.

test/test_unistd.rs Outdated Show resolved Hide resolved
@jabedude jabedude force-pushed the jabedude:acct-api branch 2 times, most recently from 837d87c to 84811a9 Oct 21, 2018
@asomers
Copy link
Member

@asomers asomers commented Oct 21, 2018

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.

@jabedude jabedude force-pushed the jabedude:acct-api branch 2 times, most recently from c773ea4 to 3d56c27 Oct 21, 2018
This patch adds a wrapper for the acct(2) syscall, with two functions
for enabling and disabling process accounting.
@jabedude jabedude force-pushed the jabedude:acct-api branch from 3d56c27 to 0ce57d9 Oct 21, 2018
@jabedude
Copy link
Contributor Author

@jabedude jabedude commented Oct 21, 2018

Done!

Copy link
Member

@asomers asomers left a comment

Thanks for your contribution!

bors r+

bors bot added a commit that referenced this pull request Oct 24, 2018
Merge #952
952: Add wrapper for acct(2) r=asomers a=jabedude

This PR aims to add a nix wrapper for acct(2).

Co-authored-by: Josh Abraham <sinisterpatrician@gmail.com>
@bors bors bot merged commit 0ce57d9 into nix-rust:master Oct 24, 2018
4 checks passed
4 checks passed
bors Build succeeded
Details
buildbot/nix-rust/nix amd64_fbsd11 Build done.
Details
buildbot/nix-rust/nix i386_fbsd11 Build done.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jabedude jabedude deleted the jabedude:acct-api branch Oct 24, 2018
asomers added a commit to asomers/nix that referenced this pull request Nov 21, 2018
asomers added a commit to asomers/nix that referenced this pull request Nov 22, 2018
asomers added a commit to asomers/nix that referenced this pull request Nov 23, 2018
levex added a commit to levex/nix that referenced this pull request Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants