Changeset 30172 for main/trunk/search4j


Ignore:
Timestamp:
09/02/15 16:02:44 (5 years ago)
Author:
ak19
Message:

John Thompson fixed a search4j bug that manifested on his Ubuntu and made the java version 0.0.0_00 because search4j expected a certain line of output (starting 'java version') to appear at the very start of the response returned from running java -version. However there may be other lines in the output that precede this, which John's patch allows for.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/search4j/libsearch4j.cpp

    r28699 r30172  
    240240   
    241241    if ( result == 0 ) {
    242         if ( strcmp( output.substr( 0, 12 ).c_str() , "java version" ) == 0 || true ) {
    243             era_ = atoi( output.substr(14,1).c_str() );
    244             major_ = atoi( output.substr(16,1).c_str() );
    245             minor_ = atoi( output.substr(18,1).c_str() );
    246             update_ = atoi( output.substr(20,2).c_str() );
    247         } else {
    248             healthy_=false;
    249         }
    250     } else {
    251         healthy_ = false;
     242      // 22 is the length of sentinel string plus typical version value
     243      int max_search_length = output.length() - 22;
     244      int caret = 0;
     245      bool found = false;
     246      while (caret < max_search_length && !found) {
     247        if ( strcmp( output.substr( caret, 12 ).c_str() , "java version" ) == 0 ) {
     248          era_ = atoi( output.substr(caret + 14,1).c_str() );
     249          major_ = atoi( output.substr(caret + 16,1).c_str() );
     250          minor_ = atoi( output.substr(caret + 18,1).c_str() );
     251          update_ = atoi( output.substr(caret + 20,2).c_str() );
     252          found = true;
     253        }
     254        else {
     255          caret++;
     256        }
     257      }
     258      if (!found) {
     259        healthy_ = false;
     260      }
     261    }
     262    else {
     263      healthy_ = false;
    252264    }
    253265}
Note: See TracChangeset for help on using the changeset viewer.