Skip to content

Commit bab1f7d

Browse files
elderingmeisterT
authored andcommitted
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. (cherry picked from commit aa67a2b)
1 parent 06beacf commit bab1f7d

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
@@ -815,6 +815,20 @@ int groupid(char *name)
815815
return (int) grp->gr_gid;
816816
}
817817

818+
char *username()
819+
{
820+
int saved_errno = errno;
821+
errno = 0; /* per the linux GETPWNAM(3) man-page */
822+
823+
struct passwd *pwd;
824+
pwd = getpwuid(getuid());
825+
826+
if ( pwd==nullptr || errno ) error(errno,"failed to get username");
827+
errno = saved_errno;
828+
829+
return pwd->pw_name;
830+
}
831+
818832
long read_optarg_int(const char *desc, long minval, long maxval)
819833
{
820834
char *ptr;
@@ -1426,9 +1440,7 @@ int main(int argc, char **argv)
14261440

14271441
/* And execute child command. */
14281442
execvp(cmdname,cmdargs);
1429-
struct rlimit limit;
1430-
getrlimit(RLIMIT_NPROC, &limit);
1431-
error(errno,"cannot start `%s', limit: %ld/%ld | ",cmdname, limit.rlim_cur, limit.rlim_max);
1443+
error(errno,"cannot start `%s' as user `%s'", cmdname, username());
14321444

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

0 commit comments

Comments
 (0)