serverInit.c
1.25 KB
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
#include <sys/select.h> /* for select system call and related */
#include <string.h> /* for memset and stuff */
#include <stdlib.h> /* for getopt */
#include "include/server.h"
#include "include/socket.h"
#include "include/monitor.h"
void
serverInit(
tVirtualItemServer * server,
unsigned int port,
unsigned int pending,
const char * logPath,
const char * namePat)
{
FD_ZERO(&(server->socks));
server->servSock = initServerSocket(port, pending);
server->maxFd = server->servSock;
FD_SET(server->servSock, &(server->socks));
strncpy(server->logPath, logPath, sizeof(server->logPath)-1);
strncpy(server->namePat, namePat, sizeof(server->namePat)-1);
memset(server->clients, 0, sizeof(server->clients));
/*
* try to open file (firstrun)
*/
if (NULL == server->wHandle) {
logRotate(server);
if (NULL == server->wHandle) {
syslogMonitor(LOG_ERR, MON_CRITICAL, "logfile.rotate",
"no valid handle for logfile");
syslogMonitor(LOG_ERR, MON_FAILURE, "logfile.rotate",
"no valid handle for logfile - service terminated");
exit(EXIT_FAILURE);
}
}
}