serverInit.c 1.19 KB
#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"
#include "../include/logRotate.h"

void
serverInit(
        tServer      * 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->wHandle), server->logPath, server->namePat);
        if (NULL == server->wHandle) {
            syslogMonitor(LOG_ERR, MON_INFO, "logfile.rotate",
                    "no valid handle for logfile - service terminated");
            exit(EXIT_FAILURE);
        }
    }
}