def _set_refresh_interval(arg): global _refresh_interval _refresh_interval = float(arg[1]) if _refresh_interval < 1: raise conf.UserError("Option {0} can not be less than 1 second".format( arg[0])) def _set_id_max_len(arg): global _id_max_len _id_max_len = int(arg[1]) if _id_max_len < 1: raise conf.UserError("Option {0} can not be less than 1".format( arg[0])) def _set_data_dir(arg): os.chdir(arg[1]) def _set_max_queue_size(arg): global _max_queue_size _max_queue_size = int(arg[1]) conf.simple_conf_handler("RefreshInterval", _set_refresh_interval, default="2") conf.simple_conf_handler("JudgeIdMaxLen", _set_id_max_len, default="20") conf.simple_conf_handler("DataDir", _set_data_dir) conf.simple_conf_handler("MaxQueueSize", _set_max_queue_size, default="1024")
def _set_web_retry_cnt(arg): global _retry_cnt _retry_cnt = int(arg[1]) if _retry_cnt == 0: _retry_cnt = 1 def _set_web_retry_wait(arg): global _retry_wait _retry_wait = float(arg[1]) if _retry_wait < 1: _retry_wait = 1 def _set_web_sched_interval(arg): global _sched_interval _sched_interval = float(arg[1]) if _sched_interval < 0.5: _sched_interval = 0.5 conf.simple_conf_handler("Password", _set_static_password) conf.simple_conf_handler("WebTimeout", _set_web_timeout, "5") conf.simple_conf_handler("WebAddress", _set_web_addr) conf.simple_conf_handler("WebRetryCount", _set_web_retry_cnt, "5") conf.simple_conf_handler("WebRetryWait", _set_web_retry_wait, "2") conf.simple_conf_handler("WebSchedInterval", _set_web_sched_interval, "1") conf.register_init_func(_login)
core.lang_dict[lang].judge(conn, pcode, pconf, src, input, output) except snc.Error as e: log.error("failed to communicate with orzoj-server because of network error") control.set_termination_flag() raise Error except core.Error: control.set_termination_flag() raise Error def _set_datacache(arg): os.chdir(arg[1]) def _set_id(arg): global _judge_id _judge_id = arg[1] def _ch_set_info(arg): if len(arg) == 1: return if len(arg) < 3: raise conf.UserError("Option {0} takes at least two arguments" . format(arg[0])) global _info_dict _info_dict[arg[1]] = "\n".join(arg[2:]) conf.simple_conf_handler("DataCache", _set_datacache) conf.simple_conf_handler("JudgeId", _set_id) conf.register_handler("SetInfo", _ch_set_info)
daemon.pid_end() try: work.connect(s) except work.Error: log.error("error occurred, terminating program") daemon.pid_end() def _ch_server_addr(arg): if len(arg) == 1: raise conf.UserError( "Option {0} must be specified in the configuration file".format( arg[0])) if len(arg) != 3: raise conf.UserError("Option {0} takes two arguments".format(arg[0])) global _server_addr, _server_port _server_addr = arg[1] _server_port = int(arg[2]) if _server_port <= 0 or _server_port > 65535: raise conf.UserError("port must be between 0 and 65536") def _set_umask(arg): os.umask(int(arg[1], 8)) conf.register_handler("ServerAddr", _ch_server_addr) conf.simple_conf_handler("SetUmask", _set_umask, required=False)
try: (conn, addr) = s.accept(1) except snc.ErrorTimeout: continue except snc.Error as e: control.set_termination_flag() break log.info("connected by {0!r}".format(addr)) work.thread_new_judge_connection(conn).start() s.close() while threading.active_count() > 1: log.debug("waiting for threads, current active count: {0}".format( threading.active_count())) for i in threading.enumerate(): log.debug("active thread: {0!r}".format(i.name)) time.sleep(1) daemon.pid_end() def _set_port(arg): global _port _port = int(arg[1]) if _port <= 0 or _port > 65535: raise conf.UserError("port must be between 0 and 65536") conf.simple_conf_handler("Listen", _set_port)
def _set_group(arg): if len(arg) == 2: import grp if arg[1][0] == '#': g = grp.getgrgid(int(arg[1][1:])) else: g = grp.getgrnam(arg[1]) global _cmd_vars _cmd_vars["GROUP"] = g.gr_gid conf.simple_conf_handler("ChrootDir", _set_chroot_dir, required=False, no_dup=True, require_os=conf.REQUIRE_UNIX) conf.simple_conf_handler("TempDir", _set_temp_dir, no_dup=True) conf.simple_conf_handler("LockFile", _set_lock_file, required=False, no_dup=True, require_os=conf.REQUIRE_UNIX) conf.simple_conf_handler("User", _set_user, required=False, no_dup=True, require_os=conf.REQUIRE_UNIX) conf.simple_conf_handler("Group", _set_group,
os._exit(0) def pid_start(): if _pid_file: try: with open(_pid_file, "w") as f: f.write("{0}\n".format(os.getpid())) except IOError as e: sys.exit( "orzoj: failed to open pid file [errno {0}] [filename {1!r}]: {2}" .format(e.errno, e.filename, e.strerror)) def pid_end(): if _pid_file: try: os.remove(_pid_file) except Exception as e: sys.exit("orzoj: faield to remove pid file: {0}".format(e)) sys.exit("orzoj: program exited") def _set_pid_file(arg): global _pid_file _pid_file = arg[1] conf.simple_conf_handler("PidFile", _set_pid_file)
def _set_cert_file(arg): global _cert_file _cert_file = arg[1] def _set_key_file(arg): global _key_file _key_file = arg[1] def _set_ca_file(arg): global _ca_file _ca_file = arg[1] conf.register_handler("UseIPv6", _ch_set_ipv6) conf.simple_conf_handler("NetworkTimeout", _set_timeout, default="30") conf.simple_conf_handler("CertificateFile", _set_cert_file) conf.simple_conf_handler("PrivateKeyFile", _set_key_file) conf.simple_conf_handler("CAFile", _set_ca_file) def _init(): if struct.calcsize("i") != 4 or struct.calcsize("I") != 4: sys.exit("standard size of integer or unsigned integer is not 4-byte!") conf.register_init_func(_init)
if res[0].exe_status != structures.EXESTS_NORMAL: return (None, "failed to execute verifier [status: {0}]: {1}" . format(structures.EXECUTION_STATUS_STR[res[0].exe_status], res[0].extra_info)) res = res[1] l = res.split(' ', 1) try: val = int(l[0]) except Exception: log.error("[pcode {0!r}] verifier output is unrecognizable; original output of verifier: {1!r}" . format(pcode, res)) return (None, "unrecognizable verifier output") if len(l) == 1: return (val, None) return (val, l[1]) return func def _parse_compiler_opt(opt): return shlex.split(opt) def _set_verifier_cache(arg): global _verifier_cache if not os.path.isdir(arg[1]): raise conf.UserError("verifier cache directory does not exist") _verifier_cache = arg[1] conf.simple_conf_handler("VerifierCache", _set_verifier_cache)
_max_bytes = int(arg[1]) if _max_bytes < 0: raise conf.UserError("{0} can't be less than 0".format(arg[0])) def _seg_backup_count(arg): global _backup_count _backup_count = int(arg[1]) if _backup_count < 0: raise conf.UserError("{0} can't be less than 0".format(arg[0])) def _init(): global _logger, _filename, _level, _max_bytes, _backup_count handler = logging.handlers.RotatingFileHandler(_filename, maxBytes=_max_bytes, backupCount=_backup_count) handler.setFormatter( logging.Formatter( "[%(asctime)s] [%(levelname)s] from %(funcName)s in %(module)s at %(filename)s:%(lineno)d :\n%(message)s\n" )) _logger.setLevel(_level) _logger.addHandler(handler) conf.simple_conf_handler("LogFile", _seg_filename) conf.simple_conf_handler("LogLevel", _seg_level, default="info") conf.simple_conf_handler("LogMaxBytes", _seg_max_bytes, default="0") conf.simple_conf_handler("LogBackupCount", _seg_backup_count, default="0") conf.register_init_func(_init)