Changeset 122:3114c2cdce23 in rrlib_util


Ignore:
Timestamp:
03.11.2014 17:43:33 (5 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
14.08
Phase:
public
Message:

Better fix for printf format string warnings: replaced PRINTF by PRINT macros to use streaming semantics for better portability as Michael suggested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sFileIOUtils.cpp

    r121 r122  
    134134  if (system(sys_call.str().c_str()) == -1) 
    135135  { 
    136     RRLIB_LOG_PRINTF(USER, "sFileIOUtils>> Error creating dir: '%s'\n", path.c_str()); 
     136    RRLIB_LOG_PRINT(USER, "sFileIOUtils>> Error creating dir: '", path, "'"); 
    137137//     std::stringstream error_msg; 
    138138//     error_msg << "sFileIOUtils>> Error creating Dir:\n" 
     
    143143  else 
    144144  { 
    145 //     RRLIB_LOG_PRINTF(USER, "sFileIOUtils>> Directory: '%s' successfully created.\n", path.c_str()); 
     145//     RRLIB_LOG_PRINT(USER, "Directory: '", path, "' successfully created."); 
    146146    return true; 
    147147  } 
     
    157157  if (fgets(buf, sizeof(buf), pipe) == 0) 
    158158  { 
    159     RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::CreateTempfile() >> Error creating temp file!\n"); 
     159    RRLIB_LOG_PRINT(ERROR, "Error creating temp file!"); 
    160160    exit(EXIT_FAILURE); 
    161161  } 
     
    185185  if (system(cmd.str().c_str()) != 0) 
    186186  { 
    187     RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils>> Execution of command '%s' failed!\n", cmd.str().c_str()); 
     187    RRLIB_LOG_PRINT(ERROR, "Execution of command '", cmd.str(), "' failed!"); 
    188188    exit(EXIT_FAILURE); 
    189189  } 
     
    200200  if (system(cmd.str().c_str()) != 0) 
    201201  { 
    202     RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils>> Execution of command '%s' failed!\n", cmd.str().c_str()); 
     202    RRLIB_LOG_PRINT(ERROR, "Execution of command '", cmd.str(), "' failed!"); 
    203203    exit(EXIT_FAILURE); 
    204204  } 
     
    289289      error_msg = "Unknown error"; 
    290290    } 
    291     RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::%s >> Could not expand '%s': %s!\n", __FUNCTION__, file_name.c_str(), error_msg); 
     291    RRLIB_LOG_PRINT(ERROR, "Could not expand '", file_name, "': ", error_msg, "!"); 
    292292    return false; 
    293293  } 
     
    349349  if (result) 
    350350  { 
    351     RRLIB_LOG_PRINTF(ERROR, "got error: <%s>\n", strerror(errno)); 
     351    RRLIB_LOG_PRINT(ERROR, "got error: <", strerror(errno), ">"); 
    352352    exit(EXIT_FAILURE); 
    353353  } 
    354   RRLIB_LOG_PRINTF(DEBUG, "got hostname: <%s>\n", name); 
     354  RRLIB_LOG_PRINT(DEBUG, "got hostname: <", name, ">"); 
    355355 
    356356  return name; 
     
    368368  { 
    369369    address = * ((struct in_addr *) host_ent->h_addr_list[ 0 ]); 
    370     RRLIB_LOG_PRINTF(USER, "ip address of host <%s> = <%s>\n", name.c_str(), inet_ntoa(address)); 
    371   } 
    372   else 
    373   { 
    374     RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::GetIpAddressOfHost() >>> could not get ip address of host <%s>\n", name.c_str()); 
     370    RRLIB_LOG_PRINT(USER, "ip address of host <", name, "> = <", inet_ntoa(address), ">"); 
     371  } 
     372  else 
     373  { 
     374    RRLIB_LOG_PRINT(ERROR, "could not get ip address of host <", name, ">"); 
    375375  } 
    376376  return address; 
     
    383383struct in_addr sFileIOUtils::HostToIpViaNslookup(const std::string & name) 
    384384{ 
    385   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIpViaNslookup() >>> started with host <%s>\n", name.c_str()); 
     385  RRLIB_LOG_PRINT(USER, "started with host <", name, ">"); 
    386386  struct in_addr address; 
    387387  address.s_addr = 0; 
     
    389389  std::stringstream command; 
    390390  command << "nslookup \"" << name << "\""; 
    391   RRLIB_LOG_PRINTF(USER, "command = <%s>\n", command.str().c_str()); 
     391  RRLIB_LOG_PRINT(USER, "command = <", command, ">"); 
    392392  FILE * pipe = popen(command.str().c_str(), "r"); 
    393393  if (!pipe) 
     
    403403  } 
    404404  pclose(pipe); 
    405   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIpViaNslookup() >>> host = <%s> , result = <%s> \n", name.c_str(), result.str().c_str()); 
     405  RRLIB_LOG_PRINT(USER, "host = <", name, ">, result = <", result.str(), ">"); 
    406406 
    407407  std::string result_str(result.str()); 
     
    410410  if (pos == std::string::npos) 
    411411  { 
    412     RRLIB_LOG_PRINTF(ERROR, "Could not find token <%s> in nslookup result ... returning <%s> \n", search_token.c_str(), inet_ntoa(address)); 
     412    RRLIB_LOG_PRINT(ERROR, "Could not find token <", search_token, "> in nslookup result ... returning <", inet_ntoa(address), ">"); 
    413413    return address; 
    414414  } 
    415415  result_str.erase(0, pos + search_token.length()); 
    416   RRLIB_LOG_PRINTF(USER, "pos = %zd\n", pos); 
     416  RRLIB_LOG_PRINT(USER, "pos = ", pos); 
    417417 
    418418  search_token = "Address:"; 
     
    420420  if (pos == std::string::npos) 
    421421  { 
    422     RRLIB_LOG_PRINTF(ERROR, "Could not find token <%s> in nslookup result ... returning <%s> \n", search_token.c_str(), inet_ntoa(address)); 
     422    RRLIB_LOG_PRINT(ERROR, "Could not find token <", search_token, "> in nslookup result ... returning <", inet_ntoa(address), ">"); 
    423423    return address; 
    424424  } 
    425   RRLIB_LOG_PRINTF(USER, "pos = %zd\n", pos); 
     425  RRLIB_LOG_PRINT(USER, "pos = ", pos); 
    426426 
    427427  std::string found_name(result_str.substr(0, pos)); 
     
    432432  //boost::trim(ip); 
    433433 
    434   RRLIB_LOG_PRINTF(USER, "found_name <%s> , name <%s> \n", found_name.c_str(), name.c_str()); 
     434  RRLIB_LOG_PRINT(USER, "found_name <", found_name, "> , name <", name, ">"); 
    435435 
    436436  if (found_name != name) 
    437437  { 
    438     RRLIB_LOG_PRINTF(ERROR, "nslookup failed .... returning <%s> \n", inet_ntoa(address)); 
     438    RRLIB_LOG_PRINT(ERROR, "nslookup failed .... returning <", inet_ntoa(address), ">"); 
    439439    return address; 
    440440  } 
    441   RRLIB_LOG_PRINTF(USER, "found_name <%s> , ip <%s> \n", found_name.c_str(), ip.c_str()); 
     441  RRLIB_LOG_PRINT(USER, "found_name <", found_name, "> , ip <", ip, ">"); 
    442442 
    443443  inet_aton(ip.c_str(), &address); 
     
    453453struct in_addr sFileIOUtils::HostToIpViaHost(const std::string & name) 
    454454{ 
    455   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIpViaHost() >>> started with host <%s>\n", name.c_str()); 
     455  RRLIB_LOG_PRINT(USER, "started with host <", name, ">"); 
    456456  struct in_addr address; 
    457457  address.s_addr = 0; 
     
    459459  std::stringstream command; 
    460460  command << "host -t A \"" << name << "\""; 
    461   RRLIB_LOG_PRINTF(USER, "command = <%s>\n", command.str().c_str()); 
     461  RRLIB_LOG_PRINT(USER, "command = <", command.str(), ">"); 
    462462  FILE * pipe = popen(command.str().c_str(), "r"); 
    463463  if (!pipe) 
     
    473473  } 
    474474  pclose(pipe); 
    475   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIpViaHost() >>> host = <%s> , result = <%s> \n", name.c_str(), result.str().c_str()); 
     475  RRLIB_LOG_PRINT(USER, "host = <", name, "> , result = <", result.str(), ">"); 
    476476 
    477477  std::string result_str(result.str()); 
     
    480480 
    481481  for_each(tokens.begin(), tokens.end(), sStringUtils::Trim<std::string>()); 
    482   RRLIB_LOG_PRINTF(DEBUG_VERBOSE_1, "sFileIOUtils::HostToIpViaHost() >>> got %zu tokens:\n", tokens.size()); 
     482  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "got ", tokens.size(), " tokens:"); 
    483483  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, Join(tokens, "\n")); 
    484484  if (tokens.size() != 4) 
     
    489489 
    490490  assert(tokens.size() == 4); 
    491   RRLIB_LOG_PRINTF(USER, "found_name <%s> , ip <%s> \n", tokens[0].c_str(), tokens[3].c_str()); 
     491  RRLIB_LOG_PRINT(USER, "found_name <", tokens[0], "> , ip <", tokens[3], ">"); 
    492492 
    493493  inet_aton(tokens[3].c_str(), &address); 
     
    500500struct in_addr sFileIOUtils::HostToIpViaHostsFile(const std::string & name) 
    501501{ 
    502   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIpViaHostsFile() >>> started with host <%s>\n", name.c_str()); 
     502  RRLIB_LOG_PRINT(USER, "started with host <", name, ">"); 
    503503  struct in_addr address; 
    504504  address.s_addr = 0; 
     
    526526          { 
    527527            ip_address = *iter; 
    528             RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIpViaHostsFile() >>> got ip <%s> of host <%s> from hosts file\n", ip_address.c_str(), name.c_str()); 
     528            RRLIB_LOG_PRINT(USER, "sFileIOUtils::HostToIpViaHostsFile() >>> got ip <", ip_address, "> of host <", name, "> from hosts file"); 
    529529            found = true; 
    530530            break; 
     
    544544struct in_addr sFileIOUtils::HostToIp(const std::string & name) 
    545545{ 
    546   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIp() >>> started with host <%s>\n", name.c_str()); 
     546  RRLIB_LOG_PRINT(USER, "started with host <", name, ">"); 
    547547 
    548548  struct in_addr address; 
     
    551551  if ((address = sFileIOUtils::HostToIpViaHostsFile(name)).s_addr != 0) 
    552552  { 
    553     RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIp() >>> got ip <%s> of host <%s> from hosts_file\n", inet_ntoa(address), name.c_str()); 
     553    RRLIB_LOG_PRINT(USER, "got ip <", inet_ntoa(address), "> of host <", name, "> from hosts_file"); 
    554554  } 
    555555  else if ((address = sFileIOUtils::HostToIpViaHost(name)).s_addr != 0) 
    556556  { 
    557     RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIp() >>> got ip <%s> of host <%s> via <host -t A>\n", inet_ntoa(address), name.c_str()); 
     557    RRLIB_LOG_PRINT(USER, "got ip <", inet_ntoa(address), "> of host <", name, "> via <host -t A>"); 
    558558  } 
    559559  else if ((address = sFileIOUtils::HostToIpViaNslookup(name)).s_addr != 0) 
    560560  { 
    561     RRLIB_LOG_PRINTF(USER, "sFileIOUtils::HostToIp() >>> got ip <%s> of host <%s> via <nslookup>\n", inet_ntoa(address), name.c_str()); 
    562   } 
    563   else 
    564   { 
    565     RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::HostToIp() >>> could not get ip of host <%s>\n", name.c_str()); 
     561    RRLIB_LOG_PRINT(USER, "got ip <", inet_ntoa(address), "> of host <", name, "> via <nslookup>"); 
     562  } 
     563  else 
     564  { 
     565    RRLIB_LOG_PRINT(ERROR, "could not get ip of host <", name, ">"); 
    566566  } 
    567567 
     
    591591                << target_directory; 
    592592 
    593   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::RSyncFile() >>> executing <%s> ...\n", rsync_command.str().c_str()); 
     593  RRLIB_LOG_PRINT(USER, "executing <", rsync_command.str(), "> ..."); 
    594594  int ret = system(rsync_command.str().c_str()); 
    595   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::RSyncFile() >>> ... done.\n"); 
    596  
    597   RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::RSyncFile() >>> finished with result %d\n", ret); 
     595  RRLIB_LOG_PRINT(USER, " ... done.\n"); 
     596 
     597  RRLIB_LOG_PRINT(ERROR, "finished with result ", ret); 
    598598  return ret; 
    599599} // RSyncFile() 
     
    626626                << target_directory; 
    627627 
    628   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::RSyncFiles() >>> executing <%s> ...\n", rsync_command.str().c_str()); 
     628  RRLIB_LOG_PRINT(USER, "executing <", rsync_command.str(), "> ..."); 
    629629  int ret = system(rsync_command.str().c_str()); 
    630   RRLIB_LOG_PRINTF(USER, "sFileIOUtils::RSyncFiles() >>> ... done.\n"); 
    631  
    632   RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::RSyncFiles() >>> finished with result %d\n", ret); 
     630  RRLIB_LOG_PRINT(USER, "... done.\n"); 
     631 
     632  RRLIB_LOG_PRINT(ERROR, "finished with result ", ret); 
    633633  return ret; 
    634634} // RSyncFiles() 
     
    640640bool sFileIOUtils::CheckAndGetFile(const std::string &file_name, std::string &full_local_file_name, const std::string& resource_repository, const std::string& resource_server, const std::string& local_resource_directory, const std::string& server_resource_directory, bool use_cache) 
    641641{ 
    642   RRLIB_LOG_PRINTF(DEBUG_VERBOSE_1, "sFileIOUtils::CheckAndGetFile() >>> started with local_resource_directory <%s>, resource_repository <%s>, file_name <%s>, resource_server <%s>, server_resource_directory <%s>\n", local_resource_directory.c_str(), resource_repository.c_str(), file_name.c_str(), resource_server.c_str(), server_resource_directory.c_str()); 
     642  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "started with local_resource_directory <", local_resource_directory, ">, resource_repository <", resource_repository, ">, file_name <", file_name, ">, resource_server <", resource_server, ">, server_resource_directory <", server_resource_directory, ">"); 
    643643 
    644644  //!##################################################################################################### 
     
    661661  full_local_file_name = "./" + resource_repository + file_name; 
    662662 
    663   RRLIB_LOG_PRINTF(DEBUG_VERBOSE_1, "sFileIOUtils::CheckAndGetFile() >>> 1. check: trying to load <%s>\n", full_local_file_name.c_str()); 
     663  RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "1. check: trying to load <", full_local_file_name, ">"); 
    664664  ifstream try_1(full_local_file_name.c_str()); 
    665665  if (try_1) 
     
    679679    if (!sFileIOUtils::ShellExpandFilename(expanded_local_resource_directory, local_resource_directory + "/")) 
    680680    { 
    681       RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::%s >> Could not expand local resource directory!\n", __FUNCTION__); 
     681      RRLIB_LOG_PRINT(ERROR, "Could not expand local resource directory!"); 
    682682      return false; 
    683683    } 
    684684    full_local_file_name = (expanded_local_resource_directory + resource_repository + file_name); 
    685685 
    686     RRLIB_LOG_PRINTF(DEBUG_VERBOSE_1, "sFileIOUtils::CheckAndGetFile() >>> 2. check: trying to load <%s>\n", full_local_file_name.c_str()); 
     686    RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "2. check: trying to load <", full_local_file_name, ">"); 
    687687    ifstream try_2(full_local_file_name.c_str()); 
    688688    if (try_2) 
     
    702702      { 
    703703        local_host = sFileIOUtils::cached_local_host; 
    704         RRLIB_LOG_PRINTF(DEBUG_VERBOSE_1, "sFileIOUtils::CheckAndGetFile() >>> retrieved local_host <%s> from cache\n", local_host.c_str()); 
     704        RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "retrieved local_host <", local_host, "> from cache"); 
    705705      } 
    706706      else 
     
    719719        { 
    720720          server_ip_address = pos->second; 
    721           RRLIB_LOG_PRINTF(DEBUG_VERBOSE_1, "sFileIOUtils::CheckAndGetFile() >>> retrieved ip address <%s> of host <%s> from cache\n", server_ip_address.c_str(), server.c_str()); 
     721          RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "retrieved ip address <", server_ip_address, "> of host <", server, "> from cache"); 
    722722        } 
    723723        else 
    724724        { 
    725725          server_ip_address = inet_ntoa(sFileIOUtils::HostToIp(server)); 
    726           RRLIB_LOG_PRINTF(DEBUG_VERBOSE_1, "sFileIOUtils::CheckAndGetFile() >>> got ip address <%s> of host <%s>\n", server_ip_address.c_str(), server.c_str()); 
     726          RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "got ip address <", server_ip_address, "> of host <", server, ">"); 
    727727 
    728728          if (server_ip_address == "0.0.0.0") 
    729729          { 
    730             RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::constructor >>> zero ip address ... clearing server\n"); 
     730            RRLIB_LOG_PRINT(ERROR, "zero ip address ... clearing server"); 
    731731            server = ""; 
    732732          } 
     
    741741      if (server != "")   //&& server != local_host) 
    742742      { 
    743         RRLIB_LOG_PRINTF(DEBUG_VERBOSE_1, "sFileIOUtils::CheckAndGetFile() >>> 3. check: trying to rsync <%s:%s> to <%s> \n", server_ip_address.c_str(), (server_resource_directory + resource_repository + file_name).c_str(), expanded_local_resource_directory.c_str()); 
     743        RRLIB_LOG_PRINT(DEBUG_VERBOSE_1, "3. check: trying to rsync <", server_ip_address, ":", server_resource_directory + resource_repository + file_name, "> to <", expanded_local_resource_directory, ">"); 
    744744 
    745745        // rsync from <resource_server:server_resource_directory + resource_repository> 
     
    748748        if (sFileIOUtils::RSyncFile("", server_ip_address, server_resource_directory + "/./" + resource_repository, file_name, expanded_local_resource_directory, "R") != 0) 
    749749        { 
    750           RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::CheckAndGetFile() >>> could not rsync file <%s> from server <%s> at <%s> ... skipping\n", file_name.c_str(), server.c_str(), (server_resource_directory + resource_repository).c_str()); 
     750          RRLIB_LOG_PRINT(ERROR, "could not rsync file <", file_name, "> from server <", server, "> at <", server_resource_directory + resource_repository, "> ... skipping"); 
    751751          return false; 
    752752        } 
     
    755755      else 
    756756      { 
    757         RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::CheckAndGetFile() >>> could neither load <%s> locally nor from resource server ... skipping\n", file_name.c_str()); 
     757        RRLIB_LOG_PRINT(ERROR, "could neither load <", file_name, "> locally nor from resource server ... skipping"); 
    758758        return false; 
    759759      } 
     
    765765  if (!try_3) 
    766766  { 
    767     RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::CheckAndGetFile() >>> final check failed: could not load <%s> ... skipping\n", full_local_file_name.c_str()); 
     767    RRLIB_LOG_PRINT(ERROR, "final check failed: could not load <", full_local_file_name, "> ... skipping"); 
    768768    return false; 
    769769  } 
Note: See TracChangeset for help on using the changeset viewer.