File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -1439,6 +1439,18 @@ pub fn sleep(seconds: c_uint) -> c_uint {
1439
1439
unsafe { libc:: sleep ( seconds) }
1440
1440
}
1441
1441
1442
+ /// Switch process accounting on or off
1443
+ ///
1444
+ /// See also [acct(2)](https://linux.die.net/man/2/acct)
1445
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1446
+ pub fn acct ( filename : & CString ) -> Result < Void > {
1447
+ unsafe {
1448
+ libc:: acct ( filename. as_ptr ( ) )
1449
+ } ;
1450
+
1451
+ Err ( Error :: Sys ( Errno :: last ( ) ) )
1452
+ }
1453
+
1442
1454
/// Creates a regular file which persists even after process termination
1443
1455
///
1444
1456
/// * `template`: a path whose 6 rightmost characters must be X, e.g. `/tmp/tmpfile_XXXXXX`
Original file line number Diff line number Diff line change @@ -6,10 +6,11 @@ use nix::sys::wait::*;
6
6
use nix:: sys:: stat:: { self , Mode , SFlag } ;
7
7
use std:: { env, iter} ;
8
8
use std:: ffi:: CString ;
9
- use std:: fs:: File ;
9
+ use std:: fs:: { File , metadata } ;
10
10
use std:: io:: Write ;
11
11
use std:: os:: unix:: prelude:: * ;
12
- use tempfile:: { self , tempfile} ;
12
+ use std:: process:: Command ;
13
+ use tempfile:: { self , tempfile, NamedTempFile } ;
13
14
use libc:: { self , _exit, off_t} ;
14
15
15
16
#[ test]
@@ -335,6 +336,18 @@ fn test_lseek64() {
335
336
close ( tmpfd) . unwrap ( ) ;
336
337
}
337
338
339
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
340
+ #[ test]
341
+ fn test_acct ( ) {
342
+ skip_if_not_root ! ( "test_acct" ) ;
343
+ let file = NamedTempFile :: new ( ) . unwrap ( ) ;
344
+ let path = file. path ( ) . to_str ( ) . unwrap ( ) ;
345
+ acct ( & CString :: new ( path) . unwrap ( ) ) . unwrap ( ) ;
346
+ Command :: new ( "echo" ) . arg ( "Hello world" ) ;
347
+ let md = metadata ( path) . unwrap ( ) ;
348
+ assert ! ( md. len( ) > 0 ) ;
349
+ }
350
+
338
351
#[ test]
339
352
fn test_fpathconf_limited ( ) {
340
353
let f = tempfile ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments