...
|
...
|
@@ -52,6 +52,7 @@ main(int argc, char *argv[])
|
52
|
52
|
{
|
53
|
53
|
int port;
|
54
|
54
|
int timeout=500;
|
|
55
|
+ int serverfd;
|
55
|
56
|
kakumei *ka,kastore;
|
56
|
57
|
memset(&kastore,0,sizeof(kastore));
|
57
|
58
|
ka=&kastore;
|
...
|
...
|
@@ -61,21 +62,27 @@ main(int argc, char *argv[])
|
61
|
62
|
}
|
62
|
63
|
port=atoi(argv[1]);
|
63
|
64
|
if(kaconfig_exists(CONFIGFILE)!=0) {
|
64
|
|
- log_setlogfile(CFLOGFILE);
|
|
65
|
+ log_setlogfile(CFLOGFILE);
|
65
|
66
|
log_write("INIT","Config file not found, writing default file %s",CONFIGFILE);
|
66
|
67
|
kaconfig_write(CONFIGFILE,CFLOGFILE,CFCOOKIENAME,CFCOOKIEDOMAIN,CFBANNERPATH,CFSSLPROXY);
|
67
|
68
|
}
|
68
|
69
|
if((ka->config=kaconfig_init(CONFIGFILE))==NULL) {
|
69
|
|
- log_setlogfile(CFLOGFILE);
|
|
70
|
+ log_setlogfile(CFLOGFILE);
|
70
|
71
|
log_write("INIT","ERROR: insufficient memory or config file error");
|
71
|
72
|
return(1);
|
72
|
73
|
}
|
73
|
|
- log_setlogfile((ka->config->logfile!=NULL)?ka->config->logfile:CFLOGFILE);
|
|
74
|
+ log_setlogfile((ka->config->logfile!=NULL)?ka->config->logfile:CFLOGFILE);
|
74
|
75
|
if((ka->ssel=sselect_init())==NULL) {
|
75
|
76
|
log_write("INIT","ERROR: insufficient memory");
|
76
|
77
|
return(1);
|
77
|
78
|
}
|
78
|
|
- if((ka->web=wk_init(port,ka->ssel,NULL,callback_http,NULL,NULL,ka))==NULL) {
|
|
79
|
+ if((serverfd=ipv4_server(port))==-1) {
|
|
80
|
+ sselect_free(ka->ssel),ka->ssel=NULL;
|
|
81
|
+ log_write("INIT","ERROR: couldn't listen on port");
|
|
82
|
+ return(2);
|
|
83
|
+ }
|
|
84
|
+ sock_setunsafe(serverfd);
|
|
85
|
+ if((ka->web=wk_init(serverfd,ka->ssel,NULL,callback_http,NULL,NULL,ka))==NULL) {
|
79
|
86
|
sselect_free(ka->ssel),ka->ssel=NULL;
|
80
|
87
|
log_write("INIT","ERROR: couldn't init web server");
|
81
|
88
|
return(2);
|
...
|
...
|
@@ -88,6 +95,7 @@ main(int argc, char *argv[])
|
88
|
95
|
wk_service(ka->web);
|
89
|
96
|
}
|
90
|
97
|
wk_free(ka->web),ka->web=NULL;
|
|
98
|
+ close(serverfd),serverfd=-1;
|
91
|
99
|
sselect_free(ka->ssel),ka->ssel=NULL;
|
92
|
100
|
kaconfig_free(ka->config),ka->config=NULL;
|
93
|
101
|
log_write("FINI","SIGINT detected, exiting...");
|