int main(void) { int p, s, r; struct rusage rr; long long tms = 0; fprintf(stderr, "t6: checking millisecond time limits\n"); if ((linux_version = get_linux_version()) < 0) return 1; if (!linux_version) { fprintf(stderr, "failed: not Linux or unknown linux version\n"); return 1; } fprintf(stderr, "t6: linux version %d\n", linux_version); if (linux_version >= 3000000) { fprintf(stderr, "t6: patch for linux >= 3.0.0 does not support millisecond time limits\n"); return 0; } if ((p = fork()) < 0) { fprintf(stderr, "failed: unexpected fork() error: %s\n", strerror(errno)); return 1; } if (!p) do_son(); sleep(5); r = wait4(-1, &s, WNOHANG, &rr); if (!r) { fprintf(stderr, "failed: child did not terminate in 5 seconds\n"); kill(p, SIGKILL); wait(0); return 1; } if (WIFEXITED(s) && WEXITSTATUS(s) == 111) { fprintf(stderr, "failed: child failed to setup limitations\n"); return 1; } if (WIFEXITED(s)) { fprintf(stderr, "info: child exited: %d\n", WEXITSTATUS(s)); } else if (WIFSIGNALED(s)) { fprintf(stderr, "info: child signaled: %d\n", WTERMSIG(s)); } tms = 0; tms += rr.ru_utime.tv_sec * 1000; tms += rr.ru_stime.tv_sec * 1000; tms += rr.ru_utime.tv_usec / 1000; tms += rr.ru_stime.tv_usec / 1000; fprintf(stderr, "info: child user+sys ms: %lld\n", tms); if (tms > 900) { fprintf(stderr, "failed: millisecond timelimit does not work\n"); return 1; } fprintf(stderr, "ok\n"); return 0; }
int main(int argc, char **argv) { int p, s, d = 0; snprintf(progname, sizeof(progname), "%s_helper", argv[0]); fprintf(stderr, "t5: checking memory limit error for program size\n"); if ((linux_version = get_linux_version()) < 0) return 1; if (!linux_version) { fprintf(stderr, "failed: not Linux or unknown linux version\n"); return 1; } fprintf(stderr, "t5: linux version %d\n", linux_version); if ((p = fork()) < 0) { fprintf(stderr, "failed: unexpected fork() error: %s\n", strerror(errno)); return 1; } if (!p) do_son(); wait(&s); if ((s & 0x10000)) { fprintf(stderr, "info: 0x10000 detected\n"); s &= 0xffff; d = 1; } if (WIFEXITED(s) && WEXITSTATUS(s) == 111) { fprintf(stderr, "failed: child failed to setup limitations\n"); return 1; } if (WIFEXITED(s)) { fprintf(stderr, "info: child exited: %d\n", WEXITSTATUS(s)); } else if (WIFSIGNALED(s)) { fprintf(stderr, "info: child signaled: %d\n", WTERMSIG(s)); } if (!d) { fprintf(stderr, "failed: memory limit error not detected\n"); return 1; } fprintf(stderr, "ok\n"); return 0; }
int main(void) { int p, s, d = 0; fprintf(stderr, "t3: checking memory limit error for stack\n"); if ((linux_version = get_linux_version()) < 0) return 1; if (!linux_version) { fprintf(stderr, "failed: not Linux or unknown linux version\n"); return 1; } fprintf(stderr, "t3: linux version %d\n", linux_version); if ((p = fork()) < 0) { fprintf(stderr, "failed: unexpected fork() error: %s\n", strerror(errno)); return 1; } if (!p) do_son(); wait(&s); if ((s & 0x10000)) { fprintf(stderr, "\ninfo: 0x10000 detected\n"); s &= 0xffff; d = 1; } if (WIFEXITED(s) && WEXITSTATUS(s) == 111) { fprintf(stderr, "failed: child failed to setup limitations\n"); return 1; } if (WIFEXITED(s)) { fprintf(stderr, "info: child exited: %d\n", WEXITSTATUS(s)); } else if (WIFSIGNALED(s)) { fprintf(stderr, "info: child signaled: %d\n", WTERMSIG(s)); } if (!d) { fprintf(stderr, "failed: memory limit error not detected\n"); return 1; } fprintf(stderr, "ok\n"); return 0; }