Files
mckernel/test/mng_mod/issues/863/CT2006.c
Tomoki Shirasawa 81d18e35dd rename files
2018-03-23 15:35:24 +09:00

76 lines
1.2 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <sys/time.h>
#include <sys/wait.h>
#define FILESIZE (2L * 1024 * 1024 * 1024)
pid_t pid;
void
sig(int s)
{
fprintf(stderr, "kill SIGURG\n");
kill(pid, SIGURG);
}
void
child()
{
char *buf;
long rc;
long l;
long r;
int fd;
buf = malloc(FILESIZE);
fd = open("testfile", O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Could not open file\n");
unlink("testfile");
exit(1);
}
rc = read(fd, buf, FILESIZE);
}
int
main(int argc, char **argv)
{
int st;
int rc;
pid = fork();
if (pid == 0) {
child();
exit(99);
}
signal(SIGALRM, sig);
alarm(2);
while ((rc = waitpid(pid, &st, 0)) == -1 && errno == EINTR);
if (rc != pid) {
fprintf(stderr, "CT2006 NG BAD wait rc=%d errno=%d\n", rc, errno);
exit(1);
}
if (WIFSIGNALED(st)) {
fprintf(stderr, "CT2006 NG BAD signal st=%08x\n", st);
exit(1);
}
if (!WIFEXITED(st)) {
fprintf(stderr, "CT2006 NG BAD terminated st=%08x\n", st);
exit(1);
}
if (WEXITSTATUS(st) != 99) {
fprintf(stderr, "CT2006 NG BAD exit status st=%08x\n", st);
exit(1);
}
fprintf(stderr, "CT2006 OK\n");
exit(0);
}