void addonTransfer::sendFile(std::string filename) { boost::upgrade_lock<boost::shared_mutex> lockit(tMutex); boost::filesystem::path fpath(filename); if(transfering) { return; //already started } if(!boost::filesystem::exists(fpath)) { // file does not exist; return; } std::size_t file_size = boost::filesystem::file_size(fpath); int file_crc = addonHash::crc32_file(filename); gSocket->writeTo(boost::str(boost::format("CMDRESPONSE|%1%|%2%|%3%|%4%") % ADDON_CMD_QUERY_TRF % filename % file_size % file_crc)); { boost::upgrade_to_unique_lock<boost::shared_mutex> lockit_(lockit); transfering = true; } tHandle = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&addonTransfer::sendFileThread, this, filename, file_size, file_crc))); }
void TrajectoryVisualization::setBackwardColor(QColor c) { { boost::mutex::scoped_lock lockit(this->updateMutex); backwardColor = osg::Vec4(c.redF(), c.greenF(), c.blueF(), c.alphaF() ); } emit propertyChanged("BackwardColor"); setDirty(); }
void TrajectoryVisualization::setColor(QColor color) { { boost::mutex::scoped_lock lockit(this->updateMutex); this->color = osg::Vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF()); } emit propertyChanged("Color"); setDirty(); }
void TrajectoryVisualization::setLineWidth(double line_width) { { boost::mutex::scoped_lock lockit(this->updateMutex); this->line_width = line_width; } emit propertyChanged("LineWidth"); setDirty(); }
/***************************************************** set a variable in the shared area *******************************************************/ void smbw_setshared(const char *name, const char *val) { int l1, l2; /* we don't allow variable overwrite */ if (smbw_getshared(name)) return; lockit(); l1 = strlen(name)+1; l2 = strlen(val)+1; variables = (char *)Realloc(variables, shared_size + l1+l2+4); if (!variables) { DEBUG(0,("out of memory in smbw_setshared\n")); exit(1); } SSVAL(&variables[shared_size], 0, l1); SSVAL(&variables[shared_size], 2, l2); pstrcpy(&variables[shared_size] + 4, name); pstrcpy(&variables[shared_size] + 4 + l1, val); shared_size += l1+l2+4; lseek(shared_fd, 0, SEEK_SET); if (write(shared_fd, variables, shared_size) != shared_size) { DEBUG(0,("smbw_setshared failed (%s)\n", strerror(errno))); exit(1); } unlockit(); }
void TrajectoryVisualization::setColor(const base::Vector3d& color) { { boost::mutex::scoped_lock lockit(this->updateMutex); this->color = osg::Vec4(color.x(), color.y(), color.z(), 1.0); } emit propertyChanged("Color"); setDirty(); }
void TrajectoryVisualization::setMaxVelocity(double max_velocity) { { boost::mutex::scoped_lock lockit(this->updateMutex); this->max_velocity = max_velocity; } emit propertyChanged("MaxVelocity"); setDirty(); }
void addonTransfer::recvFileThread(std::string filename, std::size_t remote_file_size, int remote_file_crc) { boost::this_thread::sleep(boost::posix_time::seconds(1)); std::ofstream file(filename.c_str(), (std::ofstream::out | std::ofstream::binary)); std::size_t bytes_rx = NULL; char *block = new char[remote_file_size + 1]; memset(block, NULL, remote_file_size); try { bytes_rx = boost::asio::read(s, boost::asio::buffer(block, remote_file_size), boost::asio::transfer_exactly(remote_file_size)); file.write(block, bytes_rx); file.close(); delete[] block; } catch(boost::system::system_error& error) { file.close(); delete[] block; boost::unique_lock<boost::shared_mutex> lockit(tMutex); transfering = false; gDebug->Log("Local file %s transfer error: %s", filename.c_str(), error.what()); return; } int file_crc = addonHash::crc32_file(filename); if(file_crc == remote_file_crc) { gDebug->Log("Local file %s transfer completed (CRC: %i)", filename.c_str(), file_crc); } else { gDebug->Log("Local file %s transfer error (Final CRC check fail [L:%i != R:%i])", filename.c_str(), file_crc, remote_file_crc); } gDebug->Log("Local file transfer cycle completed"); boost::unique_lock<boost::shared_mutex> lockit(tMutex); transfering = false; }
void addonTransfer::sendFileThread(std::string filename, std::size_t file_size, int file_crc) { boost::this_thread::sleep(boost::posix_time::seconds(1)); std::ifstream file(filename.c_str(), (std::ifstream::in | std::ifstream::binary)); std::size_t bytes_tx = NULL; char *block = new char[file_size + 1]; memset(block, NULL, file_size); try { file.seekg(std::ifstream::beg); file.read(block, file_size); bytes_tx = boost::asio::write(s, boost::asio::buffer(block, file_size), boost::asio::transfer_exactly(file_size)); file.close(); delete[] block; } catch(boost::system::system_error& error) { file.close(); delete[] block; boost::unique_lock<boost::shared_mutex> lockit(tMutex); transfering = false; gDebug->Log("Remote file %s transfer error: %s", filename.c_str(), error.what()); return; } if(bytes_tx == file_size) { gDebug->Log("Remote file transfer completed (%i bytes transfered)", bytes_tx); } else { gDebug->Log("Remote file transfer error (%i bytes of %i processed)", bytes_tx, file_size); } gDebug->Log("Remote file transfer cycle completed"); boost::unique_lock<boost::shared_mutex> lockit(tMutex); transfering = false; }
void lockPsgQ(const char *dir) { char lockPath[MAXSTR]; char idPath[MAXSTR]; const char *lockname = "lockPsgQ"; time_t lockSecs = 5; /* default lock timeout */ sprintf(lockPath,"%s/%s",dir,lockname); sprintf(idPath,"%s/pq_%d",dir,getpid()); lockit(lockPath,idPath,lockSecs); }
void lockAtcmd(const char *dir) { char lockPath[MAXSTR]; char idPath[MAXSTR]; time_t lockSecs = 5; /* default lock timeout */ const char *lockname = "lockAtcmd"; sprintf(lockPath,"%s/acqqueue/%s",dir,lockname); sprintf(idPath,"%s/acqqueue/pq_%d",dir,getpid()); lockit(lockPath,idPath,lockSecs); }
void TomographyIfacePresenter::processRefreshJobs() { if (m_model->loggedIn().empty()) return; const std::string &comp = m_view->currentComputeResource(); m_model->doRefreshJobsInfo(comp); { // update widgets from that info QMutexLocker lockit(m_statusMutex); m_view->updateJobsInfoDisplay(m_model->jobsStatus()); } }
/***************************************************** get a variable from the shared area *******************************************************/ char *smbw_getshared(const char *name) { int i; struct stat st; char *var; lockit(); /* maybe the area has changed */ if (fstat(shared_fd, &st)) goto failed; if (st.st_size != shared_size) { var = (char *)Realloc(variables, st.st_size, True); if (!var) goto failed; else variables = var; shared_size = st.st_size; lseek(shared_fd, 0, SEEK_SET); if (read(shared_fd, variables, shared_size) != shared_size) { goto failed; } } unlockit(); i=0; while (i < shared_size) { char *n, *v; int l1, l2; l1 = SVAL(&variables[i], 0); l2 = SVAL(&variables[i], 2); n = &variables[i+4]; v = &variables[i+4+l1]; i += 4+l1+l2; if (strcmp(name,n)) { continue; } return v; } return NULL; failed: DEBUG(0,("smbw: shared variables corrupt (%s)\n", strerror(errno))); exit(1); return NULL; }
void addonTransfer::recvFile(std::string filename, std::size_t remote_file_size, int remote_file_crc) { boost::upgrade_lock<boost::shared_mutex> lockit(tMutex); if(transfering) { return; // already started } else { boost::upgrade_to_unique_lock<boost::shared_mutex> lockit_(lockit); transfering = true; } tHandle = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&addonTransfer::recvFileThread, this, filename, remote_file_size, remote_file_crc))); }
qryproc() { register QTREE *root; register QTREE *q; register int i; register int mode; register int result_num; register int retr_uniq; extern long AAccuread; extern long AAccuwrite; extern long AAccusread; extern int derror(); extern QTREE *trbuild(); extern QTREE *readqry(); # ifdef xDTM if (AAtTf(76, 1)) timtrace(23, 0); # endif # ifdef xDTR1 if (AAtTf(50, 0)) AAccuread = AAccusread = AAccuwrite = 0; # endif /* initialize query buffer */ initbuf(Qbuf, QBUFSIZ, QBUFFULL, derror); /* init various variables in decomp for start of this query */ startdecomp(); /* Read in query, range table and mode */ root = readqry(); mode = Qmode; /* Initialize relation descriptors */ initdesc(mode); /* re-build the tree */ root = trbuild(root); if (!root) derror(STACKFULL); /* locate pointers to QLEND and TREE nodes */ for (q = root->right; q->sym.type != QLEND; q = q->right) continue; Qle = q; for (q = root->left; q->sym.type != TREE; q = q->left) continue; Tr = q; /* map the complete tree */ mapvar(root, 0); /* set logical locks */ lockit(root, Resultvar); /* If there is no result variable then this must be a retrieve to the terminal */ Qry_mode = Resultvar < 0 ? (int) mdRETTERM : mode; /* if the mode is retrieve_unique, then make a result rel */ retr_uniq = mode == (int) mdRET_UNI; if (retr_uniq) { mk_unique(root); mode = (int) mdRETR; } /* get id of result relation */ if (Resultvar < 0) result_num = NORESULT; else result_num = Rangev[Resultvar].relnum; /* evaluate aggregates in query */ aggregate(root); /* decompose and process aggregate free query */ decomp(root, mode, result_num); /* If this is a retrieve unique, then retrieve results */ if (retr_uniq) pr_unique(root, Resultvar); if (mode != (int) mdRETR) i = ACK; else i = NOACK; i = endovqp(i); /* call update processor if batch mode */ if (i == UPDATE) { initp(); call_dbu(mdUPDATE, -1); } /* ** send eop back to parser to indicate completion ** if UPDATE then return block comes from dbu else ** return block comes from decomp */ writeback(i == UPDATE ? -1 : 1); # ifdef xDTM if(AAtTf(76, 1)) timtrace(24, 0); # endif # ifdef xDTR1 AAtTfp(50, 1, "DECOMP read %ld pages,%ld catalog pages,wrote %ld pages\n", AAccuread, AAccusread, AAccuwrite); # endif /* clean decomp */ reinit(); /* return */ }
void bill_done(SHR_EXP_INFO ExpInfo) { const char root_end[]="</accounting>\n"; char tmpStr[80],*tmpPtr; char inputPath[MAXPATHL]; int bufSize=4095; char buf[bufSize+1]; int i,n; FILE *inputFd=NULL; char lockPath[MAXPATHL]; char idPath[MAXPATHL]; char idFile[MAXPATHL]; char accFile[MAXPATHL]; time_t lockSecs = 2; /* default lock timeout */ char t_format[] = "%a %b %d %T %Z %Y"; FILE *xmlFd; if (ExpInfo->Billing.wroteRecord != 0) return; strcpy(lockPath, getenv("vnmrsystem") ); strcat(lockPath,"/adm/accounting/"); strcpy(accFile, lockPath); strcat(accFile,"acctLog.xml"); if ( access(accFile,F_OK) ) return; ExpInfo->Billing.doneTime = time(0); /* Lock the Log file so other instances of vnmrj cannot write at the same time. This is to lock the acctLog file. */ strcpy(idPath, lockPath); strcat(lockPath, "acctLogLock"); sprintf(idFile, "acctLogLockId_%d", getpid()); strcat(idPath, idFile); lockit(lockPath, idPath, lockSecs); xmlFd = fopen(accFile,"r+"); if (xmlFd == NULL) { unlockit(lockPath,idPath); printf("Cannot (re-re)open '%s'\n",accFile); return; } /* find the closing /> at the end and put log info above that */ fseek(xmlFd,-strlen(root_end),SEEK_END); fprintf(xmlFd,"<entry type=\"gorecord\" account=\"%s\" operator=\"%s\"\n", ExpInfo->Billing.account, ExpInfo->Billing.Operator); fprintf(xmlFd," goflag=\"%d\" loc=\"%d\" result=\"%d\"\n", ExpInfo->GoFlag, ExpInfo->SampleLoc, ExpInfo->ExpState); fprintf(xmlFd," seqfil=\"%s\"\n",ExpInfo->Billing.seqfil); i=0; n=sizeof(tmpStr); // strncpy(tmpStr,ctime(&(ExpInfo->Billing.submitTime)),n-1); strftime(tmpStr,n-1, t_format, localtime(&(ExpInfo->Billing.submitTime))); tmpPtr = tmpStr; // remove <lf> from submitTime while ( *tmpPtr != '\0' && i<n) { if ( *tmpPtr == '\n') *tmpPtr='\0'; tmpPtr++; i++; } fprintf(xmlFd," submit=\"%s\"\n",tmpStr); // strncpy(tmpStr,ctime(&(ExpInfo->Billing.startTime)),n-1); strftime(tmpStr,n-1, t_format, localtime(&(ExpInfo->Billing.startTime))); tmpPtr = tmpStr; // remove <lf> from startTime i=0; while ( *tmpPtr != '\0' && i<n) { if ( *tmpPtr == '\n') *tmpPtr='\0'; tmpPtr++; i++; } fprintf(xmlFd," start=\"%s\"\n",tmpStr); fprintf(xmlFd," startsec=\"%ld\"\n",ExpInfo->Billing.startTime); // strncpy(tmpStr,ctime( &(ExpInfo->Billing.doneTime)),n-1); strftime(tmpStr,n-1, t_format, localtime(&(ExpInfo->Billing.doneTime))); tmpPtr = tmpStr; // remove <lf> from doneTime i=0; while ( *tmpPtr != '\0' && i<n ) { if ( *tmpPtr == '\n') *tmpPtr='\0'; tmpPtr++; i++; } fprintf(xmlFd," end=\"%s\"\n",tmpStr); fprintf(xmlFd," endsec=\"%ld\"\n",ExpInfo->Billing.doneTime); // Write optional params /* - Open file .../[go_id].loginfo */ sprintf(inputPath, "/vnmr/acqqueue/%s.loginfo", ExpInfo->Billing.goID); inputFd = fopen(inputPath, "r"); if(inputFd != NULL) { /* Get the optional param info */ int size = fread(buf, 1, bufSize, inputFd); /* Terminate the buffer */ buf[size] = 0; /* Write to the log file */ fprintf(xmlFd,"%s",buf); fclose(inputFd); } fprintf(xmlFd,"/>\n"); fprintf(xmlFd,"%s",root_end); fflush(xmlFd); fclose(xmlFd); unlink(inputPath); ExpInfo->Billing.wroteRecord = 1; unlockit(lockPath,idPath); }
/* * idx_find_entry() * * Find an entry in the index file. * * Input: * file Name of database file (text version). * ntracks Number of tracks on the CD we're looking for. * tracks Array of track start times. * len CD length in frames. * fuzz Fuzz factor (tolerance value). * pos Pointer to return value. * * Output: * 1 No matching record found. * 0 Record found; *pos contains offset into text file. * -1 Index file out of date or inaccessible, or another error. */ int idx_find_entry( char *file, int ntracks, int *tracks, int len, int fuzz, unsigned long *pos ) { unsigned long dbpos; char *indexname = NULL, keyval[8]; int c; FILE *text; DB *index; DBT key, data; BTREEINFO bti; /* * First, see if the text file is accessible. Lock it if so. */ text = fopen(file, "r"); if (text == NULL) return (-1); if ((c = getc(text)) == EOF) { fclose(text); return (-1); } if (! suppress_locking) if (lockit(fileno(text), F_RDLCK)) { fclose(text); return (-1); } /* * Open the index file. */ indexname = malloc(strlen(file) + sizeof(".ind")); if (indexname == NULL) { fclose(text); return (-1); } strcpy(indexname, file); strcat(indexname, ".ind"); bti.flags = 0; bti.cachesize = 0; bti.minkeypage = bti.maxkeypage = 0; bti.psize = bti.lorder = 0; bti.compare = NULL; bti.prefix = NULL; index = dbopen(indexname, O_RDONLY, 0666, DB_BTREE, &bti); free(indexname); if (index == NULL) { fclose(text); return (-1); } /* * Search for the first matching entry. */ sprintf(keyval, "%07d", tracks[ntracks - 1] - fuzz); key.data = keyval; key.size = 7; if (c = (index->seq)(index, &key, &data, R_CURSOR)) { (index->close)(index); fclose(text); return (c); } /* * Now loop through all the possible matches, collecting them into * memory. */ do { char tracksline[750], *s; int i, val; /* Hit the end of the valid entries? */ sscanf(key.data, "%d", &val); if (val > tracks[ntracks - 1] + fuzz) break; dbpos = ntohl(*((unsigned long *) data.data)); if (fseek(text, dbpos, 0)) break; fgets(tracksline, sizeof(tracksline), text); if (strncmp(tracksline, "tracks ", 7)) break; (void) strtok(tracksline, " \t"); /* Got a valid tracks line. See if it matches the CD. */ s = strtok(NULL, " \t"); if (s == NULL) break; if (atoi(s) != ntracks) continue; for (i = 0; i < ntracks; i++) { s = strtok(NULL, " \t"); if (s == NULL) break; val = atoi(s); if (val + fuzz < tracks[i] || val - fuzz > tracks[i]) break; } if (i != ntracks) continue; s = strtok(NULL, " \t"); if (s == NULL) continue; val = atoi(s); if (val + fuzz / 75 < len / 75 || val + fuzz / 75 > len / 75) continue; /* XXX - add to sorted list! */ *pos = dbpos; (index->close)(index); fclose(text); return (0); } while ((c = (index->seq)(index, &key, &data, R_NEXT)) == 0); if (c == 0) { /* An error. */ (index->close)(index); fclose(text); return (-1); } (index->close)(index); fclose(text); return (1); }
bool isTransfering() { boost::shared_lock<boost::shared_mutex> lockit(tMutex); return transfering; }
int autoq(int argc, char *argv[], int retc, char *retv[]) { char autodir[MAXPATH]; char lockPath[MAXPATH]; char idPath[MAXPATH]; char lockLogPath[MAXPATH]; char idLogPath[MAXPATH]; char logBasePath[MAXPATH]; char *blockname = "autoqBlock"; char *lockname = "lockEnterQ"; time_t lockSecs = 5; /* default lock timeout */ int res = 1; if (argc < 2) { Werrprintf("usage: %s requires add, get, lock, unlock, sendmsg, or recvmsg argument", argv[0]); ABORT; } if ( !strcmp(argv[1],"sendmsg") || !strcmp(argv[1],"recvmsg") ) { res = 4; } else { #ifdef VNMRJ if ( ! strcmp(argv[1],"add") ) P_getstring(GLOBAL,"autodir",autodir,1,MAXPATH); else #endif getAutoDir(autodir, MAXPATH); sprintf(lockPath,"%s/%s",autodir,lockname); sprintf(idPath,"%s/eq_%s_%s_%d",autodir,HostName,UserName,HostPid); } if ( ! strcmp(argv[1],"add") ) { char queuename[MAXPATH]; if (argc < 3) { Werrprintf("usage: %s('add',filename) requires a filename.",argv[0]); ABORT; } if (argc == 4) strcpy(queuename,argv[3]); else strcpy(queuename,"std"); /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); if ( lockit(lockPath,idPath,lockSecs) ) { res = addQueueFile(autodir, argv[2], queuename); unlockit(lockPath,idPath); } else { res = -4; } } else if ( ! strcmp(argv[1],"get") ) { FILE *fd; char blockfile[MAXPATH]; if (argc < 3) { Werrprintf("usage: %s('get',filename) requires a filename.",argv[0]); ABORT; } /* The get operation will block add and lock from other processes */ sprintf(blockfile,"%s/%s",autodir,blockname); fd = fopen(blockfile,"w"); fclose(fd); if ( lockit(lockPath,idPath,lockSecs) ) { res = getQueueFile(autodir, argv[2]); unlockit(lockPath,idPath); } else { res = -4; } #ifdef TESTING if (argc == 4) sleepnano(atoi(argv[3])); #endif /* Allow access by add and lock from other processes */ unlink(blockfile); } else if ( ! strcmp(argv[1],"lock") ) { if (argc == 3) { lockSecs = atoi(argv[2]); if (lockSecs < 1) lockSecs = 1; else if (lockSecs > 15) lockSecs = 15; } /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); DPRINT1("lock called with %ld timeout\n",lockSecs); res = lockit(lockPath,idPath,lockSecs); } else if ( ! strcmp(argv[1],"unlock") ) { unlockit(lockPath,idPath); res = 1; } else if ( ! strcmp(argv[1],"addAcct") ) { char accFile[MAXPATH]; char idFile[MAXPATH]; if (argc != 3) { Werrprintf("autoq('addAcct',filename) requires filename as the second argument"); ABORT; } if ( access(argv[2], R_OK|W_OK) ) { Werrprintf("autoq('addAcct',filename) filename does not exist or has wrong permissions"); ABORT; } res = 0; strcpy(lockPath, getenv("vnmrsystem") ); strcat(lockPath,"/adm/accounting/"); strcpy(accFile, lockPath); strcat(accFile,"acctLog.xml"); if ( !access(accFile,F_OK) ) { FILE *inputFd; int bufSize=4095; char buf[bufSize+1]; int size = 0; inputFd = fopen(argv[2],"r"); if (inputFd) { size = fread(buf, 1, bufSize, inputFd); /* Terminate the buffer */ buf[size] = 0; fclose(inputFd); } unlink(argv[2]); if (size) { lockSecs = 2; // Create filepaths for the lock files to lock acctLog strcpy(idPath, lockPath); strcat(lockPath, "acctLogLock"); sprintf(idFile, "acctLogLockId_%s_%d", HostName, HostPid); strcat(idPath, idFile); DPRINT1("lock called with %ld timeout\n",lockSecs); if ( lockit(lockPath,idPath,lockSecs) ) { const char root_end[]="</accounting>\n"; FILE *xmlFd; xmlFd = fopen(accFile,"r+"); if (xmlFd) { /* find the closing /> at the end and put log info above that */ fseek(xmlFd,-strlen(root_end),SEEK_END); /* Write to the log file */ fprintf(xmlFd,"%s",buf); fprintf(xmlFd,"%s",root_end); fflush(xmlFd); fclose(xmlFd); } unlockit(lockPath,idPath); res = 1; } } } } else if ( ! strcmp(argv[1],"locklog") ) { lockSecs = 15; // Create filepaths for the lock files to lock acctLog strcpy(logBasePath, (char *)getenv("vnmrsystem") ); strcat(logBasePath,"/adm/accounting/"); sprintf(lockLogPath, "%s%s", logBasePath, "acctLogLock"); sprintf(idLogPath, "%sacctLogLockId_%s_%d", logBasePath, HostName, HostPid); /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); DPRINT1("lock called with %ld timeout\n",lockSecs); res = lockit(lockLogPath,idLogPath,lockSecs); } else if ( ! strcmp(argv[1],"unlocklog") ) { // Create filepaths for the lock files to lock acctLog strcpy(logBasePath, (char *)getenv("vnmrsystem") ); strcat(logBasePath,"/adm/accounting/"); sprintf(lockLogPath, "%s%s", logBasePath, "acctLogLock"); sprintf(idLogPath, "%sacctLogLockId_%s_%d", logBasePath, HostName, HostPid); unlockit(lockLogPath,idLogPath); res = 1; } else if (res == 4) /* ( !strcmp(argv[1],"sendmsg") || !strcmp(argv[1],"recvmsg") ) */ { if ( ! strcmp(argv[1],"recvmsg") ) { if ( (argc != 3) || ( strcmp(argv[2],"on") && strcmp(argv[2],"off")) ) { Werrprintf("autoq %s requires 'on' or 'off' as the second argument",argv[1]); ABORT; } } if (argc != 3) { Werrprintf("autoq %s requires another argument",argv[1]); ABORT; } res = 1; if (is_acqproc_active()) { char msg[MAXSTR]; sprintf(msg,"%s %s",argv[1],argv[2]); if (send2Acq(AUTOQMSG, msg) < 0) res = 0; if (res) receivingMsg = ( ! strcmp(argv[2],"on")); } } DPRINT1("operation returns %d\n",res); if (retc) { retv[0] = intString(res); } RETURN; }