serverInit.c 1.25 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"

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);
        }
    }
}