~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/acct/acct_syscall.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 /* kselftest for acct() system call
  4  *  The acct() system call enables or disables process accounting.
  5  */
  6 
  7 #include <stdio.h>
  8 #include <errno.h>
  9 #include <string.h>
 10 #include <sys/wait.h>
 11 
 12 #include "../kselftest.h"
 13 
 14 int main(void)
 15 {
 16         char filename[] = "process_log";
 17         FILE *fp;
 18         pid_t child_pid;
 19         int sz;
 20 
 21         // Setting up kselftest framework
 22         ksft_print_header();
 23         ksft_set_plan(1);
 24 
 25         // Check if test is run a root
 26         if (geteuid()) {
 27                 ksft_test_result_skip("This test needs root to run!\n");
 28                 return 1;
 29         }
 30 
 31         // Create file to log closed processes
 32         fp = fopen(filename, "w");
 33 
 34         if (!fp) {
 35                 ksft_test_result_error("%s.\n", strerror(errno));
 36                 ksft_finished();
 37                 return 1;
 38         }
 39 
 40         acct(filename);
 41 
 42         // Handle error conditions
 43         if (errno) {
 44                 ksft_test_result_error("%s.\n", strerror(errno));
 45                 fclose(fp);
 46                 ksft_finished();
 47                 return 1;
 48         }
 49 
 50         // Create child process and wait for it to terminate.
 51 
 52         child_pid = fork();
 53 
 54         if (child_pid < 0) {
 55                 ksft_test_result_error("Creating a child process to log failed\n");
 56                 acct(NULL);
 57                 return 1;
 58         } else if (child_pid > 0) {
 59                 wait(NULL);
 60                 fseek(fp, 0L, SEEK_END);
 61                 sz = ftell(fp);
 62 
 63                 acct(NULL);
 64 
 65                 if (sz <= 0) {
 66                         ksft_test_result_fail("Terminated child process not logged\n");
 67                         ksft_exit_fail();
 68                         return 1;
 69                 }
 70 
 71                 ksft_test_result_pass("Successfully logged terminated process.\n");
 72                 fclose(fp);
 73                 ksft_exit_pass();
 74                 return 0;
 75         }
 76 
 77         return 1;
 78 }
 79 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php