Exemplo n.º 1
0
static int
fsync_with_status(stream_with_status_t* s) 
{
  ASSERT(s);

  if (s->fp == NULL || s->why != WHY_OK) {
    return 0;
  }

  int fd = fileno(s->fp);
  if (fd >= 0) {

    /* XXX:  this maintains the same semantics as the original code --
       that is, not detecting a failure if s->fp has an invalid
       fileno.  Whether or not this is the right thing to do, it's at
       least backwards-compatible. */

	if (condor_fsync(fd) < 0) {
	  s->why = WHY_FSYNC;
	  s->err = errno;
	  return -1;
	}
  }
  return 0;
}
Exemplo n.º 2
0
void
ClassAdLog::AppendLog(LogRecord *log)
{
	if (active_transaction) {
		if (active_transaction->EmptyTransaction()) {
			LogBeginTransaction *l = new LogBeginTransaction;
			active_transaction->AppendLog(l);
		}
		active_transaction->AppendLog(log);
	} else {
			//MD: using file pointer
		if (log_fp!=NULL) {
			if (log->Write(log_fp) < 0) {
				EXCEPT("write to %s failed, errno = %d", logFilename(), errno);
			}
			if( m_nondurable_level == 0 ) {
					//MD: flushing data -- using a file pointer
				if (fflush(log_fp) !=0){
					EXCEPT("flush to %s failed, errno = %d", logFilename(), errno);
				}
					//MD: syncing the data as done before
				if (condor_fsync(fileno(log_fp)) < 0) {
					EXCEPT("fsync of %s failed, errno = %d", logFilename(), errno);
				}
			}
		}
		log->Play((void *)&table);
		delete log;
	}
}
Exemplo n.º 3
0
void
ClassAdLog::LogState(FILE *fp)
{
	LogRecord	*log=NULL;
	ClassAd		*ad=NULL;
	ExprTree	*expr=NULL;
	HashKey		hashval;
	MyString	key;
	const char	*attr_name = NULL;

	// This must always be the first entry in the log.
	log = new LogHistoricalSequenceNumber( historical_sequence_number, m_original_log_birthdate );
	if (log->Write(fp) < 0) {
		EXCEPT("write to %s failed, errno = %d", logFilename(), errno);
	}
	delete log;

	table.startIterations();
	while(table.iterate(ad) == 1) {
		table.getCurrentKey(hashval);
		hashval.sprint(key);
		log = new LogNewClassAd(key.Value(), ad->GetMyTypeName(), ad->GetTargetTypeName());
		if (log->Write(fp) < 0) {
			EXCEPT("write to %s failed, errno = %d", logFilename(), errno);
		}
		delete log;
			// Unchain the ad -- we just want to write out this ads exprs,
			// not all the exprs in the chained ad as well.
		AttrList *chain = dynamic_cast<AttrList*>(ad->GetChainedParentAd());
		ad->Unchain();
		ad->ResetName();
		attr_name = ad->NextNameOriginal();
		while (attr_name) {
			expr = ad->LookupExpr(attr_name);
				// This conditional used to check whether the ExprTree is
				// invisible, but no codepath sets any attributes
				// invisible for this call.
			if (expr) {
				log = new LogSetAttribute(key.Value(), attr_name,
										  ExprTreeToString(expr));
				if (log->Write(fp) < 0) {
					EXCEPT("write to %s failed, errno = %d", logFilename(),
						   errno);
				}
				delete log;
			}
			attr_name = ad->NextNameOriginal();
		}
			// ok, now that we're done writing out this ad, restore the chain
		ad->ChainToAd(chain);
	}
	if (fflush(fp) !=0){
	  EXCEPT("fflush of %s failed, errno = %d", logFilename(), errno);
	}
	if (condor_fsync(fileno(fp)) < 0) {
		EXCEPT("fsync of %s failed, errno = %d", logFilename(), errno);
	} 
}
Exemplo n.º 4
0
void
ClassAdLog::ForceLog()
{
	// Force log changes to disk.  This involves first flushing
	// the log from memory buffers, then fsyncing to disk.
	if (log_fp!=NULL) {

		// First flush
		FlushLog();

		// Then sync
		if (condor_fsync(fileno(log_fp)) < 0) {
			EXCEPT("fsync of %s failed, errno = %d", logFilename(), errno);
		}

	}
}