/** * \brief Stop all threads */ void PipeListener::stopAll() { removePipe(); _watcher->stop(); _scanner->stop(); _cleaner->stop(); _done = true; }
/** * \brief Kill all threads (send "k" into pipe) */ void PipeListener::killAll() { _done = true; std::ofstream fpipe(_pipename, std::ios::out); fpipe << "k\n"; fpipe.close(); removePipe(); }
void destroyNamedPipeObject (NamedPipeObject *obj) { logMessage(LOG_DEBUG, "destroying named pipe: %s", obj->host.path); if (obj->releaseResources) obj->releaseResources(obj); stopInputMonitor(obj); closeInputDescriptor(obj); removePipe(obj); deallocateHostPath(obj); free(obj); }
NamedPipeObject * newNamedPipeObject (const char *name, NamedPipeInputCallback *callback, void *data) { NamedPipeObject *obj; if ((obj = malloc(sizeof(*obj)))) { memset(obj, 0, sizeof(*obj)); obj->callback = callback; obj->data = data; obj->createPipe = NULL; obj->monitorPipe = monitorInput; obj->resetPipe = NULL; obj->releaseResources = NULL; setNamedPipeMethods(obj); initializeHostPath(obj); initializeInputDescriptor(obj); initializeInputMonitor(obj); { const char *directory = getNamedPipeDirectory(); obj->host.path = directory? makePath(directory, name): NULL; } if (obj->host.path) { if (!obj->createPipe) { logUnsupportedOperation("create named pipe"); } else if (obj->createPipe(obj)) { if (!obj->monitorPipe) { logUnsupportedOperation("monitor named pipe"); } else if (obj->monitorPipe(obj)) { return obj; } closeInputDescriptor(obj); removePipe(obj); } deallocateHostPath(obj); } free(obj); } else { logMallocError(); } return NULL; }
static int createFifo (NamedPipeObject *obj) { int result = mkfifo(obj->host.path, 0); if ((result == -1) && (errno == EEXIST)) { struct stat fifo; if (lstat(obj->host.path, &fifo) == -1) { logMessage(LOG_ERR, "cannot stat FIFO: %s: %s", obj->host.path, strerror(errno)); } else if (S_ISFIFO(fifo.st_mode)) { result = 0; } } if (result != -1) { if (chmod(obj->host.path, S_IRUSR|S_IWUSR|S_IWGRP|S_IWOTH) != -1) { // open read-write even though we only read to prevent an end-of-file condition if ((obj->input.descriptor = open(obj->host.path, O_RDWR|O_NONBLOCK)) != -1) { logMessage(LOG_DEBUG, "FIFO created: %s: fd=%d", obj->host.path, obj->input.descriptor); return 1; } else { logMessage(LOG_ERR, "cannot open FIFO: %s: %s", obj->host.path, strerror(errno)); } } else { logMessage(LOG_ERR, "cannot set FIFO permissions: %s: %s", obj->host.path, strerror(errno)); } removePipe(obj); } else { logMessage(LOG_ERR, "cannot create FIFO: %s: %s", obj->host.path, strerror(errno)); } return 0; }