コード例 #1
0
ファイル: bad_link.c プロジェクト: Adam-Koza/A3
void
test_link(void)
{
	test_link_paths();
	link_dir();
	link_empty1();
	link_empty2();
}
コード例 #2
0
ファイル: bad_link.c プロジェクト: SidhantDuggal/os161hack
void
test_link(void)
{
	int ntests = 0, lost_points = 0;
	int result;

	test_link_paths(&ntests, &lost_points);

	ntests++;
	result = link_dir();
	handle_result(result, &lost_points);

	ntests++;
	result = link_empty1();
	handle_result(result, &lost_points);

	ntests++;
	result = link_empty2();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
コード例 #3
0
ファイル: worker_bee.cpp プロジェクト: fairchild/babysitter
bee_files_set *WorkerBee::libs_for(const std::string &executable) {
  std::pair<string_set *, string_set *> *dyn_libs;
  
  // If we are pointed at an absolute path to a binary
  // then find the linked libraries of the executable
  // If it's not found, then find it, then look up the libraries
  if (abs_path(executable))
    dyn_libs = linked_libraries(executable);
  else {
    std::string bin = find_binary(executable);
    dyn_libs = linked_libraries(bin);
  }
  //string_set *libs = new string_set();
  bee_files_set *libs = new bee_files_set();  

  // iterate through
  string_set obj = *dyn_libs->first;
  struct stat lib_stat;
  char link_buf[1024];
  // Go through the libs
  for (string_set::iterator ld = obj.begin(); ld != obj.end(); ++ld) {
    string_set paths = *dyn_libs->second;
    
    // Go through each of the paths
    for (string_set::iterator pth = paths.begin(); pth != paths.end(); ++pth) {
      std::string path (*pth);
      std::string full_path = *pth+'/'+*ld;
      if (fopen(full_path.c_str(), "rb") != NULL) {
        
        // Create a bee_file object
        BeeFile bf;
        bf.set_file_path(full_path.c_str());
        
        // Make sure the file can be "stat'd"
        if (stat(full_path.c_str(), &lib_stat) < 0) {
          fprintf(stderr, "[lstat] Error: %s: %s\n", full_path.c_str(), strerror(errno));
        }
        bf.set_file_stats(lib_stat);
			  // Are we looking at a symlink
        // if ((lib_stat.st_mode & S_IFMT) == S_IFLNK) {
        if (S_ISLNK(lib_stat.st_mode)) {
          memset(link_buf, 0, 1024);
          if (!readlink(full_path.c_str(), link_buf, 1024)) {
            fprintf(stderr, "[readlink] Error: %s: %s\n", full_path.c_str(), strerror(errno));
          }
          
          /** If we are looking at a symlink, then create a new BeeFile object and 
           * insert it into the library path, noting that the other is a symlink
          **/ 
          std::string link_dir (dirname(strdup(full_path.c_str())));
          // std::string link_path (link_buf);
          std::string link_path;
          if (path == "") 
            link_path = link_dir + "/" + link_buf; 
          else 
            link_path = (path+"/"+link_buf);
          
          BeeFile lbf;
          // Set the data on the BeeFile object
          lbf.set_file_path(link_path.c_str());
          // full_path.c_str()
          bf.set_file_path(full_path.c_str()); // This is redundant, but just for clarity

          bf.set_sym_origin(link_buf);
          bf.set_is_link(true);
          libs->insert(lbf);
        } else {
          bf.set_is_link(false);
        }
        
        libs->insert(bf);
        break; // We found it! Move on, yo
      }
    }
  }
  
  return libs;
}