Subversion Repositories IRCServ

Rev

Rev 5 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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