Skip to content

Commit aa67a2b

Browse files
committed
Improve runguard error message when command cannot be executed
When the system error is "Permission denied" this typically means that the full path of the command is not traversible for the user. This can happen for example when a validator is executed as `domjudge-run` user and `/home/domjudge` does not have `o+x` set.
1 parent b3811b5 commit aa67a2b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

judge/runguard.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,20 @@ int groupid(char *name)
771771
return (int) grp->gr_gid;
772772
}
773773

774+
char *username()
775+
{
776+
int saved_errno = errno;
777+
errno = 0; /* per the linux GETPWNAM(3) man-page */
778+
779+
struct passwd *pwd;
780+
pwd = getpwuid(getuid());
781+
782+
if ( pwd==nullptr || errno ) error(errno,"failed to get username");
783+
errno = saved_errno;
784+
785+
return pwd->pw_name;
786+
}
787+
774788
long read_optarg_int(const char *desc, long minval, long maxval)
775789
{
776790
char *ptr;
@@ -1384,9 +1398,7 @@ int main(int argc, char **argv)
13841398

13851399
/* And execute child command. */
13861400
execvp(cmdname,cmdargs);
1387-
struct rlimit limit;
1388-
getrlimit(RLIMIT_NPROC, &limit);
1389-
error(errno,"cannot start `%s', limit: %ld/%ld | ",cmdname, limit.rlim_cur, limit.rlim_max);
1401+
error(errno,"cannot start `%s' as user `%s'", cmdname, username());
13901402

13911403
default: /* become watchdog */
13921404
verbose("child pid = %d", child_pid);

0 commit comments

Comments
 (0)