Example #1
0
void *reader(void *prm)
{
	char *entry;
	int num = (int) prm;
	int total = 0;
	int rc;

	cp_mutex_lock(&start_mutex);
	while (!running)
		cp_cond_wait(&start_cond, &start_mutex);
	rc = cp_mutex_unlock(&start_mutex);
	if (rc == 0) write_err("reader");
	while (running || cp_hashtable_count(t[num]) > 0)
	{
		cp_mutex_lock(&lock[num]);
		while (running && cp_list_is_empty(tl[num]))
			cp_cond_wait(&cond[num], &lock[num]);

		while ((entry = (char *) cp_list_remove_head(tl[num])))
		{
			cp_hashtable_remove(t[num], entry);
			if (!silent)
				printf("[%d]: (%ld) entry: %s\n", num, cp_hashtable_count(t[num]), entry);
			total++;
			free(entry);
		}
		cp_mutex_unlock(&lock[num]);
	}

	printf("\n (-) reader %d: processed %d entries\n", num, total);
	return NULL;
}
Example #2
0
char* get_quotation(char* line,  char * instruction) {

	if (line == NULL)
	{
		return NULL;
	}

	int quotation_counter = 0;
	for (int i = 0; i < line[i] != '\0'; ++i){
		if (line[i] == '"'){quotation_counter++;}
	}

	if (quotation_counter == 0) {
		return line;
	}else if(quotation_counter == 2){
		char * token;
		token = strtok (line, "\"");

		int i = 0;
		for (; instruction[i] != '\0'; ++i){}
		instruction[i] = ' '; i++;
		instruction[i] = '"';

		int j = 0;
		for (; token[j] != '\0'; ++j) {
				instruction[i + j + 1] = token[j];
		}
		instruction[i + j + 1] = '"';instruction[i + j + 2] = '\0';

		return NULL;
	}else{
		write_err("ERROR: problem with quotation\n");
		exit(1);	
	}
}
Example #3
0
void usage(const char* msg)
{
  if(msg)
    error(msg);
  write_err("Usage: sysloguread [-g GID] [-u UID] [-U] IP PORT ...\n");
  exit(1);
}
Example #4
0
void usage(const char* msg)
{
    if(msg)
        error(msg);
    write_err("Usage: sysloglread [-g GID] [-u UID] [-U] [-m MASK] PATH ...\n");
    exit(1);
}
Example #5
0
/* The signal handler, called on every SIGXCPU */
static void signal_handler(int sig) {
    int saved_errno;

    saved_errno = errno;
    pa_assert(sig == SIGXCPU);

    if (phase == PHASE_IDLE) {
        pa_usec_t now, elapsed;

#ifdef PRINT_CPU_LOAD
        char t[256];
#endif

        now = pa_rtclock_now();
        elapsed = now - last_time;

#ifdef PRINT_CPU_LOAD
        pa_snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", ((double) CPUTIME_INTERVAL_SOFT * (double) PA_USEC_PER_SEC) / (double) elapsed * 100.0);
        write_err(t);
#endif

        if (((double) CPUTIME_INTERVAL_SOFT * (double) PA_USEC_PER_SEC) >= ((double) elapsed * (double) CPUTIME_PERCENT / 100.0)) {
            static const char c = 'X';

            write_err("Soft CPU time limit exhausted, terminating.\n");

            /* Try a soft cleanup */
            (void) write(the_pipe[1], &c, sizeof(c));
            phase = PHASE_SOFT;
            reset_cpu_time(CPUTIME_INTERVAL_HARD);

        } else {

            /* Everything's fine */
            reset_cpu_time(CPUTIME_INTERVAL_SOFT);
            last_time = now;
        }

    } else if (phase == PHASE_SOFT) {
        write_err("Hard CPU time limit exhausted, terminating forcibly.\n");
        abort(); /* Forced exit */
    }

    errno = saved_errno;
}
Example #6
0
void fork_proc (node_type *cur, int pfd) {
	 pid_t par=getpid();
	 size_t i=0;
	 pid_t ch[2];
	 int p[2][2];
	 int result=0, res[2]={0, 0};
	 int rwn=0, rwrv=0;
	if (!cur->nr_children) {					//If no children: atoi arg.
		result=atoi(cur->name);
	} else if (cur->nr_children==2) {			//Child with 2 children: Open pipes, fork children, and wait to read.
		for (i=0; i<cur->nr_children; i++) {		//For the 2 children, open pipes, and fork giving them the write end.
			if (pipe(p[i])) {							//Open pipe.
				pipe_error(par);
				shit_n_exit;//exit(EXIT_FAILURE);
			}
			ch[i]=fork();								//Fork.
			if (ch[i]<0) {
				fork_error(par);
				shit_n_exit;//exit(EXIT_FAILURE);
			} else if (ch[i]==0) {
				ccret(close(p[i][0]));
				fork_proc(&cur->children[i], p[i][1]);
			} else {
				ccret(close(p[i][1]));
			}
		}
		for (i=0; i<cur->nr_children; i++) {		//Read from the 2 child streams (and bury them in the process).
			rwn=rwrv=0;
			while (rwn<sizeof(int)) {
				if ((rwrv=read(p[i][0], &res[i]+rwn, sizeof(int)-rwn))==-1) {
					read_err(par);
					shit_n_exit;//exit(EXIT_FAILURE);
				}
				rwn+=rwrv;
			}
			ccret(close(p[i][0]));
			wait(NULL);
		}
		_Bool err=0;
		result = (cur->name[0]=='+') ? res[0]+res[1] : ((cur->name[0]=='*') ? res[0]*res[1] : ((cur->name[0]=='-') ? res[0]-res[1] : (err=1)));
		if (err && op_err(par, cur->name[0]) && shit_n_exit) ;
	} else {									//Child with illegal number of children:
		fprintf(stderr, "Illegal operand number ( %u ) in process: %ld.\n", cur->nr_children, (long)par);
		shit_n_exit;//exit(EXIT_FAILURE);
	}
	rwn=sizeof(int);
	printf("Writing data (%d) to pipe from process %ld.\n", result, (long)par);
	while (rwn!=0) {
		if ((rwrv=write(pfd, &result+sizeof(int)-rwn, (sizeof(int)<<1)-rwn))==-1) {
			write_err(par);
			shit_n_exit;//exit(EXIT_FAILURE);
		}
		rwn-=rwrv;
	}
	ccret(close(pfd));
	exit(EXIT_SUCCESS);
}
Example #7
0
char* get_line_before_semicol(char* line, int * check_mark) {

	int quotation_counter = 0;
	for (int i = 0; i < line[i] != '\0'; ++i){
		if (line[i] == '"'){quotation_counter++;}
	}

	if (quotation_counter != 0 && quotation_counter != 2) {
		* check_mark = 1;
		write_err("Unclosed string.\n");
		return NULL;
	}

	int i = 0;
	int quoter = 0;
	bool is_empty = true;
	for (; line[i] != '\0'; ++i)
	{

		if (line[i] != ' ' && line[i] != '\n' && line[i] != ';')
		{
			is_empty = false;
		}else if (line[i] == '\n')
		{
			line[i] = ' ';
		}

		if (line[i] == ';' && (quoter == 0 || quoter == 2))
		{
			line[i] = '\0';
			break;
		}

		if (line[i] == '"')
		{
			quoter++;
		}
	}


	if (is_empty)
	{
		return NULL;
	}else{
		return line;
	}
}
Example #8
0
File: dns.c Project: nrhtr/genesis
/* out must be a DNS_MAXLEN character buffer */
int lookup_ip_by_name(char *name, char *out)
{
    register struct hostent *hp;
    char *p;

    if (!(hp = gethostbyname(name)))
        return DNS_NORESOLV;

    p = inet_ntoa(*(struct in_addr *) hp->h_addr);
    strncpy(out, p, DNS_MAXLEN);
    if (strlen(p) > DNS_MAXLEN) {
        write_err("Hostname longer than DNS_MAXLEN?!?: '%s'\n", hp->h_name);
        out[DNS_MAXLEN] = '\0';
        return DNS_OVERFLOW;
    }
    return DNS_NOERROR;
}
Example #9
0
char* get_label_instruction(char* line,  char * label) {

	if (line == NULL)
	{
		return NULL;
	}

	int colon_counter = 0;
	for (int i = 0; i < line[i] != '\0'; ++i){
		if (line[i] == ':'){colon_counter++;}
	}

	if (colon_counter == 0)
	{
		return line;
	}else if(colon_counter == 1){
		char * token;
		token = strtok (line, " :");

		int i = 0;
		for (; i < 8; ++i) {
			if(token[i] != '\0'){
				label[i] = token[i];
			}else{
				break;
			}
		}
		label[i] = ':'; i++;
		for (; i < 9; ++i) {
			label[i] = ' ';
		}

		label[9] = '\0';

		token = strtok (NULL,"");
		return token;
	}else{
		write_err("Double label.\n");
		exit(1);	
	}
}
Example #10
0
File: dns.c Project: nrhtr/genesis
/* out must be a DNS_MAXLEN character buffer */
int lookup_name_by_ip(char *ip, char *out)
{
    unsigned addr;
    register struct hostent *hp;

    addr = inet_addr(ip);
    if (addr == INVALID_INADDR)
        return DNS_INVADDR;

    if (!(hp = gethostbyaddr((char *) &addr, 4, AF_INET)))
        return DNS_NORESOLV;

    /* we have a problem houston */
    strncpy(out, hp->h_name, DNS_MAXLEN);
    if (strlen(hp->h_name) > DNS_MAXLEN) {
        write_err("Hostname longer than DNS_MAXLEN?!?: '%s'\n", hp->h_name);
        out[DNS_MAXLEN] = '\0';
        return DNS_OVERFLOW;
    }
    return DNS_NOERROR;
}
Example #11
0
/* Save materials (0=lib, 1=current) to file */
int
save_mli(char *fname,int type)
	{
	FILE *stream;
	int error;
	
	libtype=type;
	
	if((stream=GOpen(fname,"wb"))==NULL)
		{
		cant_create();
		return(0);
		}
	
	error=0;
	
	if(dump_mtlchunk(MLIBMAGIC,stream,NULL)==0)
		error=1;
	
	if(GClose(stream))
		error=1;
	
	if(error) {
		write_err();
		remove(fname);
		}
	
	if(debug)
		{
		getchar();
		redraw(0,0,320,200);
		}
	
	if(error)
		return(0);
	return(1);
	}
