public static void prepare ( String fname ) { if ( ! "Linux" . equalsIgnoreCase ( System . getProperty ( "os.name" ) ) ) { System . err . println ( "Linux system required for FailMon. Exiting..." ) ; System . exit ( 0 ) ; } System . setProperty ( "log4j.configuration" , "conf/log4j.properties" ) ; PropertyConfigurator . configure ( "conf/log4j.properties" ) ; LOG = LogFactory . getLog ( "org.apache.hadoop.contrib.failmon" ) ; logInfo ( "********** FailMon started ***********" ) ; // read parseState file PersistentState . readState ( "conf/parsing.state" ) ; try { FileInputStream propFile = new FileInputStream ( fname ) ; fmProperties . load ( propFile ) ; propFile . close ( ) ; } catch ( FileNotFoundException e1 ) { e1 . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } ready = true ; try { String sudo_prompt = "passwd_needed:" ; String echo_txt = "access_ok" ; Process p = Runtime . getRuntime ( ) . exec ( "sudo -S -p " + sudo_prompt + " echo " + echo_txt ) ; InputStream inps = p . getInputStream ( ) ; InputStream errs = p . getErrorStream ( ) ; while ( inps . available ( ) < echo_txt . length ( ) && errs . available ( ) < sudo_prompt . length ( ) ) Thread . sleep ( 100 ) ; byte [ ] buf ; String s ; if ( inps . available ( ) >= echo_txt . length ( ) ) { buf = new byte [ inps . available ( ) ] ; inps . read ( buf ) ; s = new String ( buf ) ; if ( s . startsWith ( echo_txt ) ) { superuser = true ; logInfo ( "Superuser privileges found!" ) ; } else { // no need to read errs superuser = false ; logInfo ( "Superuser privileges not found." ) ; } } } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } }
Initializes structures needed by other methods . Also determines whether the executing user has superuser privileges .