Subversion Repositories IRCServ

Rev

Rev 8 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 nishi 1
/* $Id: main.c 10 2024-08-26 13:37:23Z nishi $ */
2
 
3
#include "is_version.h"
5 nishi 4
#include "is_util.h"
5
#include "is_log.h"
7 nishi 6
#include "is_socket.h"
7
#include "is_ircd.h"
10 nishi 8
#include "is_db.h"
2 nishi 9
 
7 nishi 10
#include "../config.h"
11
 
12
#ifdef USE_NICKSERV
13
#include "is_nickserv.h"
14
#endif
15
 
16
#ifdef USE_CHANSERV
17
#include "is_chanserv.h"
18
#endif
19
 
20
#ifdef USE_MEMOSERV
21
#include "is_memoserv.h"
22
#endif
23
 
24
#ifdef USE_OPERSERV
25
#include "is_operserv.h"
26
#endif
27
 
3 nishi 28
#include <stdio.h>
5 nishi 29
#include <stdlib.h>
30
#include <unistd.h>
31
#include <stdbool.h>
32
#include <string.h>
3 nishi 33
 
7 nishi 34
struct is_config config;
35
 
3 nishi 36
int main(int argc, char** argv) {
5 nishi 37
	bool daemon = true;
38
	int i;
39
	for(i = 1; i < argc; i++) {
40
		if(strcmp(argv[i], "-D") == 0) {
41
			daemon = false;
42
			break;
43
		}
44
	}
7 nishi 45
 
46
	char* str;
47
	int st;
48
 
49
	str = is_strcat("IRCServ version ", is_get_version());
50
	is_log(str);
51
	free(str);
52
 
10 nishi 53
	is_log("Initialing the database");
54
	st = is_db_init();
55
	if(st != 0) goto cleanup;
56
 
7 nishi 57
	is_log("Initializing the socket");
58
	st = is_socket_init();
59
	if(st != 0) goto cleanup;
60
 
61
	is_log("Initializing the connection");
62
	st = is_ircd_connect();
63
	if(st != 0) goto cleanup;
64
 
65
#ifdef USE_NICKSERV
8 nishi 66
	is_log("Initializing NickServ");
7 nishi 67
	st = is_nickserv_init();
68
	if(st != 0) goto cleanup;
69
#endif
70
#ifdef USE_CHANSERV
8 nishi 71
	is_log("Initializing ChanServ");
7 nishi 72
	st = is_chanserv_init();
73
	if(st != 0) goto cleanup;
74
#endif
75
#ifdef USE_MEMOSERV
8 nishi 76
	is_log("Initializing MemoServ");
7 nishi 77
	st = is_memoserv_init();
78
	if(st != 0) goto cleanup;
79
#endif
80
#ifdef USE_OPERSERV
8 nishi 81
	is_log("Initializing OperServ");
7 nishi 82
	st = is_operserv_init();
83
	if(st != 0) goto cleanup;
84
#endif
85
 
5 nishi 86
	pid_t pid = 0;
87
	if(daemon) {
88
		pid = fork();
89
	}
90
	if(pid == 0) {
7 nishi 91
		/* Main */
92
		is_log("Initialization successful, hello from daemon");
5 nishi 93
 
7 nishi 94
		is_socket_close();
5 nishi 95
		return 0;
96
	} else {
97
		return 0;
98
	}
7 nishi 99
cleanup:
100
	fprintf(stderr, "IRCServ exiting with error, check the log.\n");
101
	return st;
3 nishi 102
}