Example #1
0
/*
 * Add a FD to the fd set
 */
static int fpm_event_port_add(struct fpm_event_s *ev) /* {{{ */
{
	/* add the event to port */
	if (port_associate(pfd, PORT_SOURCE_FD, ev->fd, POLLIN, (void *)ev) < 0) {
		zlog(ZLOG_ERROR, "port: unable to add the event");
		return -1;
	}
	return 0;
}
static inline void
vws_add(struct vws *vws, int fd, void *data)
{
	/*
	 * POLLIN should be all we need here
	 *
	 */
	AZ(port_associate(vws->dport, PORT_SOURCE_FD, fd, POLLIN, data));
}
Example #3
0
int event_queue_add_fd_write(int eq, int fd) {

        if (port_associate(eq, PORT_SOURCE_FD, fd, POLLOUT, NULL)) {
                uwsgi_error("port_associate");
                return -1;
        }

        return fd;
}
Example #4
0
static inline void
vca_add(int fd, void *data)
{
	/*
	 * POLLIN should be all we need here
	 *
	 */
	AZ(port_associate(solaris_dport, PORT_SOURCE_FD, fd, POLLIN, data));
}
Example #5
0
ph_result_t ph_nbio_emitter_apply_io_mask(struct ph_nbio_emitter *emitter,
    ph_job_t *job, ph_iomask_t mask)
{
  int res;
  int want_mask = 0;

  if (job->fd == -1) {
    return PH_OK;
  }

  switch (mask & (PH_IOMASK_READ|PH_IOMASK_WRITE)) {
    case PH_IOMASK_READ:
      want_mask = POLLIN|DEFAULT_POLL_MASK;
      break;
    case PH_IOMASK_WRITE:
      want_mask = POLLOUT|DEFAULT_POLL_MASK;
      break;
    case PH_IOMASK_READ|PH_IOMASK_WRITE:
      want_mask = POLLIN|POLLOUT|DEFAULT_POLL_MASK;
      break;
    case 0:
    default:
      want_mask = 0;
  }

  if (want_mask == job->kmask) {
    return PH_OK;
  }

  switch (want_mask) {
    case 0:
      res = port_dissociate(emitter->io_fd, PORT_SOURCE_FD, job->fd);
      if (res != 0 && errno == ENOENT) {
        res = 0;
      }
      if (res != 0) {
        ph_panic("port_dissociate: setting mask to %02x on fd %d -> `Pe%d",
            mask, job->fd, errno);
      }
      job->kmask = 0;
      job->mask = 0;
      break;

    default:
      job->mask = mask;
      job->kmask = want_mask;
      res = port_associate(emitter->io_fd, PORT_SOURCE_FD, job->fd,
          want_mask, job);
      if (res != 0) {
        ph_panic("port_associate: setting mask to %02x on fd %d -> `Pe%d",
            mask, job->fd, errno);
        return PH_ERR;
      }
  }
  return PH_OK;
}
Example #6
0
int event_queue_fd_read_to_readwrite(int eq, int fd) {

    if (port_associate(eq, PORT_SOURCE_FD, fd, POLLIN|POLLOUT, NULL)) {
        uwsgi_error("port_associate");
        return -1;
    }

    return 0;

}
static ngx_int_t
ngx_eventport_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
{
    ngx_event_t       *e;
    ngx_connection_t  *c;
    /*
     * when the file descriptor is closed, the event port automatically
     * dissociates it from the port, so we do not need to dissociate explicitly
     * the event before the closing the file descriptor
     */
    if (flags & NGX_CLOSE_EVENT)
    {
        ev->active = 0;
        ev->oneshot = 0;
        return NGX_OK;
    }
    c = ev->data;
    if (event == NGX_READ_EVENT)
    {
        e = c->write;
        event = POLLOUT;
    }
    else
    {
        e = c->read;
        event = POLLIN;
    }
    if (e->oneshot)
    {
        ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
                       "eventport change event: fd:%d ev:%04Xi", c->fd, event);
        if (port_associate(ep, PORT_SOURCE_FD, c->fd, event,
                           (void *)((uintptr_t) ev | ev->instance))
                == -1)
        {
            ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
                          "port_associate() failed");
            return NGX_ERROR;
        }
    }
    else
    {
        ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0,
                       "eventport del event: fd:%d", c->fd);
        if (port_dissociate(ep, PORT_SOURCE_FD, c->fd) == -1)
        {
            ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
                          "port_dissociate() failed");
            return NGX_ERROR;
        }
    }
    ev->active = 0;
    ev->oneshot = 0;
    return NGX_OK;
}
Example #8
0
static int uv__fs_event_rearm(uv_fs_event_t* handle) {
  if (handle->fd == -1) return 0;

  if (port_associate(handle->loop->fs_fd, PORT_SOURCE_FILE,
                     (uintptr_t) & handle->fo, FILE_ATTRIB | FILE_MODIFIED,
                     handle) == -1) {
    uv__set_sys_error(handle->loop, errno);
    return -1;
  }
  handle->fd = PORT_LOADED;
  return 0;
}
Example #9
0
bool SelEpolKqEvPrt::registerForEvent(SOCKET descriptor)
{
	curfds++;
	#ifdef OS_MINGW
		u_long iMode = 1;
		ioctlsocket(descriptor, FIONBIO, &iMode);
	#else
		fcntl(descriptor, F_SETFL, fcntl(descriptor, F_GETFD, 0) | O_NONBLOCK);
	#endif
	//fcntl(descriptor, F_SETFL, fcntl(descriptor, F_GETFD, 0) | O_NONBLOCK);
	#if defined(USE_MINGW_SELECT)
		FD_SET(descriptor, &master);
		if(descriptor > fdMax)
			fdMax = descriptor;
	#elif defined(USE_SELECT)
		FD_SET(descriptor%FD_SETSIZE, &master[descriptor/FD_SETSIZE]);
		if(descriptor > fdMax)
			fdMax = descriptor;
	#elif defined USE_EPOLL
		ev.events = EPOLLIN | EPOLLPRI;
		ev.data.fd = descriptor;
		if (epoll_ctl(epoll_handle, EPOLL_CTL_ADD, descriptor, &ev) < 0)
		{
			perror("epoll");
			logger << "Error adding to epoll cntl list" << endl;
			return false;
		}
	#elif defined USE_KQUEUE
		memset(&change, 0, sizeof(change));
		EV_SET(&change, descriptor, EVFILT_READ, EV_ADD, 0, 0, 0);
		kevent(kq, &change, 1, NULL, 0, NULL);
	#elif defined USE_DEVPOLL
		struct pollfd poll_fd;
		poll_fd.fd = descriptor;
		poll_fd.events = POLLIN;
		poll_fd.revents = 0;
		if (write(dev_poll_fd, &poll_fd, sizeof(poll_fd)) < 0) {
			perror("devpoll");
			return false;
		}
	#elif defined USE_EVPORT
		if (port_associate(port, PORT_SOURCE_FD, descriptor, POLLIN, NULL) < 0) {
			perror("port_associate");
		}
	#elif defined USE_POLL
		nfds++;
		polled_fds = (struct pollfd *)realloc(polled_fds, (nfds+1)*sizeof(struct pollfd));
		(polled_fds+nfds)->fd = descriptor;
		(polled_fds+nfds)->events = POLLIN | POLLPRI;
	#endif
	return true;
}
Example #10
0
File: port.c Project: Ga-vin/apache
static apr_status_t impl_pollset_add(apr_pollset_t *pollset,
                                     const apr_pollfd_t *descriptor)
{
    apr_os_sock_t fd;
    pfd_elem_t *elem;
    int res;
    apr_status_t rv = APR_SUCCESS;

    pollset_lock_rings();

    if (!APR_RING_EMPTY(&(pollset->p->free_ring), pfd_elem_t, link)) {
        elem = APR_RING_FIRST(&(pollset->p->free_ring));
        APR_RING_REMOVE(elem, link);
    }
    else {
        elem = (pfd_elem_t *) apr_palloc(pollset->pool, sizeof(pfd_elem_t));
        APR_RING_ELEM_INIT(elem, link);
        elem->on_query_ring = 0;
    }
    elem->pfd = *descriptor;

    if (descriptor->desc_type == APR_POLL_SOCKET) {
        fd = descriptor->desc.s->socketdes;
    }
    else {
        fd = descriptor->desc.f->filedes;
    }

    /* If another thread is polling, notify the kernel immediately; otherwise,
     * wait until the next call to apr_pollset_poll().
     */
    if (apr_atomic_read32(&pollset->p->waiting)) {
        res = port_associate(pollset->p->port_fd, PORT_SOURCE_FD, fd, 
                             get_event(descriptor->reqevents), (void *)elem);

        if (res < 0) {
            rv = apr_get_netos_error();
            APR_RING_INSERT_TAIL(&(pollset->p->free_ring), elem, pfd_elem_t, link);
        }
        else {
            elem->on_query_ring = 1;
            APR_RING_INSERT_TAIL(&(pollset->p->query_ring), elem, pfd_elem_t, link);
        }
    } 
    else {
        APR_RING_INSERT_TAIL(&(pollset->p->add_ring), elem, pfd_elem_t, link);
    }

    pollset_unlock_rings();

    return rv;
}
Example #11
0
static void alter_fd_associate(eventer_t e, int mask, struct ports_spec *spec) {
  int events = 0, s_errno = 0, ret;
  if(mask & EVENTER_READ) events |= POLLIN;
  if(mask & EVENTER_WRITE) events |= POLLOUT;
  if(mask & EVENTER_EXCEPTION) events |= POLLERR;
  errno = 0;
  ret = port_associate(spec->port_fd, PORT_SOURCE_FD, e->fd, events, (void *)(intptr_t)e->fd);
  s_errno = errno;
  if (ret == -1) {
    mtevFatal(mtev_error,
          "eventer port_associate failed(%d-%d): %d/%s\n", e->fd, spec->port_fd, s_errno, strerror(s_errno));
  }
}
Example #12
0
bool FdEventQueue::associate(fd_t fd, FdEvent::Type fd_event_types) {
  if (fd_event_types > 0) {
    return port_associate(
             port,
             PORT_SOURCE_FD,
             fd,
             fd_event_types,
             NULL
           ) != -1;
  } else {
    return dissociate(fd);
  }
}
Example #13
0
void
pe_update_events(fde_t * F, short filter, PF * handler)
{
	PF *cur_handler = NULL;

	if (filter == POLLRDNORM)
		cur_handler = F->read_handler;
	else if (filter == POLLWRNORM)
		cur_handler = F->write_handler;

	if (!cur_handler && handler)
		port_associate(pe, PORT_SOURCE_FD, F->fd, filter, F);
	else if (cur_handler && !handler)
		port_dissociate(pe, PORT_SOURCE_FD, F->fd);
}
static ngx_int_t
ngx_eventport_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
{
    ngx_int_t          events, prev;
    ngx_event_t       *e;
    ngx_connection_t  *c;

    c = ev->data;

    events = event;

    if (event == NGX_READ_EVENT) {
        e = c->write;
        prev = POLLOUT;
#if (NGX_READ_EVENT != POLLIN)
        events = POLLIN;
#endif

    } else {
        e = c->read;
        prev = POLLIN;
#if (NGX_WRITE_EVENT != POLLOUT)
        events = POLLOUT;
#endif
    }

    if (e->oneshot) {
        events |= prev;
    }

    ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
                   "eventport add event: fd:%d ev:%04Xi", c->fd, events);

    if (port_associate(ep, PORT_SOURCE_FD, c->fd, events,
                       (void *) ((uintptr_t) ev | ev->instance))
        == -1)
    {
        ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
                      "port_associate() failed");
        return NGX_ERROR;
    }

    ev->active = 1;
    ev->oneshot = 1;

    return NGX_OK;
}
Example #15
0
bool PortsEngine::AddFd(EventHandler* eh, int event_mask)
{
	int fd = eh->GetFd();
	if ((fd < 0) || (fd > GetMaxFds() - 1))
		return false;

	if (ref[fd])
		return false;

	ref[fd] = eh;
	SocketEngine::SetEventMask(eh, event_mask);
	port_associate(EngineHandle, PORT_SOURCE_FD, fd, mask_to_events(event_mask), eh);

	ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);
	CurrentSetSize++;
	return true;
}
Example #16
0
/*
 * (Re)associates the given file descriptor with the event port. The OS events
 * are specified (implicitly) from the fd_info struct.
 */
