]> jfr.im git - irc/thales.git/blob - src/main.c
Fixed segfault error
[irc/thales.git] / src / main.c
1 /* Main program of GNU Thales. Copyright (C)
2 2012 Free Software Foundation, Inc. This file is part of GNU Thales.
3
4 GNU Thales is free software; you can redistribute it and/or modify it under the
5 terms of the GNU General Public License as published by the Free Software
6 Foundation; either version 3 of the License, or (at your option) any later
7 version.
8
9 GNU Thales is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "cmd.h"
21 #include "conf.h"
22 #include "list.h"
23 #include "error.h"
24 #include "workers_registration.h"
25 static LIST_HEAD(workers);
26 static void
27 module_initialization_dispatcher(const char *type,
28 const char *name, const struct envz *env)
29 {
30 const struct worker_creator *cr = worker_creator_by_type(type);
31 struct worker *worker;
32
33 if (!cr)
34 fatal_error("No module of type `%s' registered", type);
35
36 worker = (*cr->creator)(env);
37 if (!worker)
38 fatal_error("Failed to initiailize modude of type %s with name %s",
39 type, name);
40
41 list_add(&worker->list, &workers);
42 }
43 int
44 main(int argc, char **argv)
45 {
46 struct cmd_options opts = {
47 .conf_filename = NULL,
48 .host = NULL,
49 .port = 0,
50 .channels = NULL
51 };
52 FILE *config_file;
53
54 parse_cmdopts(&opts, argc, argv);
55 config_file = opts.conf_filename ?
56 fopen(opts.conf_filename, "r")
57 : default_config_file();
58 if (!config_file)
59 fatal_error("failed to open config file");
60 init_worker_creators();
61 parse_config(config_file, &module_initialization_dispatcher);
62
63 return 0;
64 }