mirror of
https://github.com/torvalds/linux.git
synced 2026-04-19 23:34:00 -04:00
This follow-up patch completes centralization of kselftest.h and ksefltest_harness.h includes in remaining seltests files, replacing all relative paths with a non-relative paths using shared -I include path in lib.mk Tested with gcc-13.3 and clang-18.1, and cross-compiled successfully on riscv, arm64, x86_64 and powerpc arch. [reddybalavignesh9979@gmail.com: add selftests include path for kselftest.h] Link: https://lkml.kernel.org/r/20251017090201.317521-1-reddybalavignesh9979@gmail.com Link: https://lkml.kernel.org/r/20251016104409.68985-1-reddybalavignesh9979@gmail.com Signed-off-by: Bala-Vignesh-Reddy <reddybalavignesh9979@gmail.com> Suggested-by: Andrew Morton <akpm@linux-foundation.org> Link: https://lore.kernel.org/lkml/20250820143954.33d95635e504e94df01930d0@linux-foundation.org/ Reviewed-by: Wei Yang <richard.weiyang@gmail.com> Cc: David Hildenbrand <david@redhat.com> Cc: David S. Miller <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Günther Noack <gnoack@google.com> Cc: Jakub Kacinski <kuba@kernel.org> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Mickael Salaun <mic@digikod.net> Cc: Ming Lei <ming.lei@redhat.com> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Simon Horman <horms@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
79 lines
1.4 KiB
C
79 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/* kselftest for acct() system call
|
|
* The acct() system call enables or disables process accounting.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <sys/wait.h>
|
|
|
|
#include "kselftest.h"
|
|
|
|
int main(void)
|
|
{
|
|
char filename[] = "process_log";
|
|
FILE *fp;
|
|
pid_t child_pid;
|
|
int sz;
|
|
|
|
// Setting up kselftest framework
|
|
ksft_print_header();
|
|
ksft_set_plan(1);
|
|
|
|
// Check if test is run a root
|
|
if (geteuid()) {
|
|
ksft_exit_skip("This test needs root to run!\n");
|
|
return 1;
|
|
}
|
|
|
|
// Create file to log closed processes
|
|
fp = fopen(filename, "w");
|
|
|
|
if (!fp) {
|
|
ksft_test_result_error("%s.\n", strerror(errno));
|
|
ksft_finished();
|
|
return 1;
|
|
}
|
|
|
|
acct(filename);
|
|
|
|
// Handle error conditions
|
|
if (errno) {
|
|
ksft_test_result_error("%s.\n", strerror(errno));
|
|
fclose(fp);
|
|
ksft_finished();
|
|
return 1;
|
|
}
|
|
|
|
// Create child process and wait for it to terminate.
|
|
|
|
child_pid = fork();
|
|
|
|
if (child_pid < 0) {
|
|
ksft_test_result_error("Creating a child process to log failed\n");
|
|
acct(NULL);
|
|
return 1;
|
|
} else if (child_pid > 0) {
|
|
wait(NULL);
|
|
fseek(fp, 0L, SEEK_END);
|
|
sz = ftell(fp);
|
|
|
|
acct(NULL);
|
|
|
|
if (sz <= 0) {
|
|
ksft_test_result_fail("Terminated child process not logged\n");
|
|
ksft_exit_fail();
|
|
return 1;
|
|
}
|
|
|
|
ksft_test_result_pass("Successfully logged terminated process.\n");
|
|
fclose(fp);
|
|
ksft_exit_pass();
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|