Subversion Repositories Mokou

Rev

Rev 5 | 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-09-07 08:42:09Z nishi $ */
1
/* $Id: main.c 7 2024-09-07 09:14:35Z nishi $ */
2
 
2
 
3
#include <stdio.h>
3
#include <stdio.h>
4
#include <unistd.h>
4
#include <unistd.h>
5
#include <stdlib.h>
5
#include <stdlib.h>
6
#include <string.h>
6
#include <string.h>
7
#include <stdbool.h>
7
#include <stdbool.h>
8
 
8
 
9
#include "mk_service.h"
9
#include "mk_service.h"
-
 
10
#include "mk_server.h"
10
#include "mk_log.h"
11
#include "mk_log.h"
11
#include "mk_util.h"
12
#include "mk_util.h"
12
#include "mk_version.h"
13
#include "mk_version.h"
13
 
14
 
14
extern bool mk_syslog;
15
extern bool mk_syslog;
15
 
16
 
16
int main(int argc, char** argv){
17
int main(int argc, char** argv){
17
	int i;
18
	int i;
-
 
19
	bool daemon = true;
18
	for(i = 1; i < argc; i++){
20
	for(i = 1; i < argc; i++){
19
		if(argv[i][0] == '-'){
21
		if(argv[i][0] == '-'){
20
			if(strcmp(argv[i], "--stderr") == 0 || strcmp(argv[i], "-S") == 0){
22
			if(strcmp(argv[i], "--stderr") == 0 || strcmp(argv[i], "-S") == 0){
21
				mk_syslog = false;
23
				mk_syslog = false;
-
 
24
			}else if(strcmp(argv[i], "-D") == 0){
-
 
25
				daemon = false;
22
			}else{
26
			}else{
23
				fprintf(stderr, "%s: %s: unknown flag\n", argv[0], argv[i]);
27
				fprintf(stderr, "%s: %s: unknown flag\n", argv[0], argv[i]);
24
				return 1;
28
				return 1;
25
			}
29
			}
26
		}
30
		}
Line 33... Line 37...
33
	mk_log(log);
37
	mk_log(log);
34
	free(log);
38
	free(log);
35
	mk_service_scan();
39
	mk_service_scan();
36
	mk_start_services();
40
	mk_start_services();
37
	mk_log("Mokou is up, creating the server socket");
41
	mk_log("Mokou is up, creating the server socket");
-
 
42
	if(mk_server_init() != 0){
-
 
43
		mk_log("Could not initialize the server");
-
 
44
		return 1;
-
 
45
	}
-
 
46
	unsigned long long pid = 0;
-
 
47
	if(daemon){
-
 
48
		mk_log("Spawning daemon");
-
 
49
		pid = fork();
-
 
50
	}
-
 
51
	if(pid == 0){
-
 
52
		if(daemon){
-
 
53
			mk_log("Hello from daemon");
-
 
54
		}
-
 
55
		mk_log("Entering server loop");
-
 
56
		mk_server_loop();
-
 
57
		return 0;
-
 
58
	}else if(daemon){
-
 
59
		FILE* f = fopen("/var/run/mokou.pid", "w");
-
 
60
		fprintf(f, "%llu", pid);
-
 
61
		fclose(f);
-
 
62
	}
38
}
63
}