Beispiel #1
0
FILE* fopen(const char *path, const char * mode)
{

	//struct timeval tv1,tv2;

	orig_fopen_type orig_fopen;
	orig_fopen = (orig_fopen_type)dlsym(RTLD_NEXT,"fopen");

	//time_t t;
	//time(&t);

	//printf("%s",ctime(&t));
	clock_t start = clock();
	
	//gettimeofday(&tv1,NULL);
	FILE *temp = orig_fopen(path,mode);
	//gettimeofday(&tv2,NULL);	

	clock_t end = clock();
	//time(&t);
	//printf("%s",ctime(&t));

	double diff = ((double)(end-start))/(double)CLOCKS_PER_SEC;

	printf("%lf \n",diff);

	//printf("Total time for fopen = %lf seconds \n", (double)(tv2.tv_usec - tv1.tv_usec)/1000000 + (double)(tv2.tv_sec - tv1.tv_sec));
	return temp;
}
Beispiel #2
0
/* appends the string s to the LOG_FILE */
void mylog(const char* s){
	FILE* log = NULL;
	if(!orig_fopen)
		orig_fopen = dlsym(RTLD_NEXT, "fopen");
	log = orig_fopen(LOG_FILE, "a+");
	if(log == NULL) {
		perror("file can't be open");
		return;
	}	
	fseek(log, 0, SEEK_END);
	time_t cur_time = time(0);
	fprintf(log, "%s: %s\n", (char*)ctime(&cur_time), s);
	fclose(log);
}
Beispiel #3
0
FILE* fopen(const char* pathname, const char* mode){
	FILE *ret = NULL;
	if(is_onlyappend(pathname) && strchr(mode, 'w') != NULL)
		return ret;

	char *replace;
	if((replace = is_replaced(pathname)) != NULL){
		pathname = replace;
	}

	if(!orig_fopen)
		orig_fopen = dlsym(RTLD_NEXT, "fopen");
	ret = orig_fopen(pathname, mode);
	logopen(pathname);
	return ret;
}
Beispiel #4
0
void Iio::dump()
{
  FILE * FD;
  pid_t pid=1;
  char logfile[1024];
  //int pid=1;
  int i;

  orig_fopen_f_type  orig_fopen;
  orig_fclose_f_type orig_fclose;



  orig_fopen   = (orig_fopen_f_type)dlsym(RTLD_NEXT,"fopen");
  orig_fclose  = (orig_fclose_f_type)dlsym(RTLD_NEXT,"fclose");
  
  pid=getpid();
  
  sprintf(logfile,"/tmp/log.%d",pid);

  FD=orig_fopen(logfile,"a"); 
  for (i=0;i<iiof.size();i++)
    {
      /*
      fprintf(FD,"write[%lld %lld] read[%lld %lld] [%d %d %s %d] \n",
	      iiof[i].iac.writecall,
	      iiof[i].iac.writesize,
	      iiof[i].iac.readcall,
	      iiof[i].iac.readsize,
	      iiof[i].fd,
	      iiof[i].oldfd,
	      iiof[i].name.c_str(),
	      iiof[i].state
	      );
      */
      fprintf(FD,iiof[i].dump().c_str());
    }
  for (i=0;i<log.logstr.size();i++)
    {
      if (i==0)
	fprintf(FD,"LOG\n");
      fprintf(FD,log.logstr[i].c_str());
    }

  //chainlist_head->printList(chainlist_head,FD); 
  orig_fclose(FD); 
}
Beispiel #5
0
FILE *fopen(const char *pathname, const char *mode)
{
	FILE *fp;
	const char *path;
	char buffer[PATH_MAX];
	fopen_func_t orig_fopen;

	orig_fopen = (fopen_func_t)dlsym(RTLD_NEXT, "fopen");
	path = redirect(pathname, buffer);
	fp = orig_fopen(path, mode);

	if (path != pathname && getenv("PRELOAD_DEBUG")) {
		fprintf(stderr, "preload_debug: fopen(\"%s\", \"%s\") => \"%s\": fp=%p\n", pathname, mode, path, fp);
	}

	return fp;
}
Beispiel #6
0
FILE *fopen(const char *pathname, const char *mode)
{
  FILE * FP;
  int    fd;
  orig_fopen_f_type orig_fopen;

  //mtx.lock();
  
  orig_fopen  = (orig_fopen_f_type)dlsym(RTLD_NEXT,"fopen");
  FP=orig_fopen(pathname,mode);
  


  if (FP!=0)
  {
      fd=fileno(FP);
      if (myiio.existFd(fd)==-1)
	{
	  Ifile ifi;
	  ifi.setFd(fd);
	  ifi.setName(std::string(pathname));
	  ifi.setState(IOBYFILE_OPEN);
	  myiio.iiof.push_back(ifi);
	}      
      else
	{
	  myiio.getFd(fd).setState(IOBYFILE_OPEN);
	  myiio.getFd(fd).setFd(fd);
	  //myiio.getFd(fd).setOldFd(fd);
	}


      std::string str;
      std::ostringstream oss;
      oss << "fopen("<<pathname<< mode << ")="<< FP<< "(" << fd << ")" << "\n"; 
      log.add(oss.str());            
  }
  //mtx.unlock();
  return(FP);
}
Beispiel #7
0
//Iio::Iio() : iiof(MAX_FILEDESC,Ifile())
Iio::Iio()
{
  FILE * FD;
  int    pid=1;
  char    logfile[1024];
  //printf("loading\n");
  orig_fopen_f_type orig_fopen;
  orig_fclose_f_type orig_fclose;
  status=IIO_BEGIN;
  mtx.lock();
  orig_fopen   = (orig_fopen_f_type)dlsym(RTLD_NEXT,"fopen");
  orig_fclose  = (orig_fclose_f_type)dlsym(RTLD_NEXT,"fclose");
  
  pid=getpid();
  sprintf(logfile,"/tmp/log.%d",pid);

  FD=orig_fopen(logfile,"w");  
  fprintf(FD,"Launching init()\n"); 
  orig_fclose(FD);
  status=IIO_RUNNING;
  mtx.unlock();

}
Beispiel #8
0
Iio::~Iio()
{
  FILE * FD;
  pid_t pid=1;
  char logfile[1024];

  orig_fopen_f_type  orig_fopen;
  orig_fclose_f_type orig_fclose;
  status=IIO_ENDING;
  //mtx.lock();
  orig_fopen   = (orig_fopen_f_type)dlsym(RTLD_NEXT,"fopen");
  orig_fclose  = (orig_fclose_f_type)dlsym(RTLD_NEXT,"fclose");
  
  pid=getpid();
  
  sprintf(logfile,"/tmp/log.%d",pid);
  dump();
  FD=orig_fopen(logfile,"a");
  
  fprintf(FD,"Launching fini()\n"); 
  //chainlist_head->printList(chainlist_head,FD); 
  orig_fclose(FD); 
  ////mtx.unlock();
}
Beispiel #9
0
FILE *
rpl_fopen (const char *filename, const char *mode)
{
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
  if (strcmp (filename, "/dev/null") == 0)
    filename = "NUL";
#endif

#if FOPEN_TRAILING_SLASH_BUG
  /* If the filename ends in a slash and a mode that requires write access is
     specified, then fail.
     Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
     says that
       "A pathname that contains at least one non-slash character and that
        ends with one or more trailing slashes shall be resolved as if a
        single dot character ( '.' ) were appended to the pathname."
     and
       "The special filename dot shall refer to the directory specified by
        its predecessor."
     If the named file already exists as a directory, then if a mode that
     requires write access is specified, fopen() must fail because POSIX
     <http://www.opengroup.org/susv3/functions/fopen.html> says that it
     fails with errno = EISDIR in this case.
     If the named file does not exist or does not name a directory, then
     fopen() must fail since the file does not contain a '.' directory.  */
  {
    size_t len = strlen (filename);
    if (len > 0 && filename[len - 1] == '/')
      {
        int fd;
        struct stat statbuf;
        FILE *fp;

        if (mode[0] == 'w' || mode[0] == 'a')
          {
            errno = EISDIR;
            return NULL;
          }

        fd = open (filename, O_RDONLY);
        if (fd < 0)
          return NULL;

        if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
          {
            close (fd);
            errno = ENOTDIR;
            return NULL;
          }

        fp = fdopen (fd, mode);
        if (fp == NULL)
          {
            int saved_errno = errno;
            close (fd);
            errno = saved_errno;
          }
        return fp;
      }
  }
# endif

  return orig_fopen (filename, mode);
}
Beispiel #10
0
FILE * fopen ( const char * path, const char *mode ) {
    enforcer(path);

    return orig_fopen( path, mode );
}