blob: 20c96ff91c2ec5b9dbd9e992778a3ad12dd5b593 (
plain)
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
|
#include "music.h"
#include "httpd.h"
#include "command_service.h"
#include "conf.h"
#include "servers.h"
#include "control_service.h"
#include "options.h"
#include "daemon.h"
#include <glib.h>
#include <glib-object.h>
#include <signal.h>
GMainLoop *main_loop;
struct options options = {0};
static void sig_handler(int sig) {
g_debug("caught signal %d", sig);
g_main_loop_quit(main_loop);
}
int main(int argc, char **argv) {
g_type_init();
conf_load();
options_parse(argc, argv, &options);
if(options.kill == TRUE) {
daemon_kill();
return 0;
}
if(options.daemonize == TRUE) {
daemonize();
}
control_service_start();
servers_init();
music_init();
music_scan_root();
server_start();
httpd_start();
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(main_loop);
g_main_loop_unref(main_loop);
httpd_stop();
server_stop();
music_free();
servers_free();
control_service_stop();
if(options.daemonize == TRUE) {
daemonize_finished();
}
conf_free();
return 0;
}
|