int
main(int argc, char **argv)
{
    int sock, nserver0;
    int errfd;
    pthread_t th;

    pthread_create(&th, NULL, response_to_search, NULL);
    parseArgv(argc, argv);
    if (Daemonize) {
        if (fork()) {
            exit(0);
        }
        else {
            close(2);
            errfd = open(LogFileName, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
            if (errfd < 0) {
                perror("open:");
            }
            close(0);
            close(1);
        }
    }

    initEnv();
    sock = create_daemon_socket(RC_DAEMON_IP_PORT, NBACKLOG);
    if (sock == -1) {
	WARN(0, "create_daemon_socket() failed\n");
	exit(1);
    }
    nserver0 = Nserver;
    while (1) {
        if (Nserver < RC_NSERVERMAX) {
            spawn_server(sock);

            if (nserver0 != Nserver) {
                if (Nserver < RC_NSERVERMAX) {
                    WARN(0, "%d servers active (%d max possible).\n", Nserver, RC_NSERVERMAX);
                }
                else {
                    WARN(0, "%d servers active. reached the limit.\n", Nserver);
                }
            }
        }
        sleep(1);
        nserver0 = Nserver;
    }
    WARN(0, "%s: cannot be reached.\n", __FILE__);

    pthread_join(th, NULL);
    exit(1);
}
示例#2
0
int
main(int argc, char **argv)
{
    int sock, nserver0;
    int errfd;

    parseArgv(argc, argv);
    if (Daemonize) {
        if (fork()) {
            exit(0);
        }
        else {
            close(2);
            errfd = open(LogFileName, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
            if (errfd < 0) {
                perror("open:");
            }
            close(0);
            close(1);
        }
    }

    initEnv();
    sock = create_daemon_socket(RC_DAEMON_IP_PORT, NSERVERMAX);
    if (sock == -1) {
	WARN(0, "create_daemon_socket() failed\n");
	exit(1);
    }
    nserver0 = Nserver;
    while (1) {
        if (Nserver < NSERVERMAX) {
            spawn_server(sock);
        }
        else {
            if (nserver0 != Nserver) {
                WARN(0, "already max possible clients (=%d) active.\n", Nserver);
            }
            sleep(1);
        }
        nserver0 = Nserver;
    }
    WARN(0, "%s: cannot be reached.\n", __FILE__);
    exit(1);
}