int CondorFileTable::poll( struct pollfd *fds, int nfds, int timeout )
{
	struct pollfd *realfds;

	realfds = (struct pollfd *) malloc( sizeof(struct pollfd)*nfds );
	if(!realfds) {
		errno = ENOMEM;
		return -1;
	}

	for( int i=0; i<nfds; i++ ) {
		if(_condor_is_fd_local(fds[i].fd)) {
			realfds[i].fd = _condor_get_unmapped_fd(fds[i].fd);
			realfds[i].events = fds[i].events;
		} else {
			_condor_warning(CONDOR_WARNING_KIND_UNSUP,"poll() is not supported for remote files");
			free(realfds);
			errno = EINVAL;
			return -1;
		}
	}

	int scm = SetSyscalls( SYS_LOCAL|SYS_UNMAPPED );
	int result = ::poll( realfds, nfds, timeout );
	SetSyscalls(scm);

	for( int i=0; i<nfds; i++ ) {
		fds[i].revents = realfds[i].revents;
	}

	free(realfds);

	return result;
}
Beispiel #2
0
int direct_fcntl(int fd, int cmd, void *arg)
{
    int ret = -1;
    int unmapped_fd;

#ifdef CONDOR
    /* This call would normally go through the file table. However, we want
        to do it locally here, so get the unmapped fd the kernel originally
        gave us for this fd and use that directly. */
    unmapped_fd = _condor_get_unmapped_fd(fd);
#else 
    unmapped_fd = fd;
#endif
    ret = syscall(SYS_fcntl, unmapped_fd, cmd, arg);

    return ret;
}
int CondorFileTable::select( int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *timeout )
{
	fd_set	r_real, w_real, e_real;
	int	n_real, fd, fd_real;
	int	result, scm;

	FD_ZERO( &r_real );
	FD_ZERO( &w_real );
	FD_ZERO( &e_real );

	n_real = 0;

	/* For each fd, put its mapped equivalent in the appropriate set */

	for( fd=0; fd<n; fd++ ) {
		fd_real = _condor_get_unmapped_fd(fd);
		if( fd_real>=0 ) {
			if( _condor_is_fd_local(fd) ) {
				if( r && FD_ISSET(fd,r) )
					FD_SET(fd_real,&r_real);
				if( w && FD_ISSET(fd,w) )
					FD_SET(fd_real,&w_real);
				if( e && FD_ISSET(fd,e) )
					FD_SET(fd_real,&e_real);
				n_real = MAX( n_real, fd_real+1 );
			} else {
				if( (r && FD_ISSET(fd,r)) ||
				    (w && FD_ISSET(fd,w)) ||
				    (e && FD_ISSET(fd,e)) ) {
					_condor_warning(CONDOR_WARNING_KIND_UNSUP,"select() is not supported for remote files.");
					errno = EINVAL;
					return -1;
				}
			}
		}
	}

	/* Do a local select */

	scm = SetSyscalls( SYS_LOCAL|SYS_UNMAPPED );
	result = ::select( n_real, &r_real, &w_real, &e_real, timeout );
	SetSyscalls(scm);

	if( r ) FD_ZERO( r );
	if( w ) FD_ZERO( w );
	if( e ) FD_ZERO( e );

	/* Set the bit for each fd whose real equivalent is set. */

	for( fd=0; fd<n; fd++ ) {
		fd_real = _condor_get_unmapped_fd(fd);
		if( fd_real>=0 && _condor_is_fd_local(fd) ) {
			if( r && FD_ISSET(fd_real,&r_real) )
				FD_SET(fd,r);
			if( w && FD_ISSET(fd_real,&w_real) )
				FD_SET(fd,w);
			if( e && FD_ISSET(fd_real,&e_real) )
				FD_SET(fd,e);
		}
	}

	return result;
}