X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=secnet.c;h=2ebcddc1ae94491bbf5ad90edb1f12e3a84049dd;hb=4d9d6e20e19c1aaa0d138e70897d136b36d673c0;hp=024744c55e5c0ecdf84d0fc67381664ded27f67c;hpb=64f5ae57aece3480ab79a93fc1b310e8b5ce22e9;p=secnet.git diff --git a/secnet.c b/secnet.c index 024744c..2ebcddc 100644 --- a/secnet.c +++ b/secnet.c @@ -1,3 +1,22 @@ +/* + * This file is part of secnet. + * See README for full list of copyright holders. + * + * secnet is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * secnet is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with secnet; if not, see + * https://www.gnu.org/licenses/gpl.html. + */ + #include "secnet.h" #include #include @@ -108,6 +127,9 @@ static void parse_options(int argc, char **argv) exit(0); break; + case 'd': + message_level|=M_DEBUG_CONFIG|M_DEBUG_PHASE|M_DEBUG; + /* fall through */ case 'v': message_level|=M_INFO|M_NOTICE|M_WARNING|M_ERR|M_SECURITY| M_FATAL; @@ -117,10 +139,6 @@ static void parse_options(int argc, char **argv) message_level&=(~M_WARNING); break; - case 'd': - message_level|=M_DEBUG_CONFIG|M_DEBUG_PHASE|M_DEBUG; - break; - case 'f': message_level=M_FATAL; break; @@ -169,11 +187,9 @@ static void parse_options(int argc, char **argv) static void setup(dict_t *config) { list_t *l; - item_t *site; dict_t *system; struct passwd *pw; struct cloc loc; - int i; l=dict_lookup(config,"system"); @@ -208,6 +224,12 @@ static void setup(dict_t *config) "that secnet retain root privileges while running.", require_root_privileges_explanation); } +} + +static void start_sites(dict_t *config) { + int i; + list_t *l; + item_t *site; /* Go along site list, starting sites */ l=dict_lookup(config,sites_key); @@ -225,7 +247,7 @@ static void setup(dict_t *config) cfgfatal(site->loc,"system","non-site closure in site list"); } s=site->data.closure->interface; - s->control(s->st,True); + s->startup(s->st); } } } @@ -235,7 +257,7 @@ struct poll_interest *register_for_poll(void *st, beforepoll_fn *before, { struct poll_interest *i; - i=safe_malloc(sizeof(*i),"register_for_poll"); + NEW(i); i->before=before; i->after=after; i->state=st; @@ -307,8 +329,6 @@ static void run(void) struct pollfd *fds=0; int allocdfds=0, shortfall=0; - Message(M_NOTICE,"%s [%d]: starting\n",version,secnet_pid); - do { if (gettimeofday(&tv_now_global, NULL)!=0) { fatal_perror("main loop: gettimeofday"); @@ -331,7 +351,7 @@ static void run(void) if (shortfall) { allocdfds *= 2; allocdfds += shortfall; - fds=safe_realloc_ary(fds,sizeof(*fds),allocdfds, "run"); + REALLOC_ARY(fds,allocdfds); } shortfall=0; idx=0; @@ -475,6 +495,9 @@ int main(int argc, char **argv) { dict_t *config; + log_early_init(); + phase_hooks_init(); + enter_phase(PHASE_GETOPTS); parse_options(argc,argv); @@ -483,6 +506,7 @@ int main(int argc, char **argv) enter_phase(PHASE_SETUP); setup(config); + start_sites(config); if (just_check_config) { Message(M_INFO,"configuration file check complete\n"); @@ -491,6 +515,7 @@ int main(int argc, char **argv) enter_phase(PHASE_DAEMONIZE); become_daemon(); + Message(M_NOTICE,"%s [%d]: starting\n",version,secnet_pid); enter_phase(PHASE_GETRESOURCES); /* Appropriate phase hooks will have been run */