QPair<QString, KLockFile::Ptr> allocateRepository() { KLockFile::Ptr lock; QString repoPath; KComponentData component("item repositories temp", QByteArray(), KComponentData::SkipMainComponentRegistration); QString xdgCacheDir = QProcessEnvironment::systemEnvironment().value("XDG_CACHE_HOME", QDir::homePath() + "/.cache") + "/kdevduchain"; QString baseDir = QProcessEnvironment::systemEnvironment().value("KDEV_DUCHAIN_DIR", xdgCacheDir); KStandardDirs::makeDir(baseDir); Q_ASSERT( ICore::self() ); Q_ASSERT( ICore::self()->activeSession() ); baseDir += '/' + ICore::self()->activeSession()->id().toString(); //Since each instance of kdevelop needs an own directory, iterate until we find a not-yet-used one for(int a = 0; a < 100; ++a) { QString specificDir = baseDir + QString("/%1").arg(a); KStandardDirs::makeDir(specificDir); lock = new KLockFile(specificDir + "/lock", component); KLockFile::LockResult result = lock->lock(KLockFile::NoBlockFlag | KLockFile::ForceFlag); bool useDir = false; if(result != KLockFile::LockOK) { int pid; QString hostname, appname; if(lock->getLockInfo(pid, hostname, appname)) { if(!processExists(pid)) { kDebug() << "The process holding" << specificDir << "with pid" << pid << "does not exists any more. Re-using the directory."; QFile::remove(specificDir + "/lock"); useDir = true; if(lock->lock(KLockFile::NoBlockFlag | KLockFile::ForceFlag) != KLockFile::LockOK) { kWarning() << "Failed to re-establish the lock in" << specificDir; continue; } } } }else { useDir = true; } if(useDir) { repoPath = specificDir; if(result == KLockFile::LockStale) { kWarning() << "stale lock detected:" << specificDir + "/lock"; } break; } } if(repoPath.isEmpty()) { kError() << "could not create a directory for the duchain data"; }else{ kDebug() << "picked duchain directory" << repoPath; } return qMakePair(repoPath, lock); }
ssize_t devblast_readProvider(char *buf, size_t count, loff_t *f_pos) { int i, erro = 0; printk(KERN_WARNING "devblast_readProvider begin\n"); Inicio: if(providerPid == -1) { return 0; } if(flagSendToProvider > 0) { //TRACE1("flagSendToProvider %d\n", flagSendToProvider); printk(KERN_NOTICE "flagSendToProvider %d\n", flagSendToProvider); flagSendToProvider = 0; if (down_interruptible (&sem)) { return -ERESTARTSYS; } for (i=0;i<lastListPos+1;i++) { if (list[i].pid > 0 && !processExists(list[i].pid)) { printk(KERN_NOTICE "%d)Process %d finished\n", list[i].index, list[i].pid); removeProcess(&list[i]); } } //TRACE1("lastListPos %d\n", lastListPos); printk(KERN_NOTICE "lastListPos %d\n", lastListPos); erro = copy_to_user(buf, &list, (lastListPos+1)*sizeof(ProcessInformation)); up(&sem); if(erro) { return -EFAULT; } return (lastListPos+1)*sizeof(ProcessInformation); } else { printk(KERN_WARNING "Flag doesn't send to provider\n"); wait_event_interruptible(queue_provider, flagSendToProvider > 0); if (signal_pending(current)) { //ERROR_TRACE0("Interrupted by signal\n"); printk(KERN_ALERT "Interrupted by signal\n"); } goto Inicio; } }
static ProcessInformation* registerProcess(int file_type) { int i, free, block, isInRingStage, blockRingUpdate; if (current->pid == providerPid) { //printTaskInfo(current->pid); return NULL; } if (IS_SEQUENCE_TYPE(file_type) == BTL_True) blockRingUpdate = 0; else blockRingUpdate = 1; free = -1; block = -1; isInRingStage = 1; for(i=0; i<=lastListPos+1;i++) { if (list[i].pid > 0 && !processExists(list[i].pid)) { printk(KERN_NOTICE "%d)Process %d finished\n", i, list[i].pid); removeProcess(&list[i]); } if (list[i].pid == current->pid) { if (list[i].file_type == file_type) { list[i].state = RUNNING; return &list[i]; } if (IS_SEQUENCE_TYPE(file_type) == BTL_True) { list[i].blockRingUpdate = 0; } if (IS_SEQUENCE_TYPE(list[i].file_type) == BTL_True) { blockRingUpdate = 0; } if (list[i].block != -1) block = list[i].block; isInRingStage = list[i].isInRingStage; } if ((list[i].state == FREE) && (free == -1)) { free = i; } } if(free != -1) { //ERROR_TRACE3("%d)Registrando processo %d lendo do arquivo %d\n", free, current->pid, file_type); printk(KERN_NOTICE "%d)Registrando processo %d lendo do arquivo %d\n", free, current->pid, file_type); list[free].file_type = file_type; list[free].state = RUNNING; list[free].pid = current->pid; list[free].count = 0; list[free].f_pos = 0; list[free].block = block; list[free].ringStageDBPos = 0; list[free].isInRingStage = isInRingStage; list[free].blockRingUpdate = blockRingUpdate; if (free > lastListPos) lastListPos = free; //printTaskInfo(current->pid); return &list[free]; } return NULL; }