Example #12
0
int main(int argc, char **argv)
{
	FILE		*fp;
	struct timeval	tv;
	fd_set		fds;
	char		buf[1024];
	char		realcons[1024];
	char		*p;
	char		*logfile;
	char		*pidfile;
	int		rotate;
	int		dontfork;
	int		ptm, pts;
	int		realfd;
	int		n, m, i;
	int		todo;

	fp = NULL;
	logfile = LOGFILE;
	pidfile = NULL;
	rotate = 0;
	dontfork = 0;

	while ((i = getopt(argc, argv, "cdsl:p:rv")) != EOF) switch(i) {
		case 'l':
			logfile = optarg;
			break;
		case 'r':
			rotate = 1;
			break;
		case 'v':
			printf("%s\n", Version);
			exit(0);
			break;
		case 'p':
			pidfile = optarg;
			break;
		case 'c':
			createlogfile = 1;
			break;
		case 'd':
			dontfork = 1;
			break;
		case 's':
			syncalot = 1;
			break;
		default:
			usage();
			break;
	}
	if (optind < argc) usage();

	signal(SIGTERM, handler);
	signal(SIGQUIT, handler);
	signal(SIGINT,  handler);
	signal(SIGTTIN,  SIG_IGN);
	signal(SIGTTOU,  SIG_IGN);
	signal(SIGTSTP,  SIG_IGN);

	/*
	 *	Open console device directly.
	 */
	if (consolename(realcons, sizeof(realcons)) < 0)
		return 1;

	if (strcmp(realcons, "/dev/tty0") == 0)
		strcpy(realcons, "/dev/tty1");
	if (strcmp(realcons, "/dev/vc/0") == 0)
		strcpy(realcons, "/dev/vc/1");

	if ((realfd = open_nb(realcons)) < 0) {
		fprintf(stderr, "bootlogd: %s: %s\n", buf, strerror(errno));
		return 1;
	}

	/*
	 *	Grab a pty, and redirect console messages to it.
	 */
	ptm = -1;
	pts = -1;
	buf[0] = 0;
	if (findpty(&ptm, &pts, buf) < 0) {
		fprintf(stderr,
			"bootlogd: cannot allocate pseudo tty: %s\n",
			strerror(errno));
		return 1;
	}

	(void)ioctl(0, TIOCCONS, NULL);
#if 1
	/* Work around bug in 2.1/2.2 kernels. Fixed in 2.2.13 and 2.3.18 */
	if ((n = open("/dev/tty0", O_RDWR)) >= 0) {
		(void)ioctl(n, TIOCCONS, NULL);
		close(n);
	}
#endif
	if (ioctl(pts, TIOCCONS, NULL) < 0) {
		fprintf(stderr, "bootlogd: ioctl(%s, TIOCCONS): %s\n",
			buf, strerror(errno));
		return 1;
	}

	/*
	 *	Fork and write pidfile if needed.
	 */
	if (!dontfork) {
		pid_t child_pid = fork();
		switch (child_pid) {
		case -1: /* I am parent and the attempt to create a child failed */
			fprintf(stderr, "bootlogd: fork failed: %s\n",
				strerror(errno));
			exit(1);
			break;
		case 0: /* I am the child */
			break;
		default: /* I am parent and got child's pid */
			exit(0);
			break;
		}
		setsid();
	}
	if (pidfile) {
		unlink(pidfile);
		if ((fp = fopen(pidfile, "w")) != NULL) {
			fprintf(fp, "%d\n", (int)getpid());
			fclose(fp);
		}
		fp = NULL;
	}

	/*
	 *	Read the console messages from the pty, and write
	 *	to the real console and the logfile.
	 */
	while (!got_signal) {

		/*
		 *	We timeout after 5 seconds if we still need to
		 *	open the logfile. There might be buffered messages
		 *	we want to write.
		 */
		tv.tv_sec = 0;
		tv.tv_usec = 500000;
		FD_ZERO(&fds);
		FD_SET(ptm, &fds);
		if (select(ptm + 1, &fds, NULL, NULL, &tv) == 1) {
			/*
			 *	See how much space there is left, read.
			 */
			if ((n = read(ptm, inptr, endptr - inptr)) >= 0) {
				/*
				 *	Write data (in chunks if needed)
				 *	to the real output device.
				 */
				m = n;
				p = inptr;
				while (m > 0) {
					i = write(realfd, p, m);
					if (i >= 0) {
						m -= i;
						p += i;
						continue;
					}
					/*
					 *	Handle EIO (somebody hung
					 *	up our filedescriptor)
					 */
					realfd = write_err(pts, realfd,
						realcons, errno);
					if (realfd >= 0) continue;
					got_signal = 1; /* Not really */
					break;
				}

				/*
				 *	Increment buffer position. Handle
				 *	wraps, and also drag output pointer
				 *	along if we cross it.
				 */
				inptr += n;
				if (inptr - n < outptr && inptr > outptr)
					outptr = inptr;
				if (inptr >= endptr)
					inptr = ringbuf;
				if (outptr >= endptr)
					outptr = ringbuf;
			}
		}

		/*
		 *	Perhaps we need to open the logfile.
		 */
		if (fp == NULL && access(logfile, F_OK) == 0) {
			if (rotate) {
				snprintf(buf, sizeof(buf), "%s~", logfile);
				rename(logfile, buf);
			}
			fp = fopen(logfile, "a");
		}
		if (fp == NULL && createlogfile)
			fp = fopen(logfile, "a");

		if (inptr >= outptr)
			todo = inptr - outptr;
		else
			todo = endptr - outptr;
		if (fp && todo)
			writelog(fp, (unsigned char *)outptr, todo);
	}

	if (fp) {
		if (!didnl) fputc('\n', fp);
		fclose(fp);
	}

	close(pts);
	close(ptm);
	close(realfd);

	return 0;
}
Example #13
0
File: sig.c Project: nrhtr/genesis
/* void catch_signal(int sig, int code, struct sigcontext *scp) { */
void catch_signal(int sig)
{
    char *sptr;
    cStr *sigstr;
    cData arg1;
    Bool do_shutdown = NO;

    signal(sig, catch_signal);

    sptr = sig_name(sig);
    sigstr = string_from_chars(sptr, strlen(sptr));

    write_err("Caught signal %d: %S", sig, sigstr);

    string_discard(sigstr);


    /* figure out what to do */
    switch (sig) {
#ifdef __UNIX__
    case SIGHUP:
        atomic = NO;
        handle_connection_output();
        flush_files();
#endif
#ifndef __MSVC__
    case SIGUSR2:
        /* let the db do what it wants from here */
        break;
    case SIGUSR1:
        {
            cData *d;
            cList *l;

            /* First cancel all preempted and suspended tasks */
            l = vm_list();
            for (d = list_first(l); d; d = list_next(l, d)) {
                /* boggle */
                if (d->type != INTEGER)
                    continue;
                vm_cancel(d->u.val);
            }
            list_discard(l);

            /* now cancel the current task if it is valid */
            if (vm_lookup(task_id) != NULL) {
                vm_cancel(task_id);
            }

            /* jump back to the main loop */
            longjmp(main_jmp, 1);
            break;
        }
#endif
    case SIGILL:
        /* lets panic and hopefully shutdown without frobbing the db */
        panic(sig_name(sig));
        break;
    case SIGTERM:
        if (running) {
            write_err("*** Attempting normal shutdown ***");
            running = NO;

            /* jump back to the main loop, ignore any current tasks;
             *drip*, *drip*, leaky */
            longjmp(main_jmp, 1);
        } else {
            panic(sig_name(sig));
        }
        break;
    default:
        do_shutdown = YES;
        break;
    }

    /* only pass onto the db if we are 'executing' */
    if (!running)
        return;

    /* send a message to the system object */
    arg1.type = SYMBOL;
    arg1.u.symbol = ident_get(sptr);
    vm_task(SYSTEM_OBJNUM, signal_id, 1, &arg1);

    if (do_shutdown)
        running = NO;
}
Example #14
0
int main(int argc, char *argv[])
{
	int i;
	cp_thread w[COUNT];
	cp_thread r[COUNT];
	long total;
	int rc;

	if (argc > 1) silent = atoi(argv[1]);

	for (i = 0; i < COUNT; i++)
	{
		rc = cp_mutex_init(&lock[i], NULL);
		cp_cond_init(&cond[i], NULL);
		t[i] = cp_hashtable_create(10, cp_hash_string, cp_hash_compare_string);
		tl[i] = cp_list_create();
	}


	rc = cp_mutex_init(&start_mutex, NULL);
	cp_cond_init(&start_cond, NULL);

	for (i = 0; i < COUNT; i++)
		cp_thread_create(r[i], NULL, reader, (void *) i);

	for (i = 0; i < COUNT; i++)
		cp_thread_create(w[i], NULL, writer, (void *) INSERTS);

	printf("press enter\n");
	getchar();
	cp_mutex_lock(&start_mutex);
	running = 1;
	total = time(NULL);
	cp_cond_broadcast(&start_cond);
	rc = cp_mutex_unlock(&start_mutex);
	if (rc == 0) write_err("MAIN");
	for (i = 0; i < COUNT; i++)
		cp_thread_join(w[i], NULL);
	running = 0;

	for (i = 0; i < COUNT; i++)
	{
		cp_mutex_lock(&lock[i]);
		cp_cond_broadcast(&cond[i]);
		cp_mutex_unlock(&lock[i]);
		cp_thread_join(r[i], NULL);
	}

	total = time(NULL) - total;

	printf("\ndone in %ld seconds. tables should be empty now. press enter.\n",
			total);
	getchar();

	for (i = 0; i < COUNT; i++)
	{
		printf("table %d: %ld items\n", i, cp_hashtable_count(t[i]));
		cp_hashtable_destroy(t[i]);
		printf("list %d: %ld items\n", i, cp_list_item_count(tl[i]));
		while (cp_list_item_count(tl[i]))
		{
			char *leftover = cp_list_remove_head(tl[i]);
			printf("       * %s\n", leftover);
		}
		cp_list_destroy(tl[i]);
	}

	printf("deleted them tables. press enter.\n");
	getchar();

	printf("bye.\n");
	return 0;
}
Example #15
0
void error(const char* msg)
{
  write_err("sysloguread: Error: ");
  write_err(msg);
  write_err("\n");
}
Example #16
0
File: net.c Project: whilke/ColdC
/* Wait for I/O events.  sec is the number of seconds we can wait before
 * returning, or -1 if we can wait forever.  Returns nonzero if an I/O event
 * happened. */
