/* This is called when a new ICE connection is made. It arranges for the ICE connection to be handled via the event loop. */ static void iceNewConnection(IceConn connection, IcePointer clientData, Bool opening, IcePointer *watchData) { if (opening) { SM_DEBUG(printf("ICE connection opening\n")); /* Make sure we don't pass on these file descriptors to any exec'ed children */ fcntl(IceConnectionNumber(connection), F_SETFD, fcntl(IceConnectionNumber(connection), F_GETFD, 0) | FD_CLOEXEC); iceWatchFdHandle = compAddWatchFd(IceConnectionNumber(connection), POLLIN | POLLPRI | POLLHUP | POLLERR, iceProcessMessages, connection); iceConnected = 1; } else { SM_DEBUG(printf("ICE connection closing\n")); if (iceConnected) { compRemoveWatchFd(iceWatchFdHandle); iceWatchFdHandle = 0; iceConnected = 0; } } }
static void glibPrepare (CompDisplay *display, GMainContext *context) { int nFds = 0; int timeout = -1; int i; GLIB_DISPLAY (display); g_main_context_prepare (context, &gd->maxPriority); do { if (nFds > gd->fdsSize) { if (gd->fds) free (gd->fds); gd->fds = malloc ((sizeof (GPollFD) + sizeof (GLibWatch)) * nFds); if (!gd->fds) { nFds = 0; break; } gd->watch = (GLibWatch *) (gd->fds + nFds); gd->fdsSize = nFds; } nFds = g_main_context_query (context, gd->maxPriority, &timeout, gd->fds, gd->fdsSize); } while (nFds > gd->fdsSize); if (timeout < 0) timeout = INT_MAX; for (i = 0; i < nFds; i++) { gd->watch[i].display = display; gd->watch[i].index = i; gd->watch[i].handle = compAddWatchFd (gd->fds[i].fd, gd->fds[i].events, glibCollectEvents, &gd->watch[i]); } gd->nFds = nFds; gd->timeoutHandle = compAddTimeout (timeout, timeout, glibDispatchAndPrepare, display); }
static void fuseMount(CompDisplay *d) { char *mountPoint; struct fuse_args args = FUSE_ARGS_INIT(0, NULL); FUSE_DISPLAY(d); mountPoint = strdup(fd->opt[FUSE_DISPLAY_OPTION_MOUNT_POINT].value.s); if (!mountPoint) return; fuse_opt_add_arg(&args, ""); fuse_opt_add_arg(&args, "-o"); fuse_opt_add_arg(&args, "allow_root"); fd->channel = fuse_mount(mountPoint, &args); if (!fd->channel) { fuse_opt_free_args(&args); free(mountPoint); return; } fuse_opt_free_args(&args); fd->buffer = malloc(fuse_chan_bufsize(fd->channel)); if (!fd->buffer) { fuse_unmount(mountPoint, fd->channel); free(mountPoint); fd->channel = NULL; return; } fd->mountPoint = mountPoint; fuse_session_add_chan(fd->session, fd->channel); fd->watchFdHandle = compAddWatchFd(fuse_chan_fd(fd->channel), POLLIN | POLLPRI | POLLHUP | POLLERR, fuseProcessMessages, d); }
static Bool inotifyInitDisplay(CompPlugin *p, CompDisplay *d) { InotifyDisplay *id; CompFileWatch *fw; id = malloc (sizeof (InotifyDisplay)); if (!id) return FALSE; id->fd = inotify_init (); if (id->fd < 0) { perror ("inotify_init"); free (id); return FALSE; } id->watch = NULL; id->watchFdHandle = compAddWatchFd (id->fd, POLLIN | POLLPRI | POLLHUP | POLLERR, inotifyProcessEvents, d); WRAP (id, d, fileWatchAdded, inotifyFileWatchAdded); WRAP (id, d, fileWatchRemoved, inotifyFileWatchRemoved); d->privates[displayPrivateIndex].ptr = id; for (fw = d->fileWatch; fw; fw = fw->next) inotifyFileWatchAdded (d, fw); return TRUE; }