Компания "Яндекс" и проект SnarkNews представляют

SnarkNews summer series - 2007

Running by Yandex
 

Используемая на сервере реализация Java - Java 1.5.0_04

Компиляция программ на Java осуществляется следующим скриптом:

#!/bin/bash
# $Id: javac.in,v 1.3 2004/10/27 05:40:34 cher Exp $
# Copyright (c) 2004 Alexander Chernov

# Usage: javac in-file out-file
# The working dir must not contain any .class files.

# using EJUDGE_FLAGS we may pass additional flags

infile="$1"
outfile="$2"

JAVACRUN="/usr/java/jdk1.5.0_04/bin/javac"
JAVADIR="/usr/java/jdk1.5.0_04"
JAVAVER="1.5"

if [ x"${JAVACRUN}" = x -o x"${JAVACRUN}" = xno ]
then
  echo "This language is not supported." >&2
  exit 1
fi

JAVA_HOME="${JAVADIR}"
PATH="${JAVA_HOME}/bin:${PATH}"
export JAVA_HOME PATH

mv "$infile" Main.java || exit 1
rm -f *.class
"${JAVACRUN}" -source "${JAVAVER}" -Xlint:unchecked ${EJUDGE_FLAGS} Main.java || exit 1

if [ ! -f Main.class ]
then
  echo "No output file Main.class" >& 2
  exit 1
fi

"${JAVA_HOME}/bin/jar" cvf Main.jar *.class || exit 1

mv Main.jar "$outfile" || exit 1
exit 0

Запуск программ на Java осуществляется следующим скриптом:

#!/bin/bash
# $Id: runjava.in,v 1.3 2004/10/27 05:40:09 cher Exp $
# Copyright (c) 2004 Alexander Chernov

# assume that we have single argument
# EJUDGE_JAVA_FLAGS may be used to pass additional flags
# EJUDGE_JAVA_POLICY is the policy name
# EJUDGE_PREFIX_DIR is used to create the full path

runfile="$1"

JAVARUN="/usr/java/jdk1.5.0_04/bin/java"
JAVADIR="/usr/java/jdk1.5.0_04"
JAVAVER="1.5"

JAVA_HOME="${JAVADIR}"
PATH="${JAVA_HOME}/bin:${PATH}"
export JAVA_HOME PATH

if [ x"${EJUDGE_JAVA_POLICY}" = xnone ]
then
  # no securuty policy, use with caution!
  mv "$1" Main.jar || exit 128
  exec "${JAVARUN}" ${EJUDGE_JAVA_FLAGS} -cp ./Main.jar Main
fi

[ x"${EJUDGE_JAVA_POLICY}" = x ] && EJUDGE_JAVA_POLICY=default.policy

if [ -f "${EJUDGE_JAVA_POLICY}" ]
then
  policy_file="${EJUDGE_JAVA_POLICY}"
else
  if [ x"${EJUDGE_PREFIX_DIR}" = x ]
  then
    echo "EJUDGE_PREFIX_DIR is not set - impossible to set securuty policy" >&2
    exit 128
  fi
  policy_file="${EJUDGE_PREFIX_DIR}/share/ejudge/${EJUDGE_JAVA_POLICY}"
fi

if [ ! -f "${policy_file}" ]
then
  echo "Java policy file does not exist" >&2
  exit 128
fi

mv "$1" Main.jar || exit 128
exec "${JAVARUN}" ${EJUDGE_JAVA_FLAGS} -cp ./Main.jar -Djava.security.manager -Duser.language=us -Duser.country=US -Djava.security.policy="${policy_file}" Main