Files
cubelinux-kernel/tools/testing/selftests/acct/acct_syscall.c
T
Greg Kroah-Hartman 598cf27219 Linux 6.19.3
Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com>
Tested-by: Peter Schneider <pschneider1968@googlemail.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Salvatore Bonaccorso <carnil@debian.org>
Tested-by: Brett A C Sheffield <bacs@librecast.net>
Tested-by: Mark Brown <broonie@kernel.org>
Tested-by: Luna Jernberg <droidbittin@gmail.com>
Tested-by: Ronald Warsow <rwarsow@gmx.de>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Tested-by: Ron Economos <re@w6rz.net>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-02-19 16:33:27 +01:00

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;
}