Skip to content

Commit 3f49e61

Browse files
committed
ejudge_config passed to prepare() as the first parameter
1 parent 09d62ed commit 3f49e61

File tree

10 files changed

+54
-51
lines changed

10 files changed

+54
-51
lines changed

bin/ej-compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ main(int argc, char *argv[])
19191919
subst_dst_ptr = subst_dst;
19201920
#endif
19211921

1922-
if (prepare(NULL, &serve_state, compile_cfg_path, prepare_flags, PREPARE_COMPILE,
1922+
if (prepare(ejudge_config, NULL, &serve_state, compile_cfg_path, prepare_flags, PREPARE_COMPILE,
19231923
cpp_opts, 0, subst_src_ptr, subst_dst_ptr) < 0)
19241924
return 1;
19251925
#if HAVE_OPEN_MEMSTREAM - 0

bin/ej-convert-status.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- mode: c; c-basic-offset: 4 -*- */
22

3-
/* Copyright (C) 2022 Alexander Chernov <[email protected]> */
3+
/* Copyright (C) 2022-2023 Alexander Chernov <[email protected]> */
44

55
/*
66
* This program is free software; you can redistribute it and/or modify
@@ -124,7 +124,7 @@ process_contest(
124124
state->current_time = time(NULL);
125125
state->load_time = state->current_time;
126126

127-
if (prepare(cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
127+
if (prepare(ejudge_config, cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
128128
goto done;
129129
if (prepare_serve_defaults(cnts, state, NULL) < 0) goto done;
130130
global = state->global;

bin/ej-convert-variant.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- mode: c; c-basic-offset: 4 -*- */
22

3-
/* Copyright (C) 2022 Alexander Chernov <[email protected]> */
3+
/* Copyright (C) 2022-2023 Alexander Chernov <[email protected]> */
44

55
/*
66
* This program is free software; you can redistribute it and/or modify
@@ -197,7 +197,7 @@ process_contest(
197197
state->current_time = time(NULL);
198198
state->load_time = state->current_time;
199199

200-
if (prepare(cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
200+
if (prepare(ejudge_config, cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
201201
goto done;
202202
if (prepare_serve_defaults(cnts, state, NULL) < 0) goto done;
203203
global = state->global;

bin/ej-convert-xuser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- mode: c; c-basic-offset: 4 -*- */
22

3-
/* Copyright (C) 2022 Alexander Chernov <[email protected]> */
3+
/* Copyright (C) 2022-2023 Alexander Chernov <[email protected]> */
44

55
/*
66
* This program is free software; you can redistribute it and/or modify
@@ -127,7 +127,7 @@ process_contest(
127127
state->current_time = time(NULL);
128128
state->load_time = state->current_time;
129129

130-
if (prepare(cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
130+
if (prepare(ejudge_config, cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
131131
goto done;
132132
if (prepare_serve_defaults(cnts, state, NULL) < 0) goto done;
133133
global = state->global;

bin/ej-fix-db.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- mode: c -*- */
22

3-
/* Copyright (C) 2010-2019 Alexander Chernov <[email protected]> */
3+
/* Copyright (C) 2010-2023 Alexander Chernov <[email protected]> */
44

55
/*
66
* This program is free software; you can redistribute it and/or modify
@@ -554,7 +554,7 @@ process_contest(int contest_id)
554554
state->config_path = xstrdup(config_path);
555555
state->current_time = time(0);
556556
state->load_time = state->current_time;
557-
if (prepare(NULL, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
557+
if (prepare(NULL, NULL, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
558558
goto failure;
559559
global = state->global;
560560
if (!global) {

bin/ej-run.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- c -*- */
22

3-
/* Copyright (C) 2000-2022 Alexander Chernov <[email protected]> */
3+
/* Copyright (C) 2000-2023 Alexander Chernov <[email protected]> */
44

55
/*
66
* This program is free software; you can redistribute it and/or modify
@@ -1145,7 +1145,7 @@ main(int argc, char *argv[])
11451145

11461146
if (!strcasecmp(EJUDGE_CHARSET, "UTF-8")) utf8_mode = 1;
11471147

1148-
if (prepare(NULL, &serve_state, argv[i], p_flags, PREPARE_RUN,
1148+
if (prepare(NULL, NULL, &serve_state, argv[i], p_flags, PREPARE_RUN,
11491149
cpp_opts, managed_mode_flag, 0, 0) < 0)
11501150
return 1;
11511151
if (filter_testers(key) < 0) return 1;

bin/ej-serve.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- mode: c -*- */
22

3-
/* Copyright (C) 2000-2019 Alexander Chernov <[email protected]> */
3+
/* Copyright (C) 2000-2023 Alexander Chernov <[email protected]> */
44

55
/*
66
* This program is free software; you can redistribute it and/or modify
@@ -145,7 +145,7 @@ main(int argc, char *argv[])
145145
// initialize the current time to avoid some asserts
146146
serve_state.current_time = time(0);
147147

148-
if (prepare(NULL, &serve_state, argv[i], p_flags, PREPARE_SERVE, cpp_opts,
148+
if (prepare(NULL, NULL, &serve_state, argv[i], p_flags, PREPARE_SERVE, cpp_opts,
149149
(cmdline_socket_fd >= 0), 0, 0) < 0) return 1;
150150
if (prepare_serve_defaults(NULL, &serve_state, &cur_contest) < 0) return 1;
151151

include/ejudge/prepare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,7 @@ struct section_tester_data
15001500

15011501
int
15021502
prepare(
1503+
const struct ejudge_cfg *config,
15031504
const struct contest_desc *cnts,
15041505
serve_state_t,
15051506
char const *,

lib/prepare.c

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,6 +2697,7 @@ prepare_insert_variant_num(
26972697

26982698
static int
26992699
set_defaults(
2700+
const struct ejudge_cfg *config,
27002701
const struct contest_desc *cnts,
27012702
const unsigned char *config_file,
27022703
serve_state_t state,
@@ -2844,7 +2845,7 @@ set_defaults(
28442845
if (g->stand_show_warn_number == -1)
28452846
g->stand_show_warn_number = DFLT_G_STAND_SHOW_WARN_NUMBER;
28462847
if (g->autoupdate_standings == -1) {
2847-
if (ejudge_config->disable_autoupdate_standings > 0)
2848+
if (config && config->disable_autoupdate_standings > 0)
28482849
g->autoupdate_standings = 0;
28492850
else
28502851
g->autoupdate_standings = DFLT_G_AUTOUPDATE_STANDINGS;
@@ -2930,10 +2931,10 @@ set_defaults(
29302931
if (!g->root_dir || !g->root_dir[0]) {
29312932
usprintf(&g->root_dir, "%06d", contest_id);
29322933
}
2933-
if (!os_IsAbsolutePath(g->root_dir) && ejudge_config
2934-
&& ejudge_config->contests_home_dir
2935-
&& os_IsAbsolutePath(ejudge_config->contests_home_dir)) {
2936-
usprintf(&g->root_dir, "%s/%s", ejudge_config->contests_home_dir, g->root_dir);
2934+
if (!os_IsAbsolutePath(g->root_dir) && config
2935+
&& config->contests_home_dir
2936+
&& os_IsAbsolutePath(config->contests_home_dir)) {
2937+
usprintf(&g->root_dir, "%s/%s", config->contests_home_dir, g->root_dir);
29372938
}
29382939
#if defined EJUDGE_CONTESTS_HOME_DIR
29392940
if (!os_IsAbsolutePath(g->root_dir)) {
@@ -2947,27 +2948,27 @@ set_defaults(
29472948

29482949
param_subst_2(&g->root_dir, subst_src, subst_dst);
29492950

2950-
if ((!g->clardb_plugin || !g->clardb_plugin[0]) && ejudge_config
2951-
&& ejudge_config->default_clardb_plugin
2952-
&& ejudge_config->default_clardb_plugin[0]) {
2953-
xstrdup3(&g->clardb_plugin, ejudge_config->default_clardb_plugin);
2951+
if ((!g->clardb_plugin || !g->clardb_plugin[0]) && config
2952+
&& config->default_clardb_plugin
2953+
&& config->default_clardb_plugin[0]) {
2954+
xstrdup3(&g->clardb_plugin, config->default_clardb_plugin);
29542955
}
2955-
if ((!g->rundb_plugin || !g->rundb_plugin[0]) && ejudge_config
2956-
&& ejudge_config->default_rundb_plugin
2957-
&& ejudge_config->default_rundb_plugin[0]) {
2958-
xstrdup3(&g->rundb_plugin, ejudge_config->default_rundb_plugin);
2956+
if ((!g->rundb_plugin || !g->rundb_plugin[0]) && config
2957+
&& config->default_rundb_plugin
2958+
&& config->default_rundb_plugin[0]) {
2959+
xstrdup3(&g->rundb_plugin, config->default_rundb_plugin);
29592960
}
2960-
if ((!g->xuser_plugin || !g->xuser_plugin[0]) && ejudge_config
2961-
&& ejudge_config->default_xuser_plugin && ejudge_config->default_xuser_plugin[0]) {
2962-
xstrdup3(&g->xuser_plugin, ejudge_config->default_xuser_plugin);
2961+
if ((!g->xuser_plugin || !g->xuser_plugin[0]) && config
2962+
&& config->default_xuser_plugin && config->default_xuser_plugin[0]) {
2963+
xstrdup3(&g->xuser_plugin, config->default_xuser_plugin);
29632964
}
2964-
if ((!g->status_plugin || !g->status_plugin[0]) && ejudge_config
2965-
&& ejudge_config->default_status_plugin && ejudge_config->default_status_plugin[0]) {
2966-
xstrdup3(&g->status_plugin, ejudge_config->default_status_plugin);
2965+
if ((!g->status_plugin || !g->status_plugin[0]) && config
2966+
&& config->default_status_plugin && config->default_status_plugin[0]) {
2967+
xstrdup3(&g->status_plugin, config->default_status_plugin);
29672968
}
2968-
if ((!g->variant_plugin || !g->variant_plugin[0]) && ejudge_config
2969-
&& ejudge_config->default_variant_plugin && ejudge_config->default_variant_plugin[0]) {
2970-
xstrdup3(&g->variant_plugin, ejudge_config->default_variant_plugin);
2969+
if ((!g->variant_plugin || !g->variant_plugin[0]) && config
2970+
&& config->default_variant_plugin && config->default_variant_plugin[0]) {
2971+
xstrdup3(&g->variant_plugin, config->default_variant_plugin);
29712972
}
29722973

29732974
if (!g->conf_dir || !g->conf_dir[0]) {
@@ -3506,8 +3507,8 @@ set_defaults(
35063507
const unsigned char *ecd = g->extra_compile_dirs[lang->compile_dir_index - 1];
35073508
if (os_IsAbsolutePath(ecd)) {
35083509
usprintf(&lang->compile_dir, "%s/var/compile", ecd);
3509-
} else if (ejudge_config && ejudge_config->contests_home_dir) {
3510-
usprintf(&lang->compile_dir, "%s/%s/var/compile", ejudge_config->contests_home_dir, ecd);
3510+
} else if (config && config->contests_home_dir) {
3511+
usprintf(&lang->compile_dir, "%s/%s/var/compile", config->contests_home_dir, ecd);
35113512
} else {
35123513
#if defined EJUDGE_CONTESTS_HOME_DIR
35133514
usprintf(&lang->compile_dir, "%s/%s/var/compile", EJUDGE_CONTESTS_HOME_DIR, ecd);
@@ -3553,11 +3554,11 @@ set_defaults(
35533554
err("language.%d.cmd must be set", i);
35543555
return -1;
35553556
}
3556-
if (!os_IsAbsolutePath(lang->cmd) && ejudge_config && ejudge_config->compile_home_dir) {
3557-
usprintf(&lang->cmd, "%s/scripts/%s", ejudge_config->compile_home_dir, lang->cmd);
3557+
if (!os_IsAbsolutePath(lang->cmd) && config && config->compile_home_dir) {
3558+
usprintf(&lang->cmd, "%s/scripts/%s", config->compile_home_dir, lang->cmd);
35583559
}
3559-
if (!os_IsAbsolutePath(lang->cmd) && ejudge_config && ejudge_config->contests_home_dir) {
3560-
usprintf(&lang->cmd, "%s/compile/scripts/%s", ejudge_config->contests_home_dir, lang->cmd);
3560+
if (!os_IsAbsolutePath(lang->cmd) && config && config->contests_home_dir) {
3561+
usprintf(&lang->cmd, "%s/compile/scripts/%s", config->contests_home_dir, lang->cmd);
35613562
}
35623563
#if defined EJUDGE_CONTESTS_HOME_DIR
35633564
if (!os_IsAbsolutePath(lang->cmd)) {
@@ -4501,11 +4502,11 @@ set_defaults(
45014502

45024503
if (tp->start_cmd && tp->start_cmd[0] && !os_IsAbsolutePath(tp->start_cmd)) {
45034504
snprintf(start_path, sizeof(start_path), "%s", tp->start_cmd);
4504-
if (ejudge_config && ejudge_config->compile_home_dir) {
4505-
pathmake2(start_path, ejudge_config->compile_home_dir,
4505+
if (config && config->compile_home_dir) {
4506+
pathmake2(start_path, config->compile_home_dir,
45064507
"/", "scripts", "/", start_path, NULL);
4507-
} else if (ejudge_config && ejudge_config->contests_home_dir) {
4508-
pathmake2(start_path, ejudge_config->contests_home_dir,
4508+
} else if (config && config->contests_home_dir) {
4509+
pathmake2(start_path, config->contests_home_dir,
45094510
"/", "compile", "/", "scripts", "/", start_path, NULL);
45104511
}
45114512
#if defined EJUDGE_CONTESTS_HOME_DIR
@@ -4538,8 +4539,8 @@ set_defaults(
45384539
}
45394540
if (tp->nwrun_spool_dir && tp->nwrun_spool_dir[0]) {
45404541
if (!os_IsAbsolutePath(tp->nwrun_spool_dir)) {
4541-
if (ejudge_config && ejudge_config->contests_home_dir) {
4542-
usprintf(&tp->nwrun_spool_dir, "%s/%s", ejudge_config->contests_home_dir, tp->nwrun_spool_dir);
4542+
if (config && config->contests_home_dir) {
4543+
usprintf(&tp->nwrun_spool_dir, "%s/%s", config->contests_home_dir, tp->nwrun_spool_dir);
45434544
} else {
45444545
#if defined EJUDGE_CONTESTS_HOME_DIR
45454546
usprintf(&tp->nwrun_spool_dir, "%s/%s", EJUDGE_CONTESTS_HOME_DIR, tp->nwrun_spool_dir);
@@ -4993,6 +4994,7 @@ parse_version_string(int *pmajor, int *pminor, int *ppatch, int *pbuild)
49934994

49944995
int
49954996
prepare(
4997+
const struct ejudge_cfg *config,
49964998
const struct contest_desc *cnts,
49974999
serve_state_t state,
49985000
char const *config_file,
@@ -5054,7 +5056,7 @@ prepare(
50545056
return -1;
50555057
}
50565058
*/
5057-
if (set_defaults(cnts, config_file, state, mode, subst_src, subst_dst) < 0) return -1;
5059+
if (set_defaults(config, cnts, config_file, state, mode, subst_src, subst_dst) < 0) return -1;
50585060
return 0;
50595061
}
50605062

lib/serve_state.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- mode: c -*- */
22

3-
/* Copyright (C) 2006-2022 Alexander Chernov <[email protected]> */
3+
/* Copyright (C) 2006-2023 Alexander Chernov <[email protected]> */
44

55
/*
66
* This program is free software; you can redistribute it and/or modify
@@ -716,7 +716,7 @@ serve_state_load_contest_config(
716716
state->current_time = time(0);
717717
state->load_time = state->current_time;
718718

719-
if (prepare(cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
719+
if (prepare(config, cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
720720
goto failure;
721721
if (prepare_serve_defaults(cnts, state, NULL) < 0) goto failure;
722722

@@ -799,7 +799,7 @@ serve_state_load_contest(
799799
extra->serve_state = state;
800800

801801
info("loading contest %d configuration file", contest_id);
802-
if (prepare(cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
802+
if (prepare(config, cnts, state, state->config_path, 0, PREPARE_SERVE, "", 1, 0, 0) < 0)
803803
goto failure;
804804
if (prepare_serve_defaults(cnts, state, p_cnts) < 0) goto failure;
805805
if (create_dirs(cnts, state, PREPARE_SERVE) < 0) goto failure;

0 commit comments

Comments
 (0)