static int
reassociate(struct evport_data *epdp, struct fd_info *fdip, int fd)
{
	int sysevents = FDI_TO_SYSEVENTS(fdip);

	if (sysevents != 0) {
		if (port_associate(epdp->ed_port, PORT_SOURCE_FD,
				   fd, sysevents, NULL) == -1) {
			event_warn("port_associate");
			return (-1);
		}
	}

	check_evportop(epdp);

	return (0);
}
Example #17
0
static ret_t
_set_mode (cherokee_fdpoll_port_t *fdp, int fd, int rw)
{
	int rc;

	rc = port_associate( fdp->port,
	                     PORT_SOURCE_FD,
	                     fd,
	                    (rw == FDPOLL_MODE_WRITE ? POLLOUT : POLLIN),
	                    (rw == FDPOLL_MODE_WRITE ? WRITE   : READ));
	if ( rc == -1 ) {
		LOG_ERRNO (errno, cherokee_err_error,
			   CHEROKEE_ERROR_FDPOLL_PORTS_ASSOCIATE, fd);
		return ret_error;
	}

	return ret_ok;
}
Example #18
0
void inline_speed
port_associate_and_check (EV_P_ int fd, int ev)
{
  if (0 >
      port_associate (
         backend_fd, PORT_SOURCE_FD, fd,
         (ev & EV_READ ? POLLIN : 0)
         | (ev & EV_WRITE ? POLLOUT : 0),
         0
      )
  )
    {
      if (errno == EBADFD)
        fd_kill (EV_A_ fd);
      else
        ev_syserr ("(libev) port_associate");
    }
}
Example #19
0
static ret_t
fd_associate( cherokee_fdpoll_port_t *fdp, int fd, void *rw )
{
	int rc;

	rc = port_associate (fdp->port,                /* port */
	                     PORT_SOURCE_FD,           /* source */
	                     fd,                       /* object */
	                     rw?POLL_WRITE:POLL_READ,  /* events */
	                     rw);                      /* user data */

	if ( rc == -1 ) {
		LOG_ERRNO (errno, cherokee_err_error,
			   CHEROKEE_ERROR_FDPOLL_PORTS_ASSOCIATE, fd);
		return ret_error;
	}

	return ret_ok;
}
Example #20
0
static int __iv_fd_port_upload_one(struct iv_state *st, struct iv_fd_ *fd)
{
    int ret;

    iv_list_del_init(&fd->list_notify);

    if (fd->wanted_bands) {
        ret = port_associate(st->u.port.port_fd, PORT_SOURCE_FD, fd->fd,
                             bits_to_poll_mask(fd->wanted_bands), fd);
    } else {
        ret = port_dissociate(st->u.port.port_fd, PORT_SOURCE_FD,
                              fd->fd);
    }

    if (ret == 0)
        fd->registered_bands = fd->wanted_bands;

    return ret;
}
Example #21
0
bool PortsEngine::AddFd(EventHandler* eh)
{
	int fd = eh->GetFd();
	if ((fd < 0) || (fd > GetMaxFds() - 1))
		return false;

	if (GetRemainingFds() <= 1)
		return false;

	if (ref[fd])
		return false;

	ref[fd] = eh;
	port_associate(EngineHandle, PORT_SOURCE_FD, fd, eh->Readable() ? POLLRDNORM : POLLWRNORM, eh);

	ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd);
	CurrentSetSize++;
	return true;
}
Example #22
0
APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset,
                                          const apr_pollfd_t *descriptor)
{
    apr_os_sock_t fd;
    pfd_elem_t *elem;
    int res;
    apr_status_t rv = APR_SUCCESS;

    pollset_lock_rings();

    if (!APR_RING_EMPTY(&(pollset->free_ring), pfd_elem_t, link)) {
        elem = APR_RING_FIRST(&(pollset->free_ring));
        APR_RING_REMOVE(elem, link);
    }
    else {
        elem = (pfd_elem_t *) apr_palloc(pollset->pool, sizeof(pfd_elem_t));
        APR_RING_ELEM_INIT(elem, link);
    }
    elem->pfd = *descriptor;

    if (descriptor->desc_type == APR_POLL_SOCKET) {
        fd = descriptor->desc.s->socketdes;
    }
    else {
        fd = descriptor->desc.f->filedes;
    }

    res = port_associate(pollset->port_fd, PORT_SOURCE_FD, fd, 
                         get_event(descriptor->reqevents), (void *)elem);

    if (res < 0) {
        rv = APR_ENOMEM;
        APR_RING_INSERT_TAIL(&(pollset->free_ring), elem, pfd_elem_t, link);
    }
    else {
        pollset->nelts++;
        APR_RING_INSERT_TAIL(&(pollset->query_ring), elem, pfd_elem_t, link);
    }

    pollset_unlock_rings();

    return rv;
}
Example #23
0
int ioevent_modify(IOEventPoller *ioevent, const int fd, const int e,
    void *data)
{
#if IOEVENT_USE_EPOLL
  struct epoll_event ev;
  memset(&ev, 0, sizeof(ev));
  ev.events = e | ioevent->extra_events;
  ev.data.ptr = data;
  return epoll_ctl(ioevent->poll_fd, EPOLL_CTL_MOD, fd, &ev);
#elif IOEVENT_USE_KQUEUE
  struct kevent ev[2];
  int n = 0;
  if (e & IOEVENT_READ) {
     if (!(ioevent->care_events & IOEVENT_READ)) {
        EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD | ioevent->extra_events, 0, 0, data);
     }
  }
  else if ((ioevent->care_events & IOEVENT_READ)) {
    EV_SET(&ev[n++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
  }

  if (e & IOEVENT_WRITE) {
    if (!(ioevent->care_events & IOEVENT_WRITE)) {
      EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD | ioevent->extra_events, 0, 0, data);
    }
  }
  else if ((ioevent->care_events & IOEVENT_WRITE)) {
    EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
  }

  ioevent->care_events = e;
  if (n > 0) {
      return kevent(ioevent->poll_fd, ev, n, NULL, 0, NULL);
  }
  else {
      return 0;
  }
#elif IOEVENT_USE_PORT
  return port_associate(ioevent->poll_fd, PORT_SOURCE_FD, fd, e, data);
#endif
}
Example #24
0
int PortsEngine::DispatchEvents()
{
	struct timespec poll_time;

	poll_time.tv_sec = 1;
	poll_time.tv_nsec = 0;

	unsigned int nget = 1; // used to denote a retrieve request.
	int i = port_getn(EngineHandle, this->events, GetMaxFds() - 1, &nget, &poll_time);

	// first handle an error condition
	if (i == -1)
		return i;

	TotalEvents += nget;

	for (i = 0; i < nget; i++)
	{
		switch (this->events[i].portev_source)
		{
			case PORT_SOURCE_FD:
			{
				int fd = this->events[i].portev_object;
				if (ref[fd])
				{
					// reinsert port for next time around
					port_associate(EngineHandle, PORT_SOURCE_FD, fd, POLLRDNORM, ref[fd]);
					if ((this->events[i].portev_events & POLLRDNORM))
						ReadEvents++;
					else
						WriteEvents++;
					ref[fd]->HandleEvent((this->events[i].portev_events & POLLRDNORM) ? EVENT_READ : EVENT_WRITE);
				}
			}
			default:
			break;
		}
	}

	return i;
}
Example #25
0
File: port.c Project: Ga-vin/apache
static apr_status_t impl_pollcb_add(apr_pollcb_t *pollcb,
                                    apr_pollfd_t *descriptor)
{
    int ret, fd;

    if (descriptor->desc_type == APR_POLL_SOCKET) {
        fd = descriptor->desc.s->socketdes;
    }
    else {
        fd = descriptor->desc.f->filedes;
    }

    ret = port_associate(pollcb->fd, PORT_SOURCE_FD, fd,
                         get_event(descriptor->reqevents), descriptor);

    if (ret == -1) {
        return apr_get_netos_error();
    }

    return APR_SUCCESS;
}
Example #26
0
static int associate_all_events(struct port_event_context *port_ev)
{
	struct port_associate_vals *val;

	for (val = port_ev->po_vals; val; val = val->next) {
		int ret;
		if (val->associated_event) {
			continue;
		}
		ret = port_associate(port_ev->port_fd,
					PORT_SOURCE_FD,
					(uintptr_t)val->fde->fd,
					val->events,
					(void *)val);
		if (ret != 0) {
			return -1;
		}
		val->associated_event = true;
	}
	return 0;
}
Example #27
0
File: event.c Project: sashka/uwsgi
int event_queue_wait(int eq, int timeout, int *interesting_fd) {

        int ret;
	port_event_t pe;
	timespec_t ts;

        if (timeout > 0) {
		ts.tv_sec = timeout;
		ts.tv_nsec = 0;
        	ret = port_get(eq, &pe, &ts);
        }
	else {
        	ret = port_get(eq, &pe, NULL);
	}
        if (ret < 0) {
		if (errno != ETIME) {
                	uwsgi_error("port_get()");
			return -1;
		}
		return 0;
        }

	if (pe.portev_source == PORT_SOURCE_FD) {
		// event must be readded (damn Oracle/Sun why the fu*k you made such a horrible choice ???? why not adding a ONESHOT flag ???)
		if (port_associate(eq, pe.portev_source, pe.portev_object, pe.portev_events, NULL)) {
                	uwsgi_error("port_associate");
        	}
	}


	if (pe.portev_source == PORT_SOURCE_FILE || pe.portev_source == PORT_SOURCE_TIMER) {
        	*interesting_fd = (long) pe.portev_user;
	}
	else {
		*interesting_fd = (int) pe.portev_object;
	}

        return 1;
}
Example #28
0
void mowgli_ioevent_associate(mowgli_ioevent_handle_t *self, mowgli_ioevent_source_t source, int object, unsigned int flags, void *opaque)
{
	int events = 0;

	if (source != MOWGLI_SOURCE_FD)
		return;

#ifdef HAVE_EPOLL_CTL
	{
		struct epoll_event ep_event = {};
		events = EPOLLONESHOT;

		if (flags & MOWGLI_POLLRDNORM)
			events |= EPOLLIN;

		if (flags & MOWGLI_POLLWRNORM)
			events |= EPOLLOUT;

		ep_event.events = events;
		ep_event.data.ptr = opaque;

		epoll_ctl(self->impldata, EPOLL_CTL_ADD, object, &ep_event);
	}
#endif

#ifdef HAVE_PORT_CREATE
#ifdef POLLRDNORM
	if (flags & MOWGLI_POLLRDNORM)
		events |= POLLRDNORM;
#endif

#ifdef EPOLLWRNORM
	if (flags & MOWGLI_POLLWRNORM)
		events |= EPOLLWRNORM;
#endif

	port_associate(self->impldata, PORT_SOURCE_FD, object, events, opaque);
#endif
}
Example #29
0
static void alter_fd(eventer_t e, int mask) {
  if(mask & (EVENTER_READ | EVENTER_WRITE | EVENTER_EXCEPTION)) {
    int events = 0;
    if(mask & EVENTER_READ) events |= POLLIN;
    if(mask & EVENTER_WRITE) events |= POLLOUT;
    if(mask & EVENTER_EXCEPTION) events |= POLLERR;
    if(port_associate(port_fd, PORT_SOURCE_FD, e->fd, events, (void *)e->fd) == -1) {
      noitL(eventer_err,
            "eventer port_associate failed: %s\n", strerror(errno));
      abort();
    }
  }
  else {
    if(port_dissociate(port_fd, PORT_SOURCE_FD, e->fd) == -1) {
      if(errno == ENOENT) return; /* Fine */
      if(errno == EBADFD) return; /* Fine */
      noitL(eventer_err,
            "eventer port_dissociate failed: %s\n", strerror(errno));
      abort();
    }
  }
}
Example #30
0
static DIR *portfs_root_start_watch_dir(watchman_global_watcher_t watcher,
    w_root_t *root, struct watchman_dir *dir, struct timeval now,
    const char *path) {
  struct portfs_root_state *state = root->watch;
  DIR *osdir;
  struct stat st;
  unused_parameter(watcher);

  osdir = opendir_nofollow(path);
  if (!osdir) {
    handle_open_errno(root, dir, now, "opendir", errno, NULL);
    return NULL;
  }

  if (fstat(dirfd(osdir), &st) == -1) {
    // whaaa?
    w_log(W_LOG_ERR, "fstat on opened dir %s failed: %s\n", path,
        strerror(errno));
    w_root_schedule_recrawl(root, "fstat failed");
    closedir(osdir);
    return NULL;
  }

  dir->port_file.fo_mtime = st.st_atim;
  dir->port_file.fo_mtime = st.st_mtim;
  dir->port_file.fo_ctime = st.st_ctim;
  dir->port_file.fo_name = (char*)dir->path->buf;

  errno = 0;
  if (port_associate(state->port_fd, PORT_SOURCE_FILE,
        (uintptr_t)&dir->port_file, WATCHMAN_PORT_EVENTS,
        SET_DIR_BIT(dir))) {
    w_log(W_LOG_ERR, "port_associate %s %s\n",
        dir->port_file.fo_name, strerror(errno));
  }

  return osdir;
}