From fafb30db05ca265e36a580ee213092993896e54e Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Sun, 2 Jun 2024 12:56:46 -0400 Subject: [PATCH] Add --max-execution-time option --- src/init.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/init.c b/src/init.c index 5d0a0410..86d7809b 100644 --- a/src/init.c +++ b/src/init.c @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef HAVE_INITGROUPS #include @@ -1013,14 +1014,30 @@ AddTrustedUser(char const *username) TrustedUsers[NumTrustedUsers] = pwent->pw_uid; NumTrustedUsers++; } +static void +sigalarm(int) +{ + write(STDOUT_FILENO, "\nExecution time exceeded.\n", 26); + exit(1); +} static void ProcessLongOption(char const *arg) { + int t; if (!strcmp(arg, "version")) { printf("%s\n", VERSION); exit(EXIT_SUCCESS); } + if (sscanf(arg, "max-execution-time=%d", &t) == 1) { + if (t <= 0) { + fprintf(ErrFp, "%s: Value of --max-execution-time must be positive\n", ArgV[0]); + return; + } + signal(SIGALRM, sigalarm); + alarm(t); + return; + } fprintf(ErrFp, "%s: Unknown long option --%s\n", ArgV[0], arg); }