History::History(unsigned id) { m_contact = id; Contact *contact = getContacts()->contact(id); if (contact == NULL) return; HistoryFile *f = new HistoryFile(number(id).c_str(), id); if (f->isOpen()){ files.push_back(f); }else{ delete f; } void *data; ClientDataIterator it(contact->clientData); while ((data = ++it) != NULL){ string name = it.client()->dataName(data); HistoryFile *f = new HistoryFile(name.c_str(), id); f->m_name = name; if (f->isOpen()){ files.push_back(f); }else{ delete f; } } }
History::History(unsigned id) : m_contact (id) { Contact *contact = getContacts()->contact(id); if (contact == NULL) return; HistoryFile *f = new HistoryFile(QString::number(id), id); if (f->isOpen()) files.push_back(f); else delete f; void *data; ClientDataIterator it = contact->clientDataIterator(); QStringList fnames; while ((data = ++it) != NULL) { QString name = it.client()->dataName(data); if(fnames.contains(name)) continue; fnames.append(name); HistoryFile *f = new HistoryFile(name, id); f->m_name = name; if (f->isOpen()) files.push_back(f); else delete f; } }
/** * Process the current history file. * * 1) check to see if it is properly initialized, recording id (inode) * 2) stat the current history file * 3) poll for new entries and process them * 4) detect rotations */ void aviary::history::processCurrentHistory() { static MyString currentHistoryFilename = m_path + DIR_DELIM_STRING + "history"; static HistoryFile currentHistory ( currentHistoryFilename.Value() ); CondorError errstack; if (force_reset) { currentHistory.cleanup(); } // (1) long unsigned int id; if ( !currentHistory.getId ( id ) || force_reset) { // at this point adjust the reset flag force_reset = false; if ( !currentHistory.init ( errstack ) ) { dprintf ( D_ALWAYS, "%s\n", errstack.getFullText().c_str() ); return; } ASSERT ( currentHistory.getId ( id ) ); m_historyFiles.insert ( id ); } // (2) // Stat before poll to handle race of: poll + write + rotate + stat StatWrapper stat_wrapper; if ( stat_wrapper.Stat ( currentHistoryFilename ) ) { dprintf ( D_ALWAYS, "Failed to stat %s: %d (%s)\n", currentHistoryFilename.Value(), stat_wrapper.GetErrno(), strerror ( stat_wrapper.GetErrno() ) ); return; } const StatStructType *stat = stat_wrapper.GetBuf(); ASSERT ( currentHistory.getId ( id ) ); // (3) errstack.clear(); HistoryFile::HistoryEntriesTypeIterators poll = currentHistory.poll ( errstack ); for ( HistoryFile::HistoryEntriesTypeIterator i = poll.first; i != poll.second; i++ ) { process ( ( *i ) ); } // (4) // If different the file has rotated if ( id != stat->st_ino ) { currentHistory = HistoryFile ( currentHistoryFilename.Value() ); if ( !currentHistory.init ( errstack ) ) { dprintf ( D_ALWAYS, "%s\n", errstack.getFullText().c_str() ); return; } ASSERT ( currentHistory.getId ( id ) ); m_historyFiles.insert ( id ); force_reset = true; return; } }