X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=submit%2Fsubmitd.c;h=e8578f601437ee06ca87ddea4506b77c56d6be00;hb=6324cb417d421274a384cfae916b039cbe56d6e0;hp=211cc1b12a4b5ba104dbd2531e61b1c933112efc;hpb=bdd61c84b621a5b53a78c7401094720ac1529126;p=moe.git diff --git a/submit/submitd.c b/submit/submitd.c index 211cc1b..e8578f6 100644 --- a/submit/submitd.c +++ b/submit/submitd.c @@ -4,11 +4,6 @@ * (c) 2007 Martin Mares */ -/* - * FIXME: - * - competition timeout & per-contestant exceptions - */ - #undef LOCAL_DEBUG #include "lib/lib.h" @@ -30,6 +25,7 @@ /*** CONFIGURATION ***/ +static byte *log_name; static uns port = 8888; static uns dh_bits = 1024; static uns max_conn = 10; @@ -54,16 +50,9 @@ static struct cf_section access_conf = { } }; -static byte * -config_init(void) -{ - clist_init(&access_rules); - return NULL; -} - static struct cf_section submitd_conf = { - CF_INIT(config_init), CF_ITEMS { + CF_STRING("LogFile", &log_name), CF_UNS("Port", &port), CF_UNS("DHBits", &dh_bits), CF_UNS("MaxConn", &max_conn), @@ -214,7 +203,7 @@ tls_verify_cert(struct conn *c) if (err < 0) return "Cannot retrieve common name"; if (trace_tls) - log(L_INFO, "Cert CN: %s", dn); + msg(L_INFO, "Cert CN: %s", dn); c->cert_name = xstrdup(dn); /* Check certificate purpose */ @@ -247,7 +236,7 @@ tls_log_params(struct conn *c) const char *comp = gnutls_compression_get_name(gnutls_compression_get(s)); const char *cipher = gnutls_cipher_get_name(gnutls_cipher_get(s)); const char *mac = gnutls_mac_get_name(gnutls_mac_get(s)); - log(L_DEBUG, "TLS params: proto=%s kx=%s cert=%s comp=%s cipher=%s mac=%s", + msg(L_DEBUG, "TLS params: proto=%s kx=%s cert=%s comp=%s cipher=%s mac=%s", proto, kx, cert, comp, cipher, mac); } @@ -258,7 +247,7 @@ client_error(char *msg, ...) { va_list args; va_start(args, msg); - vlog_msg(L_ERROR_R, msg, args); + vmsg(L_ERROR_R, msg, args); exit(0); } @@ -388,7 +377,7 @@ client_loop(struct conn *c) alarm(session_timeout); if (!process_init(c)) - log(L_ERROR, "Protocol handshake failed"); + msg(L_ERROR, "Protocol handshake failed"); else { setproctitle("submitd: client %s (%s)", c->ip_string, c->user); @@ -418,18 +407,18 @@ sigchld_handler(int sig UNUSED) static void reap_child(pid_t pid, int status) { - byte msg[EXIT_STATUS_MSG_SIZE]; - if (format_exit_status(msg, status)) - log(L_ERROR, "Child %d %s", (int)pid, msg); + byte buf[EXIT_STATUS_MSG_SIZE]; + if (format_exit_status(buf, status)) + msg(L_ERROR, "Child %d %s", (int)pid, buf); CLIST_FOR_EACH(struct conn *, c, connections) if (c->pid == pid) { - log(L_INFO, "Connection %d closed", c->id); + msg(L_INFO, "Connection %d closed", c->id); conn_free(c); return; } - log(L_ERROR, "Cannot find connection for child process %d", (int)pid); + msg(L_ERROR, "Cannot find connection for child process %d", (int)pid); } static int listen_sk; @@ -494,7 +483,7 @@ sk_accept(void) } struct conn *c = conn_new(); - log(L_INFO, "Connection from %s:%d (id %d, %s, %s)", + msg(L_INFO, "Connection from %s:%d (id %d, %s, %s)", ipbuf, port, c->id, (rule->plain_text ? "plain-text" : "TLS"), (rule->allow_admin ? "admin" : "user")); @@ -508,7 +497,7 @@ sk_accept(void) { conn_free(c); err = "Server overloaded"; - log(L_ERROR, "Fork failed: %m"); + msg(L_ERROR, "Fork failed: %m"); goto reject2; } if (!c->pid) @@ -521,12 +510,12 @@ sk_accept(void) return; reject: - log(L_ERROR_R, "Connection from %s:%d rejected (%s)", ipbuf, port, err); + msg(L_ERROR_R, "Connection from %s:%d rejected (%s)", ipbuf, port, err); reject2: ; // Write an error message to the socket, but do not allow it to slow us down struct linger ling = { .l_onoff=0 }; if (setsockopt(sk, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)) < 0) - log(L_ERROR, "Cannot set SO_LINGER: %m"); + msg(L_ERROR, "Cannot set SO_LINGER: %m"); write(sk, "-", 1); write(sk, err, strlen(err)); write(sk, "\n", 1); @@ -536,19 +525,22 @@ reject2: ; int main(int argc, char **argv) { setproctitle_init(argc, argv); - cf_def_file = "config"; + cf_def_file = "submit/config"; cf_declare_section("SubmitD", &submitd_conf, 0); + cf_declare_section("Tasks", &tasks_conf, 0); int opt; if ((opt = cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL)) >= 0) die("This program has no options"); - log(L_INFO, "Initializing TLS"); + log_file(log_name); + + msg(L_INFO, "Initializing TLS"); tls_init(); conn_init(); sk_init(); - log(L_INFO, "Listening on port %d", port); + msg(L_INFO, "Listening on port %d", port); struct sigaction sa = { .sa_handler = sigchld_handler