Int io_event_wait(Int sec, Conn *connections, server_t *servers,
		  pending_t *pendings)
{
    struct timeval tv, *tvp;
    Conn *conn;
    server_t *serv;
    pending_t *pend;
    fd_set read_fds, write_fds, except_fds;
    Int flags, nfds, count, result, error;
    int dummy = sizeof(int);

    /* Set time structure according to sec. */
    if (sec == -1) {
	tvp = NULL;
        /* this is a rather odd thing to happen for me */
        write_err("select: forever wait");
    } else {
	tv.tv_sec = (long) sec;
	tv.tv_usec = 0;
	tvp = &tv;
    }

    /* Begin with blank file descriptor masks and an nfds of 0. */
    FD_ZERO(&read_fds);
    FD_ZERO(&write_fds);
    FD_ZERO(&except_fds);
    nfds = 0;

    /* Listen for new data on connections, and also check for ability to write
     * to them if we have data to write. */
    for (conn = connections; conn; conn = conn->next) {
	if (!conn->flags.dead) {
            FD_SET(conn->fd, &except_fds);
	    FD_SET(conn->fd, &read_fds);
        }
	if (conn->write_buf->len)
	    FD_SET(conn->fd, &write_fds);
	if (conn->fd >= nfds)
	    nfds = conn->fd + 1;
    }

    /* Listen for connections on the server sockets. */
    for (serv = servers; serv; serv = serv->next) {
	FD_SET(serv->server_socket, &read_fds);
	if (serv->server_socket >= nfds)
	    nfds = serv->server_socket + 1;
    }

    /* Check pending connections for ability to write. */
    for (pend = pendings; pend; pend = pend->next) {
	if (pend->error != NOT_AN_IDENT) {
	    /* The connect has already failed; just set the finished bit. */
	    pend->finished = 1;
	} else {
	    FD_SET(pend->fd, &write_fds);
	    if (pend->fd >= nfds)
		nfds = pend->fd + 1;
	}
    }

#ifdef __Win32__
    /* Winsock 2.0 will return EINVAL (invalid argument) if there are no 
       sockets checked in any of the FDSETs.  At least one server must be
       listening before the call is made.  Winsock 1.1 behaves differently.
     */

    if (servers || connections || pendings) {
#endif
    /* Call select(). */
    count = select(nfds, &read_fds, &write_fds, &except_fds, tvp);
#ifdef __Win32__
    } else {
        count = 0;
    }
#endif

    /* Lose horribly if select() fails on anything but an interrupted system
     * call.  On ERR_INTR, we'll return 0. */
    if (count == SOCKET_ERROR) {
        if (GETERR() != ERR_INTR)
            panic("select() failed");

        /* Stop and return zero if no I/O events occurred. */
        return 0;
    }

    /* Check if any connections are readable or writable. */
    for (conn = connections; conn; conn = conn->next) {
	if (FD_ISSET(conn->fd, &except_fds)) {
            conn->flags.dead = 1;
            fprintf(stderr, "An exception occurred during select()\n");
        }
	if (FD_ISSET(conn->fd, &read_fds))
	    conn->flags.readable = 1;
	if (FD_ISSET(conn->fd, &write_fds))
	    conn->flags.writable = 1;
    }

    /* Check if any server sockets have new connections. */
    for (serv = servers; serv; serv = serv->next) {
	if (FD_ISSET(serv->server_socket, &read_fds)) {
	    serv->client_socket = accept(serv->server_socket,
				 (struct sockaddr *) &sockin, &addr_size);
	    if (serv->client_socket == SOCKET_ERROR)
		continue;
#ifdef __Win32__
            result = 1;
            ioctlsocket(serv->client_socket, FIONBIO, &result);
#else
            flags = fcntl(serv->client_socket, F_GETFL);
	    flags |= O_NONBLOCK;
	    fcntl(serv->client_socket, F_SETFL, flags);
#endif

	    /* Get address and local port of client. */
	    strcpy(serv->client_addr, inet_ntoa(sockin.sin_addr));
	    serv->client_port = ntohs(sockin.sin_port);

	    /* Set the CLOEXEC flag on socket so that it will be closed for a
	     * execute() operation. */
#ifdef FD_CLOEXEC
	    flags = fcntl(serv->client_socket, F_GETFD);
	    flags |= FD_CLOEXEC;
	    fcntl(serv->client_socket, F_SETFD, flags);
#endif
	}
    }

    /* Check if any pending connections have succeeded or failed. */
    for (pend = pendings; pend; pend = pend->next) {
	if (FD_ISSET(pend->fd, &write_fds)) {
	    result = getpeername(pend->fd, (struct sockaddr *) &sockin,
				 &addr_size);
	    if (result == SOCKET_ERROR) {
		getsockopt(pend->fd, SOL_SOCKET, SO_ERROR, (char *) &error,
			   &dummy);
		pend->error = translate_connect_error(error);
	    } else {
		pend->error = NOT_AN_IDENT;
	    }
	    pend->finished = 1;
	}
    }

    /* Return nonzero, indicating that at least one I/O event occurred. */
    return 1;
}