-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
main.c
110 lines (86 loc) · 2.65 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* main.c - SiriDB.
*
* author/maintainer : Jeroen van der Heijden <[email protected]>
* contributors : https://github.com/SiriDB/siridb-server/contributors
* home page : https://siridb.net
* copyright : 2022, Cesbit
*
*/
#include <locale.h>
#include <logger/logger.h>
#include <siri/args/args.h>
#include <siri/db/presuf.h>
#include <siri/err.h>
#include <siri/help/help.h>
#include <siri/siri.h>
#include <siri/version.h>
#include <siri/evars.h>
#include <siri/net/tcp.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
int main(int argc, char * argv[])
{
int seed, fd;
/* set local to LC_ALL and C to force a period over comma for float */
(void) setlocale(LC_ALL, "C");
/* set threadpool size to 8 (default=4) */
putenv("UV_THREADPOOL_SIZE=8");
/* set default timezone to UTC */
putenv("TZ=:UTC");
tzset();
/* parse arguments first since this can exit the program */
siri_args_parse(&siri, argc, argv);
/* setup logger, this must be done before logging the first line */
siri_setup_logger();
/* initialize random */
seed = 0;
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1 || read(fd, &seed, sizeof(int)) == -1)
{
log_error("Could not open /dev/urandom");
return 1;
}
(void) close(fd);
srand(seed);
/* initialize points dictionary */
siridb_points_init();
/* start server */
log_info("Starting SiriDB Server (version: %s)", SIRIDB_VERSION);
/* initialize SiriDB mutex (used for the siridb_list) */
if (uv_mutex_init(&siri.siridb_mutex))
{
exit(1);
}
/* read siridb main application configuration */
siri_cfg_init(&siri);
siri_evars_parse(&siri);
if (make_database_directory())
{
exit(1);
}
set_max_open_files_limit();
log_debug("Shard compression: %s", siri.cfg->shard_compression ? "enabled" : "disabled");
log_debug("Shard auto duration: %s", siri.cfg->shard_auto_duration ? "enabled" : "disabled");
log_debug("Pipe support: %s", siri.cfg->pipe_support ? "enabled" : "disabled");
log_debug("IP support: %s", sirinet_tcp_ip_support_str(siri.cfg->ip_support));
/* start SiriDB. (this start the event loop etc.) */
if (siri_start() && !siri_err)
{
siri_err = ERR_STARTUP;
}
/* free siridb */
siri_free();
/* destroy SiriDB mutex */
uv_mutex_destroy(&siri.siridb_mutex);
/* cleanup prefix-suffix allocation */
siridb_presuf_cleanup();
/* cleanup help */
siri_help_free();
log_info("Bye! (%d)\n", siri_err);
return siri_err;
}