예제 #1
0
void KInotifyTest::testFileClosedAfterWrite()
{
    QTemporaryDir dir;
    touchFile(dir.path() + QLatin1String("/file"));

    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    QSignalSpy spy(&kn, SIGNAL(closedWrite(QString)));
    touchFile(dir.path() + QLatin1String("/file"));

    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    QCOMPARE(spy.at(0).first().toString(), QString(dir.path() + QLatin1String("/file")));
}
예제 #2
0
void ProxyLogger::log() {
  std::vector<stat_t> stats(num_stats);
  try {
    proxy_->router->startupLock.wait();
    std::lock_guard<ShutdownLock> lg(proxy_->router->shutdownLock());
    std::lock_guard<std::mutex> guard(proxy_->stats_lock);

    prepare_stats(proxy_, stats.data());
  } catch (const shutdown_started_exception& e) {
    return;
  }

  for (int i = 0; i < num_stats; ++i) {
    if (stats[i].group & rate_stats) {
      stats[i].type = stat_double;
      stats[i].data.dbl = stats_rate_value(proxy_, i);
    }
  }

  write_stats_to_disk(proxy_, stats);
  write_config_sources_info_to_disk(proxy_);

  for (const auto& filepath : touchStatsFilepaths_) {
    touchFile(filepath);
  }

  if (additionalLogger_) {
    additionalLogger_->log(stats);
  }
}
예제 #3
0
void McrouterLogger::log() {
  std::vector<stat_t> stats(num_stats);
  prepare_stats(router_, stats.data());

  for (int i = 0; i < num_stats; ++i) {
    if (stats[i].group & rate_stats) {
      stats[i].type = stat_double;
      stats[i].data.dbl = stats_aggregate_rate_value(router_, i);
    } else if (stats[i].group & max_stats) {
      stats[i].type = stat_uint64;
      stats[i].data.uint64 = stats_aggregate_max_value(router_, i);
    }
  }

  write_stats_to_disk(router_.opts(), stats);
  write_config_sources_info_to_disk(router_);

  for (const auto& filepath : touchStatsFilepaths_) {
    touchFile(filepath);
  }

  if (additionalLogger_) {
    additionalLogger_->log(stats);
  }
}
예제 #4
0
void KInotifyTest::testRenameFolder()
{
    // create some test files
    QTemporaryDir dir;
    const QString f1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
    mkdir(f1);

    // start the inotify watcher
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    // listen to the desired signal
    QSignalSpy spy(&kn, SIGNAL(moved(QString,QString)));

    // actually move the file
    const QString f2(QStringLiteral("%1/randomJunk2").arg(dir.path()));
    QFile::rename(f1, f2);

    // check the desired signal
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    QList<QVariant> args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), f1);
    QCOMPARE(args.at(1).toString(), f2);

    // check the path cache
    QVERIFY(!kn.watchingPath(f1));
    QVERIFY(kn.watchingPath(f2));

    // test a subsequent rename
    const QString f3(QStringLiteral("%1/randomJunk3").arg(dir.path()));
    QFile::rename(f2, f3);

    // check the desired signal
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), f2);
    QCOMPARE(args.at(1).toString(), f3);

    // check the path cache
    QVERIFY(!kn.watchingPath(f1));
    QVERIFY(!kn.watchingPath(f2));
    QVERIFY(kn.watchingPath(f3));


    // KInotify claims it has updated its data structures, lets see if that is true
    // by creating a file in the new folder
    // listen to the desired signal
    const QString f4(QStringLiteral("%1/somefile").arg(f3));

    QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool)));

    // test creating a file
    touchFile(f4);

    QVERIFY(createdSpy.wait());
    QCOMPARE(createdSpy.count(), 1);
    QCOMPARE(createdSpy.takeFirst().at(0).toString(), f4);
}
예제 #5
0
void KInotifyTest::testCreateFolder()
{
    QTemporaryDir dir;

    // start the inotify watcher
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    // listen to the desired signal
    QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool)));

    // create the subdir
    const QString d1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
    mkdir(d1);
    QVERIFY(createdSpy.wait());
    QCOMPARE(createdSpy.count(), 1);
    QCOMPARE(createdSpy.takeFirst().at(0).toString(), d1);
    QVERIFY(kn.watchingPath(d1));

    // lets go one level deeper
    const QString d2 = QStringLiteral("%1/subdir1").arg(d1);
    mkdir(d2);
    QVERIFY(createdSpy.wait());
    QCOMPARE(createdSpy.count(), 1);
    QCOMPARE(createdSpy.takeFirst().at(0).toString(), d2);
    QVERIFY(kn.watchingPath(d2));

    // although we are in the folder test lets try creating a file
    const QString f1 = QStringLiteral("%1/somefile1").arg(d2);
    touchFile(f1);
    QVERIFY(createdSpy.wait());
    QCOMPARE(createdSpy.count(), 1);
    QCOMPARE(createdSpy.takeFirst().at(0).toString(), f1);
}
예제 #6
0
/******************************************************************************
* Main
*
* Main application routine. Really all this does is sets things up and waits
* for the dbus messages...
* 
*******************************************************************************/
int main(int argc, char *argv[])
{
	
	
	if (fileExists(LOCKFILE)) {
		printf("App already running, aborting\n");
		exit(0);
	} else {
		//Create the lockfile
		touchFile(LOCKFILE);
	}
	
	initializeApp();
	
	//Add the failsafe exit timeout to make sure the app doesn't run forever
	g_timeout_add(600000, (GSourceFunc) quitApp, NULL);
	
	//Setup a sync call just to be safe since Dbus doesn't always get through the first time...
	//g_timeout_add(10, (GSourceFunc) handleAlarmsSync, NULL);
	
	//Run the main loop
	g_main_loop_run(mainLoopObj);
    

    return 0;



}
예제 #7
0
void KInotifyTest::testDeleteFile()
{
    // create some test files
    QTemporaryDir dir;
    const QString f1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
    touchFile(f1);

    // start the inotify watcher
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    // listen to the desired signal
    QSignalSpy spy(&kn, SIGNAL(deleted(QString,bool)));

    // test removing a file
    QFile::remove(f1);
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    QCOMPARE(spy.takeFirst().at(0).toString(), f1);
}
예제 #8
0
void KInotifyTest::testMoveFile()
{
    // create some test files
    QTemporaryDir dir1;
    QTemporaryDir dir2;
    const QString src(QStringLiteral("%1/randomJunk1").arg(dir1.path()));
    const QString dest(QStringLiteral("%1/randomJunk2").arg(dir2.path()));
    touchFile(src);

    // start the inotify watcher
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir1.path(), KInotify::EventAll);
    kn.addWatch(dir2.path(), KInotify::EventAll);

    // listen to the desired signal
    QSignalSpy spy(&kn, SIGNAL(moved(QString,QString)));

    // actually move the file
    QFile::rename(src, dest);

    // check the desired signal
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    QList<QVariant> args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), src);
    QCOMPARE(args.at(1).toString(), dest);

    // test a subsequent move (back to the original folder)
    const QString dest2(QStringLiteral("%1/randomJunk3").arg(dir1.path()));
    QFile::rename(dest, dest2);

    // check the desired signal
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), dest);
    QCOMPARE(args.at(1).toString(), dest2);
}
예제 #9
0
void KInotifyTest::testRenameFile()
{
    // create some test files
    QTemporaryDir dir;
    const QString f1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
    touchFile(f1);

    // start the inotify watcher
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    // listen to the desired signal
    QSignalSpy spy(&kn, SIGNAL(moved(QString,QString)));

    // actually move the file
    const QString f2(QStringLiteral("%1/randomJunk2").arg(dir.path()));
    QFile::rename(f1, f2);

    // check the desired signal
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    QList<QVariant> args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), f1);
    QCOMPARE(args.at(1).toString(), f2);

    // test a subsequent rename
    const QString f3(QStringLiteral("%1/randomJunk3").arg(dir.path()));
    QFile::rename(f2, f3);

    // check the desired signal
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), f2);
    QCOMPARE(args.at(1).toString(), f3);
}
예제 #10
0
int readAndSendEventRamdisk(char *headerLinkFilename) {
    static int errorCounter=0;
    AnitaEventHeader_t *theHeader;
    GenericHeader_t *gHdr;
    int retVal;
    char currentTouchname[FILENAME_MAX];
    char currentLOSTouchname[FILENAME_MAX];
    char waveFilename[FILENAME_MAX];
    char headerFilename[FILENAME_MAX];
//    char crapBuffer[FILENAME_MAX];
    char justFile[FILENAME_MAX];
    unsigned int thisEventNumber;
    

    //First up we test if the link still exists
    if(!checkFileExists(headerLinkFilename))
      return 0;
    
    retVal=snprintf(justFile,sizeof(justFile),"%s",basename(headerLinkFilename));
    if(retVal<0) {
      syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
    }
    retVal=sscanf(justFile,"hd_%u.dat",&thisEventNumber);
    if(retVal<=0) {
      syslog(LOG_ERR,"Error reading eventNumber from %s",justFile);
      thisEventNumber=0;
    }

    if(thisEventNumber==0) {
      printf("Why is this zero -- %s\n",headerLinkFilename);
    }

    retVal=snprintf(headerFilename,sizeof(headerFilename),"%s/hd_%d.dat",eventTelemDirs[currentPri],thisEventNumber);
    if(retVal<0) {
      syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
    }

    retVal=snprintf(waveFilename,sizeof(waveFilename),"%s/hd_%d.dat",eventTelemDirs[currentPri], thisEventNumber);
    if(retVal<0) {
      syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
    }

    retVal=snprintf(currentTouchname,sizeof(currentTouchname),"%s.sipd",headerFilename);
    if(retVal<0) {
      syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
    }

    retVal=snprintf(currentLOSTouchname,sizeof(currentLOSTouchname),"%s.losd",headerFilename);
    if(retVal<0) {
      syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
    }
    
    
    if(checkFileExists(currentLOSTouchname)) 
      return 0;
    touchFile(currentTouchname);
//    printf("%s\n",headerLinkFilename);
    removeFile(headerLinkFilename);

//     Next load header 
    theHeader=(AnitaEventHeader_t*) &theBuffer[0]; 
    retVal=fillHeader(theHeader,headerFilename); 
        
    if(retVal<0) {
//	syslog(LOG_ERR,"Problem with %s",headerFilename);
      retVal=snprintf(headerFilename,sizeof(headerFilename),"%s/hd_%d.dat",eventTelemDirs[currentPri],thisEventNumber);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      
      unlink(currentTouchname);
      unlink(headerFilename);
      unlink(waveFilename);
      
      //Bollocks
      return 0;
    }
    
    
    theHeader->gHdr.packetNumber=getOpenportNumber();
    retVal = openportWrite((unsigned char*)theHeader,sizeof(AnitaEventHeader_t),0);
    if(retVal<0) {
	//Problem sending data
	syslog(LOG_ERR,"Problem sending file %s over Openport\n",headerFilename);
	fprintf(stderr,"Problem sending file %s over Openport\n",headerFilename);	
    }
    eventDataSent+=sizeof(AnitaEventHeader_t);
    
    
    thisEventNumber=theHeader->eventNumber;
    

    //Now get event file
    retVal=snprintf(headerFilename,sizeof(headerFilename),"%s/hd_%d.dat",eventTelemDirs[currentPri], thisEventNumber);
    if(retVal<0) {
      syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
    }
    retVal=snprintf(waveFilename,sizeof(waveFilename),"%s/ev_%d.dat",eventTelemDirs[currentPri], thisEventNumber);
    if(retVal<0) {
      syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
    }


    retVal=genericReadOfFile((unsigned char*)theBuffer,waveFilename,MAX_EVENT_SIZE);
    if(retVal<0) {
	fprintf(stderr,"Problem reading %s\n",waveFilename);
	syslog(LOG_ERR,"Problem reading %s\n",waveFilename);

//	unlink(headerLinkFilename);
	unlink(headerFilename);
	unlink(waveFilename);	
	unlink(currentTouchname);
	//Bollocks
	return 0;
    }


    //Okay so now the buffer either contains EncodedSurfPacketHeader_t or
    // it contains EncodedPedSubbedSurfPacketHeader_t
    gHdr = (GenericHeader_t*) &theBuffer[0];
    switch(gHdr->code) {
	case PACKET_BD:
	    if(sendWavePackets)
		retVal=sendRawWaveformPackets(retVal);
	    else 
		retVal=sendRawSurfPackets(retVal);
	    break;
	case PACKET_PED_SUBBED_EVENT:
	    if(sendWavePackets)
		retVal=sendPedSubbedWaveformPackets(retVal);
	    else
		retVal=sendPedSubbedSurfPackets(retVal);
	    break;
	case PACKET_ENC_EVENT_WRAPPER:
	    retVal=sendEncodedSurfPackets(retVal);
	    break;
	case PACKET_ENC_PEDSUB_EVENT_WRAPPER:
	    if(!sendWavePackets) {
		retVal=sendEncodedPedSubbedSurfPackets(retVal);
	    }
	    else {
		retVal=sendEncodedPedSubbedWavePackets(retVal);
	    }
	    break;
	default:
	    if(errorCounter<100) {
		syslog(LOG_ERR,"Don't know what to do with packet %d -- %s (Message %d of 100)\n",gHdr->code,packetCodeAsString(gHdr->code),errorCounter);
		errorCounter++;
	    }
	    fprintf(stderr,"Don't know what to do with packet %d -- %s\n",gHdr->code,packetCodeAsString(gHdr->code));
    }
    


    
    if(printToScreen && verbosity>1) 
	printf("Removing files %s\t%s\n%s\n",headerFilename,waveFilename,
	       headerLinkFilename);
	        
    if(!checkFileExists(currentLOSTouchname)) {
//	unlink(headerLinkFilename);
	unlink(headerFilename);
	unlink(waveFilename);
	unlink(currentTouchname);
    }
    else {
	sleep(1);
//	unlink(headerLinkFilename);
	unlink(headerFilename);
	unlink(waveFilename);
	unlink(currentTouchname);
	unlink(currentLOSTouchname);
    }

    return 1;

}
예제 #11
0
int readHkAndOpenport(int wd,int maxCopy, char *telemDir, char *linkDir, int fileSize, int *numSent) 
/* Looks in the specified directroy and OPENPORT's up to maxCopy bytes of data */
/* fileSize is the maximum size of a packet in the directory */
{
  //  fprintf(stderr,"readHkAndOpenport %s -- %d\n",linkDir,maxCopy);
  char currentFilename[FILENAME_MAX];
  char currentTouchname[FILENAME_MAX];
  char currentLOSTouchname[FILENAME_MAX];
  char currentLinkname[FILENAME_MAX];
  int retVal,numLinks,count,numBytes,totalBytes=0;//,checkVal=0;
  char *tempString;
  GenericHeader_t *gHdr; 
  *numSent=0;
    
  numLinks=getNumLinks(wd);
  if(numLinks<=0) {
	return 0;
  }

  int counter=0;
    for(count=numLinks-1;count>=0;count--) {
      //Get last link name
      tempString=getLastLink(wd);
      retVal=snprintf(currentFilename,sizeof(currentFilename),"%s/%s",telemDir,tempString);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      retVal=snprintf(currentTouchname,sizeof(currentTouchname),"%s.sipd",currentFilename);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      retVal=snprintf(currentLOSTouchname,sizeof(currentLOSTouchname),"%s.losd",currentFilename);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      retVal=snprintf(currentLinkname,sizeof(currentLinkname),"%s/%s",linkDir,tempString);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }

      if(!checkFileExists(currentLinkname))
	continue;

      if(checkFileExists(currentLOSTouchname)) 
	continue;
      
      touchFile(currentTouchname);
      
      if(checkFileExists(currentLOSTouchname)) {	  
	  unlink(currentTouchname);	  
	  continue;
      }

      retVal=genericReadOfFile((unsigned char*)theBuffer,
			       currentFilename,
			       MAX_EVENT_SIZE);

      syslog(LOG_DEBUG,"Trying %s",currentFilename);
      if(retVal<=0) {
	//	    syslog(LOG_ERR,"Error opening file, will delete: %s",
	//		   currentFilename);
	//	    fprintf(stderr,"Error reading file %s -- %d\n",currentFilename,retVal);
	unlink(currentFilename);	
	unlink(currentLinkname);
	unlink(currentTouchname);
	continue;
      }
      numBytes=retVal;

      if(printToScreen && verbosity>=0) {
	printf("Read File: %s -- (%d bytes)\n",currentFilename,numBytes);
      }
      

      //	printf("Read %d bytes from file\n",numBytes);
      //	Maybe I'll add a packet check here
      gHdr = (GenericHeader_t*)theBuffer;
      //	checkVal=checkPacket(gHdr);
      //	if(checkVal!=0 ) {
      //	    printf("Bad packet %s == %d\n",currentFilename,checkVal);
      //	}
      gHdr->packetNumber=getOpenportNumber();
      printf("Openport number %d\n",gHdr->packetNumber);
      retVal = openportWrite(theBuffer, numBytes,1);
      if(retVal<0) {
	//Problem sending data
	syslog(LOG_ERR,"Problem sending Wake up Packet over OPENPORT\n");
	fprintf(stderr,"Problem sending Wake up Packet over OPENPORT\n");	
      }
      
      totalBytes+=numBytes;
      
      if(!checkFileExists(currentLOSTouchname)) {
	unlink(currentLinkname);
	unlink(currentFilename);
	unlink(currentTouchname);
      }
      else {
	usleep(1);
	unlink(currentLinkname);
	unlink(currentFilename);
	unlink(currentTouchname);
	unlink(currentLOSTouchname);
      }
      (*numSent)++;

      
      //	if((totalBytes+fileSize)>maxCopy) break;
      counter++;
      if(counter>=maxCopy) break;
      //	break;
    }
    //    fprintf(stderr,"readHkAndOpenport %s -- %d\n",linkDir,*numSent);
    return totalBytes;
}
예제 #12
0
void readAndSendEventRamdisk(char *headerLinkFilename) {
  static int errorCounter=0;
  AnitaEventHeader_t *theHeader;
  GenericHeader_t *gHdr;
  int retVal;
  char waveFilename[FILENAME_MAX];
  char headerFilename[FILENAME_MAX];
  char currentTouchname[FILENAME_MAX];
  char currentLOSTouchname[FILENAME_MAX];
  char justFile[FILENAME_MAX];
  unsigned int thisEventNumber;
    
  sprintf(justFile,"%s",basename(headerLinkFilename));
  sscanf(justFile,"hd_%u.dat",&thisEventNumber);
  sprintf(headerFilename,"%s/hd_%d.dat",eventTelemDirs[currentPri], 
	  thisEventNumber);
  sprintf(waveFilename,"%s/psev_%d.dat",eventTelemDirs[currentPri], 
	  thisEventNumber);
    
  sprintf(currentTouchname,"%s.sipd",headerFilename);
  sprintf(currentLOSTouchname,"%s.losd",headerFilename);

  if(checkFileExists(currentTouchname)) 
    return;
  touchFile(currentLOSTouchname);
  //Removing headerLinkFilename
  //  fprintf(stderr,"Removing %s\n",headerLinkFilename);
  unlink(headerLinkFilename);



  //First check if there is room for the header
  if((LOS_MAX_BYTES-numBytesInBuffer)<sizeof(AnitaEventHeader_t))
    doWrite();

    
  //     Next load header 
  theHeader=(AnitaEventHeader_t*) &losBuffer[numBytesInBuffer]; 
  retVal=fillHeader(theHeader,headerFilename); 
  theHeader->gHdr.packetNumber=getLosNumber();
  numBytesInBuffer+=sizeof(AnitaEventHeader_t);

    
  if(retVal<0) {
    unlink(headerFilename);
    unlink(waveFilename);
    unlink(currentLOSTouchname);
    //Bollocks
    return;
  }
    
  thisEventNumber=theHeader->eventNumber;
    

  //Now get event file
  sprintf(headerFilename,"%s/hd_%d.dat",eventTelemDirs[currentPri], 
	  thisEventNumber);
  sprintf(waveFilename,"%s/ev_%d.dat",eventTelemDirs[currentPri], 
	  thisEventNumber);


  retVal=genericReadOfFile(eventBuffer,waveFilename,MAX_EVENT_SIZE);
  if(retVal<0) {
    fprintf(stderr,"Problem reading %s\n",waveFilename);
    unlink(headerFilename);
    unlink(waveFilename);
    unlink(currentLOSTouchname);
	
    //Bollocks
    return;
  }


  //Okay so now the buffer either contains EncodedSurfPacketHeader_t or
  // it contains EncodedPedSubbedSurfPacketHeader_t
  gHdr = (GenericHeader_t*) &eventBuffer[0];
  switch(gHdr->code) {
  case PACKET_BD:
    if(sendWavePackets) 
      retVal=sendRawWaveformPackets(retVal);
    else
      retVal=sendRawSurfPackets(retVal);
    break;
  case PACKET_PED_SUBBED_EVENT:
    if(sendWavePackets)
      retVal=sendPedSubbedWaveformPackets(retVal);
    else 
      retVal=sendPedSubbedSurfPackets(retVal);
    break;
  case PACKET_ENC_EVENT_WRAPPER:
    retVal=sendEncodedSurfPackets(retVal);
    break;
  case PACKET_ENC_PEDSUB_EVENT_WRAPPER:
    if(sendWavePackets)
      retVal=sendEncodedPedSubbedWavePackets(retVal);
    else 
      retVal=sendEncodedPedSubbedSurfPackets(retVal);
    break;
  default:
    if(errorCounter<100) {
      syslog(LOG_ERR,"Don't know what to do with packet %d -- %s (Message %d of 100)\n",gHdr->code,packetCodeAsString(gHdr->code),errorCounter);
      errorCounter++;
    }
    fprintf(stderr,"Don't know what to do with packet %d -- %s (file %s, size %d)\n",gHdr->code,packetCodeAsString(gHdr->code),waveFilename,retVal);
  }
	
  if(printToScreen && verbosity>1) 
    printf("Removing files %s\t%s\n",headerFilename,waveFilename);

  if(!checkFileExists(currentTouchname)) {
    unlink(headerFilename);
    unlink(waveFilename);
    unlink(currentLOSTouchname);
  }
  else {
    printf("Not removing %s because checkFileExists == %d\n",
	   headerFilename,checkFileExists(currentTouchname));
  }
    
}
예제 #13
0
int addToTelemetryBuffer(int maxCopy, int wd, char *telemDir, char *linkDir, int fileSize,int numToLeave)
/* Uses the inotify watch specified by wd to look */
/* in the specified directroy and fill buffer upto maxCopy. */
/* fileSize is the maximum size of a packet in the directory */
{
  char currentFilename[FILENAME_MAX];
  char currentLinkname[FILENAME_MAX];
  char currentTouchname[FILENAME_MAX];
  char currentLOSTouchname[FILENAME_MAX];
  int retVal,numLinks,count,numBytes,totalBytes=0;//,checkVal=0;
  GenericHeader_t *gHdr;
  char *tempString;
  //  printf("%s %s == %d %d %d\n",telemDir,linkDir,fileSize,numBytesInBuffer,LOS_MAX_BYTES);

  //Both of these two checks should be uneccesary
  if((numBytesInBuffer+fileSize)>LOS_MAX_BYTES) return 0;
  numLinks=getNumLinks(wd);
  if(numLinks<=numToLeave) {
    return 0;
  }
  
  for(count=numLinks-1;count>=numToLeave;count--) {
    tempString=getLastLink(wd);
    sprintf(currentFilename,"%s/%s",telemDir,tempString);
    sprintf(currentTouchname,"%s.sipd",currentFilename);
    sprintf(currentLOSTouchname,"%s.losd",currentFilename);
    sprintf(currentLinkname,"%s/%s",linkDir,tempString);

    printf("RJN -- %s\n",currentFilename);

    if(!checkFileExists(currentLinkname)) {
      //      printf("%s -- doesn't exist\n",currentLinkname);
      unlink(currentLinkname);
      continue;
    }

    if(checkFileExists(currentTouchname)) continue;
    touchFile(currentLOSTouchname);


    retVal=genericReadOfFile((unsigned char*)&(losBuffer[numBytesInBuffer]),
			     currentFilename,
			     LOS_MAX_BYTES-numBytesInBuffer);
    if(retVal<=0) {
      //	    syslog(LOG_ERR,"Error opening file, will delete: %s",
      //		   currentFilename);
      //	    fprintf(stderr,"Error reading file %s -- %d\n",currentFilename,retVal);
      unlink(currentFilename);
      unlink(currentLOSTouchname);
      unlink(currentLinkname);
      unlink(currentTouchname);
      continue;
    }
    numBytes=retVal;

    if(printToScreen && verbosity>1) {
      printf("Read File: %s -- (%d bytes)\n",currentFilename,numBytes);
    }
	

    //	printf("Read %d bytes from file\n",numBytes);
    //	Maybe I'll add a packet check here
    gHdr = (GenericHeader_t*) (&(losBuffer[numBytesInBuffer]));
    //	checkVal=checkPacket(gHdr);
    //	if(checkVal!=0 ) {
    //	    printf("Bad packet %s == %d\n",currentFilename,checkVal);
    //	}
    gHdr->packetNumber=getLosNumber();
    numBytesInBuffer+=numBytes;
    totalBytes+=numBytes;

    if(!checkFileExists(currentTouchname)) {
      unlink(currentLinkname);
      unlink(currentFilename);
      unlink(currentLOSTouchname);
    }
    else {
      printf("%s exists\n",currentTouchname);
    }

    if((totalBytes+fileSize)>maxCopy ||
       (numBytesInBuffer+fileSize)>LOS_MAX_BYTES) break;
  }
        
  return totalBytes;
}
예제 #14
0
static
PGPError pgpInitSDKPrefsDir( PGPContextRef context )
{
    char            *pszTemp = NULL;
    char            rootPath[MAX_PATH] = {'\0'};
    char            filename[MAX_PATH] = {'\0'};
    FILE            *fp = NULL;
    PGPUInt16       len = 0;
    PGPError        err = kPGPError_NoErr;
    PGPKeySetRef    keyset = kPGPInvalidRef;

#ifdef PGP_UNIX
    PFLFileSpecRef  dirspec = kPGPInvalidRef;
    PGPMemoryMgrRef mmgr = kPGPInvalidRef;
    PFLFileSpecRef  sdkpflPrefs = kPGPInvalidRef;
    PGPBoolean	    exists = FALSE;
    
    err = PGPNewMemoryMgr(0, &mmgr);
    if(IsPGPError(err))
        return err;

    err = pgpGetPrefsSpec( mmgr, &sdkpflPrefs );
    if(IsPGPError(err)) 
    {
        PGPFreeMemoryMgr(mmgr);
        return err;
    }

    err = PFLGetParentDirectory(sdkpflPrefs, &dirspec);
    if(IsPGPError(err))
    {
        PFLFreeFileSpec(sdkpflPrefs);
        PGPFreeMemoryMgr(mmgr);
        return err;
    }
    err = PFLFileSpecExists(dirspec, &exists);
    pgpAssertNoErr(err);

    if(!exists) /* need to create directory */
    {
        char    *dirname;

        err = PFLGetFullPathFromFileSpec( dirspec, &dirname );
        pgpAssertNoErr(err);
        if(mkdir(dirname, 0700) == -1)
        {
            fprintf(stderr, LANG("mkdir (%s) failed..\n\n"), dirname);
            err = kPGPError_CantOpenFile;
        }
        PGPFreeData(dirname);
    }
    if(dirspec != kPGPInvalidRef)
        PGPFreeFileSpec(dirspec);
    if(sdkpflPrefs != kPGPInvalidRef)
        PFLFreeFileSpec(sdkpflPrefs);
    if(mmgr != kPGPInvalidRef)
        PGPFreeMemoryMgr(mmgr);


#endif /* PGP_UNIX */

    err = PGPsdkLoadDefaultPrefs(context);
    pgpAssertNoErr(err);
    err = PGPOpenDefaultKeyRings(context, 
                    kPGPKeyRingOpenFlags_Create | 
                    kPGPKeyRingOpenFlags_Mutable, &keyset);
    if(IsntPGPError(err))
    {
        PGPFreeKeySet(keyset);
    }
    else
        return err;

    /* now check to see if configuration file exists, if not, create it */
    buildFileName(filename, "pgp.cfg");
    if((fp = fopen(filename, "r")) != NULL)
        fclose(fp);
    else
    {
        /* file doesn't exist, create it */
        touchFile(filename, 0600);
    }
    return err;
}
예제 #15
0
int checkLinkDir(int maxCopy, char *telemDir, char *linkDir, int fileSize)
/* Looks in the specified directroy and fill buffer upto maxCopy. */
/* fileSize is the maximum size of a packet in the directory */
{
  char currentFilename[FILENAME_MAX];
  char currentLinkname[FILENAME_MAX];
  char currentTouchname[FILENAME_MAX];
  char currentLOSTouchname[FILENAME_MAX];
  int retVal,numLinks,count,numBytes,totalBytes=0;//,checkVal=0;
  GenericHeader_t *gHdr;
  struct dirent **linkList;

  if((numBytesInBuffer+fileSize)>LOS_MAX_BYTES) return 0;


  numLinks=getListofLinks(linkDir,&linkList); 
  if(numLinks<=1) {
    return 0;
  }
        
  for(count=numLinks-1;count>=1;count--) {
    sprintf(currentFilename,"%s/%s",telemDir,
	    linkList[count]->d_name);
    sprintf(currentTouchname,"%s.sipd",currentFilename);
    sprintf(currentLOSTouchname,"%s.losd",currentFilename);
    sprintf(currentLinkname,"%s/%s",
	    linkDir,linkList[count]->d_name);

    if(checkFileExists(currentTouchname)) continue;
    touchFile(currentLOSTouchname);


    retVal=genericReadOfFile((unsigned char*)&(losBuffer[numBytesInBuffer]),
			     currentFilename,
			     LOS_MAX_BYTES-numBytesInBuffer);
    if(retVal<=0) {
      //	    syslog(LOG_ERR,"Error opening file, will delete: %s",
      //		   currentFilename);
      //	    fprintf(stderr,"Error reading file %s -- %d\n",currentFilename,retVal);
      unlink(currentFilename);
      unlink(currentLOSTouchname);
      unlink(currentLinkname);
      unlink(currentTouchname);
      continue;
    }
    numBytes=retVal;

    if(printToScreen && verbosity>1) {
      printf("Read File: %s -- (%d bytes)\n",currentFilename,numBytes);
    }
	

    //	printf("Read %d bytes from file\n",numBytes);
    //	Maybe I'll add a packet check here
    gHdr = (GenericHeader_t*) (&(losBuffer[numBytesInBuffer]));
    //	checkVal=checkPacket(gHdr);
    //	if(checkVal!=0 ) {
    //	    printf("Bad packet %s == %d\n",currentFilename,checkVal);
    //	}
    gHdr->packetNumber=getLosNumber();
    numBytesInBuffer+=numBytes;
    totalBytes+=numBytes;

    if(!checkFileExists(currentTouchname)) {
      unlink(currentLinkname);
      unlink(currentFilename);
      unlink(currentLOSTouchname);
    }
    else {
      printf("%s exists\n",currentTouchname);
    }

    if((totalBytes+fileSize)>maxCopy ||
       (numBytesInBuffer+fileSize)>LOS_MAX_BYTES) break;
  }
    
  for(count=0;count<numLinks;count++)
    free(linkList[count]);
  free(linkList);
    
  return totalBytes;
}
void runSlamExe(char *outputDir, struct genomeBit *target, struct genomeBit *aligns, char *refPrefix, char *alignPrefix)
/* run the actual slam program */
{
char *fa1 = NULL;
char *fa2 = NULL;
char *gff1 = NULL;
char *gff2 = NULL;
struct dyString *dy = newDyString(1024);

char command[2048];
int retVal = 0;
/* get our arguments */
fa1 = fileNameFromGenomeBit("", ".fa", target);
fa2 = fileNameFromGenomeBit("", ".fa", aligns);
gff1 = fileNameFromGenomeBit("", "", target);
gff2 = fileNameFromGenomeBit("", "", aligns);

if(runAvidFirst)
    {
    struct dnaSeq *faMerged = NULL, *fa = NULL;
    int bpCount = 0;
    snprintf(command, sizeof(command), "%savid -nm=both  %s %s",
	       slamBin, fa1, fa2); 
    retVal = system(command);

    warn("%s exited with value %d", command, retVal);
    snprintf(command, sizeof(command), "echo \"\" >> %s.merged", fa2);
    system(command);
    dyStringClear(dy);
    dyStringPrintf(dy, "%s.merged", fa2); 

    /* Check to make sure that the merged fa file is smaller than our limit. */
    faMerged = faReadAllDna(dy->string);
    for(fa = faMerged; fa !=NULL; fa = fa->next)
	bpCount += fa->size;
    if( bpCount >= bpLimit)
	{
	warn("runSlam()::runSlam() - trying to write %d to fasta file which is greater than limit of %d for %s\n pair is: %s/%s.%s\t%s/%s.%s",
		 bpCount, bpLimit, dy->string, target->chrom, refPrefix, fa1, target->chrom, alignPrefix, fa2);
	exit(0); // Exit zero to let parasol know we did what we could....
	}
    dyStringClear(dy);
    }
/* File is hardmasked already, create fake repeat-masker files so other
   programs don't squawk. */
touchFile(fa1, ".out");
touchFile(fa1, ".masked");
touchFile(fa2, ".merged.out");
touchFile(fa2, ".merged.masked");

if(runAvidFirst) /* if we ran avid first then we need to use .merged files. */
    {
      snprintf(command, sizeof(command),  
  	     "%sslam.pl %s %s %s.merged -outDir %s -o1 %s.%s -o2 %s.%s.merged",   
  	     slamBin, slamOpts, fa1, fa2, outputDir, refPrefix, gff1, alignPrefix, gff2); 
    }
else 
    {
      snprintf(command, sizeof(command),  
  	     "%sslam.pl %s %s %s -outDir %s -o1 %s.%s -o2 %s.%s",   
  	     slamBin, slamOpts, fa1, fa2, outputDir, refPrefix, gff1, alignPrefix, gff2); 
    }
warn("Running %s", command);
retVal = system(command);
warn("%s exited with value %d", command, retVal);

/* cleanup */
freez(&fa1);
freez(&fa2);
freez(&gff1);
freez(&gff2);
}
예제 #17
0
int checkLinkDirAndOpenport(int maxCopy, char *telemDir, char *linkDir, int fileSize) 
/* Looks in the specified directroy and OPENPORT's up to maxCopy bytes of data */
/* fileSize is the maximum size of a packet in the directory */
{
    char currentFilename[FILENAME_MAX];
    char currentTouchname[FILENAME_MAX];
    char currentLOSTouchname[FILENAME_MAX];
    char currentLinkname[FILENAME_MAX];
    int retVal,numLinks,count,numBytes,totalBytes=0;//,checkVal=0;
    GenericHeader_t *gHdr;
    struct dirent **linkList;
    


    numLinks=getListofLinks(linkDir,&linkList); 
    if(numLinks<=0) {
	return 0;
    }
    int counter=0;
    for(count=numLinks-1;count>=0;count--) {
      retVal=snprintf(currentFilename,sizeof(currentFilename),"%s/%s",telemDir,
	       linkList[count]->d_name);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      retVal=snprintf(currentTouchname,sizeof(currentTouchname),"%s.sipd",currentFilename);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      retVal=snprintf(currentLOSTouchname,sizeof(currentLOSTouchname),"%s.losd",currentFilename);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      retVal=snprintf(currentLinkname,sizeof(currentLinkname),"%s/%s",
		      linkDir,linkList[count]->d_name);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      
      if(checkFileExists(currentLOSTouchname)) 
	continue;
      touchFile(currentTouchname);
      
      retVal=genericReadOfFile((unsigned char*)theBuffer,
				 currentFilename,
				 MAX_EVENT_SIZE);
	syslog(LOG_DEBUG,"Trying %s",currentFilename);
	if(retVal<=0) {
//	    syslog(LOG_ERR,"Error opening file, will delete: %s",
//		   currentFilename);
//	    fprintf(stderr,"Error reading file %s -- %d\n",currentFilename,retVal);
	    removeFile(currentFilename);
	    removeFile(currentLinkname);
	    removeFile(currentTouchname);
	    continue;
	}
	numBytes=retVal;

	if(printToScreen && verbosity>1) {
	    printf("Read File: %s -- (%d bytes)\n",currentFilename,numBytes);
	}
	

	printf("Read %d bytes from file\n",numBytes);
//	Maybe I'll add a packet check here
	gHdr = (GenericHeader_t*)theBuffer;
//	checkVal=checkPacket(gHdr);
//	if(checkVal!=0 ) {
//	    printf("Bad packet %s == %d\n",currentFilename,checkVal);
//	}
	gHdr->packetNumber=getOpenportNumber();
	printf("Openport number %d\n",gHdr->packetNumber);
	retVal = openportWrite(theBuffer, numBytes,1);
	if(retVal<0) {
	    //Problem sending data
	    syslog(LOG_ERR,"Problem sending Wake up Packet over Openprt\n");
	    fprintf(stderr,"Problem sending Wake up Packet over Openport\n");	
	}
	
	totalBytes+=numBytes;

	if(!checkFileExists(currentLOSTouchname)) {
	    removeFile(currentLinkname);
	    removeFile(currentFilename);
	    removeFile(currentTouchname);
	}
	else {
	    sleep(1);
	    removeFile(currentLinkname);
	    removeFile(currentFilename);
	    removeFile(currentTouchname);
	    removeFile(currentLOSTouchname);
	}
	printf("Got code: %#x %#x\n",gHdr->code&BASE_PACKET_MASK,PACKET_GPS_ADU5_PAT);

//	if((totalBytes+fileSize)>maxCopy) break;
	counter++;
	if(counter>=maxCopy) break;
//	break;
    }
    
    for(count=0;count<numLinks;count++)
	free(linkList[count]);
    free(linkList);
    
    return totalBytes;
}