ÿØÿà JFIF    ÿÛ „  ( %"1!%)+...383,7(-.+  -+++--++++---+-+-----+---------------+---+-++7-----ÿÀ  ß â" ÿÄ     ÿÄ H    !1AQaq"‘¡2B±ÁÑð#R“Ò Tbr‚²á3csƒ’ÂñDS¢³$CÿÄ   ÿÄ %  !1AQa"23‘ÿÚ   ? ôÿ ¨pŸªáÿ —åYõõ\?àÒü©ŠÄï¨pŸªáÿ —åYõõ\?àÓü©ŠÄá 0Ÿªáÿ Ÿå[úƒ ú®ði~TÁbqÐ8OÕpÿ ƒOò¤Oè`–RÂáœá™êi€ßÉ< FtŸI“öÌ8úDf´°å}“¾œ6  öFá°y¥jñÇh†ˆ¢ã/ÃÐ:ªcÈ "Y¡ðÑl>ÿ ”ÏËte:qž\oäŠe÷󲍷˜HT4&ÿ ÓÐü6ö®¿øþßèô Ÿ•7Ñi’•j|“ñì>b…þS?*Óôÿ ÓÐü*h¥£ír¶ü UãS炟[AÐaè[ûª•õ&õj?†Éö+EzP—WeÒírJFt ‘BŒ†Ï‡%#tE Øz ¥OÛ«!1›üä±Í™%ºÍãö]°î(–:@<‹ŒÊö×òÆt¦ãº+‡¦%ÌÁ²h´OƒJŒtMÜ>ÀÜÊw3Y´•牋4ǍýʏTì>œú=Íwhyë,¾Ôò×õ¿ßÊa»«þˆѪQ|%6ž™A õ%:øj<>É—ÿ Å_ˆCbõ¥š±ý¯Ýƒï…¶|RëócÍf溪“t.СøTÿ *Ä¿-{†çàczůŽ_–^XþŒ±miB[X±d 1,é”zEù»& î9gœf™9Ð'.;—™i}!ôšåîqêÛ٤ёý£½ÆA–àôe"A$˝Úsäÿ ÷Û #°xŸëí(l »ý3—¥5m! rt`†0~'j2(]S¦¦kv,ÚÇ l¦øJA£Šƒ J3E8ÙiŽ:cÉžúeZ°€¯\®kÖ(79«Ž:¯X”¾³Š&¡* ….‰Ž(ÜíŸ2¥ª‡×Hi²TF¤ò[¨íÈRëÉ䢍mgÑ.Ÿ<öäS0í„ǹÁU´f#Vß;Õ–…P@3ío<ä-±»Ž.L|kªÀê›fÂ6@»eu‚|ÓaÞÆŸ…¨ááå>åŠ?cKü6ùTÍÆ”†sĤÚ;H2RÚ†õ\Ö·Ÿn'¾ ñ#ºI¤Å´%çÁ­‚â7›‹qT3Iï¨ÖÚ5I7Ë!ÅOóŸ¶øÝñØôת¦$Tcö‘[«Ö³šÒ';Aþ ¸èíg A2Z"i¸vdÄ÷.iõ®§)¿]¤À†–‡É&ä{V¶iŽ”.Ó×Õÿ û?h¬Mt–íª[ÿ Ñÿ ÌV(í}=ibÔ¡›¥¢±b Lô¥‡piη_Z<‡z§èŒ)iÖwiÇ 2hÙ3·=’d÷8éŽ1¦¸c¤µ€7›7Ø ð\á)} ¹fËí›pAÃL%âc2 í§æQz¿;T8sæ°qø)QFMð‰XŒÂ±N¢aF¨…8¯!U  Z©RÊ ÖPVÄÀÍin™Ì-GˆªÅËŠ›•zË}º±ŽÍFò¹}Uw×#ä5B¤{î}Ð<ÙD é©¤&‡ïDbàÁôMÁ." ¤‡ú*õ'VŽ|¼´Úgllº¼klz[Æüï÷Aób‡Eÿ dÑ»Xx9ÃÜ£ÁT/`¼¸vI±Ýµ·Ë‚“G³þ*Ÿû´r|*}<¨îºœ @¦mÄ’M¹”.œ«Y–|6ÏU¤jç¥ÕÞqO ˜kDÆÁ¨5ÿ š;ÐЦ¦€GÙk \ –Þ=â¼=SͧµªS°ÚÍpÜãQűÀõ¬?ÃÁ1Ñ•õZà?hóœ€ L¦l{Y*K˜Ù›zc˜–ˆâ ø+¾ ­-Ök¥%ùEÜA'}ˆ><ÊIè“bpÍ/qÞâvoX€w,\úªò6Z[XdÒæ­@Ö—€$òJí#é>'°Ú ôª˜<)4ryÙ£|óAÅn5žêŸyÒäMÝ2{"}‰–¤l÷ûWX\l¾Á¸góÉOÔ /óñB¤f¸çñ[.P˜ZsÊË*ßT܈§QN¢’¡¨§V¼(Üù*eÕ“”5T¨‹Âê¥FŒã½Dü[8'Ò¥a…Ú¶k7a *•›¼'Ò·\8¨ª\@\õ¢¦íq+DÙrmÎ…_ªæ»ŠÓœ¡¯’Ré9MÅ×D™lælffc+ŒÑ,ý™ÿ ¯þǤ=Å’Á7µ÷ÚÛ/“Ü€ñýã¼àí¾ÕÑ+ƒ,uµMâÀÄbm:ÒÎPæ{˜Gz[ƒ¯«® KHà`ߨŠéí¯P8Aq.C‰ à€kòpj´kN¶qô€…Õ,ÜNŠª-­{Zö’æû44‰sŽè‰îVíRœÕm" 6?³D9¡ÇTíÅꋇ`4«¸ÝÁô ï’ýorqКÇZ«x4Žâéþuïf¹µö[P ,Q£éaX±`PÉÍZ ¸äYúg üAx ’6Lê‚xÝÓ*äQ  Ï’¨hÍ =²,6ï#rÃ<¯–£»ƒ‹,–ê•€ aÛsñ'%Æ"®ÛüìBᝠHÚ3ß°©$“XnœÖ’î2ËTeûìxîß ¦å¿çÉ ðK§þ{‘t‚Ϋ¬jéîZ[ ”š7L¥4VÚCE×]m¤Øy”ä4-dz£œ§¸x.*ãÊÊ b÷•h:©‡¦s`BTÁRû¾g⻩‹jø sF¢àJøFl‘È•Xᓁà~*j¯ +(ÚÕ6-£¯÷GŠØy‚<Ç’.F‹Hœw(+)ÜÜâÈzÄäT§FߘãÏ;DmVœ3Àu@mÚüXÝü•3B¨òÌÁÛ<·ÃÜ z,Ì@õÅ·d2]ü8s÷IôÞ¯^Ç9¢u„~ëAŸï4«M? K]­ÅàPl@s_ p:°¬ZR”´›JC[CS.h‹ƒïËœ«Æ]–÷ó‚wR×k7X‰k›‘´ù¦=¡«‰¨¨Â')—71ó’c‡Ðúµ `é.{§p¹ój\Ž{1h{o±Ý=áUÊïGÖŒõ–-BÄm+AZX¶¡ ïHðæ¥JmÙ;…䡟ˆ¦ ° äšiÉg«$üMk5¤L“’çÊvïâï ,=f“"íἊ5ô¬x6{ɏžID0e¸vçmi'︧ºð9$ò¹÷*£’9ÿ ²TÔ…×>JV¥}Œ}$p[bÔ®*[jzS*8 ”·T›Í–ñUîƒwo$áè=LT™ç—~ô·¤ÈÚ$榍q‰„+´kFm)ž‹©i–ËqÞŠ‰à¶ü( ‚•§ •°ò·‡#5ª•µÊ﯅¡X¨šÁ*F#TXJÊ ušJVÍ&=iÄs1‚3•'fý§5Ñ<=[íÞ­ PÚ;ѱÌ_~Ä££8rÞ ²w;’hDT°>ÈG¬8Á²ÚzŽ®ò®qZcqJêäÞ-ö[ܘbň±çb“ж31²n×iƒðÕ;1¶þÉ ªX‰,ßqÏ$>•î íZ¥Z 1{ç൵+ƒÕµ¥°T$§K]á»Ûï*·¤tMI’ÂZbŽÕiÒ˜}bÓ0£ª5›¨ [5Ž^ÝœWøÂÝh° ¢OWun£¤5 a2Z.G2³YL]jåtì”ä ÁÓ‘%"©<Ôúʰsº UZvä‡ÄiÆÒM .÷V·™ø#kèýiíÌ–ª)µT[)BˆõÑ xB¾B€ÖT¨.¥~ð@VĶr#¸ü*åZNDŽH;âi ],©£öØpù(šºãö¼T.uCê•4@ÿ GÕÛ)Cx›®0ø#:ÏðFÒbR\(€€Ä®fã4Þ‰Fä¯HXƒÅ,†öEÑÔÜ]Öv²?tLÃvBY£ú6Êu5ÅAQ³1‘’¬x–HŒÐ‡ ^ ¸KwJôÖŽ5×CÚ¨vÜ«/B0$×k°=ðbÇ(Ï)w±A†Á† 11Í=èQšµ626ŒÜ/`G«µ<}—-Ö7KEHÈÉðóȤmݱû±·ø«Snmá=“䫚mݱŸ¡¶~ó·“äUóJæúòB|E LêŽy´jDÔ$G¢þÐñ7óR8ýÒ…Ç› WVe#·Ÿ p·Fx~•ݤF÷0Èÿ K¯æS<6’¡WШ; ´ÿ ¥Êø\Òuî†åÝ–VNœkÒ7oòX¨Á­Ø÷FÎÑä±g÷ÿ M~Çî=p,X´ ÝÌÚÅ‹’ÃjÖ.ØöÏñ qïQ¤ÓZE†° =6·]܈ s¸>v•Ž^Ý\wq9r‰Î\¸¡kURÒ$­*‹Nq?Þª*!sŠÆ:TU_u±T+øX¡ ®¹¡,ÄâÃBTsÜ$Ø›4m椴zÜK]’’›Pƒ @€#â˜`é¹=I‡fiV•Ôî“nRm+µFPOhÍ0B£ €+¬5c v•:P'ÒyÎ ‰V~‚Ó†ÖuókDoh$å\*ö%Ю=£«…aȼ½÷Û.-½VŒŠ¼'lyî±1¬3ó#ÞE¿ÔS¤gV£m›=§\û"—WU¤ÚǼÿ ÂnÁGŒÃ ‚õN D³õNÚíŒÕ;HôyÄÈ©P¹Ä{:?R‘Ô¨âF÷ø£bÅó® JS|‚R÷ivýáâ€Æé¡è³´IئÑT!§˜•ت‚¬â@q€wnïCWÄ@JU€ê¯m6]Ï:£âx'+ÒðXvÓ¦Úm=–´7œ $ì“B£~p%ÕŸUþ« N@¼üï~w˜ñø5®—'Ôe»¤5ã//€ž~‰Tþ›Å7•#¤× Íö pÄ$ùeåì*«ÓŠEØWEÈsßg ¦ûvžSsLpºÊW–âµEWöˬH; ™!CYõZ ÃÄf æ#1W. \uWâ\,\Çf j’<qTbên›Î[vxx£ë 'ö¨1›˜ÀM¼Pÿ H)ƒêêŒA7s,|F“ 꺸k³9Ìö*ç®;Ö!Ö$Eiž•¹ÒÚ†ýóéÝû¾ÕS®ó$’NÝäŸz¤5r¦ãÄÃD÷Üø!°ø‡Ô&@m™Ì^Ãä­d q5Lnÿ N;.6½·N|#ä"1Nƒx“ã<3('&ñßt  ~ªu”1Tb㫨9ê–›–bìd$ߣ=#ÕãÒmU¯eí$EFù5ýYô櫨æì™Ç—±ssM]·á¿0ÕåJRÓªîiƒ+O58ÖñªŠÒx" \µâá¨i’¤i —Ö ” M+M¤ë9‚‰A¦°Qõ¾ßøK~¼Ã‘g…Ö´~÷Ï[3GUœÒ½#…kàÔ®Ò”‰³·dWV‰IP‰Ú8u¹”E ÖqLj¾êÕCBš{A^Âß;–¨`¯¬ìö ˼ ×tìø.tƐm*n¨y4o&Àx¥n¦×î‡aupáÛj8¿m›è¶ã!o½;ß0y^ý×^EÑ¿ÒjzŒ­)vÚÑnÄL …^ªô× ‡—‚3k Îý­hï]içå–îÏ*÷ñþ»Ô CÒjøjÍznˆ´ ¹#b'Fô‹ ‰v¥'’à'T´ƒHýÍ%M‰ ƒ&ÆÇŒï1 ‘ –Þ ‰i¬s žR-Ÿ kЬá¬7:þ 0ŒÅÒÕ/aÙ¬ÃÝ#Úøœ ©aiVc‰. ¹¦ãµ” ›Yg¦›ÆÎýº°f³7ƒhá·¸­}&D9¡ÂsÉÙÞèŠõØàC™¨ñbFC|´Ü(ŸƒÚÒ-%»'a Ì¿)ËÇn¿úÿ ÞŽX…4ÊÅH^ôΑí@ù¹Eh¶“L8Çjù ¼ÎåVªóR©Ï5uà V4lZß®=€xÖŸ–ÑÈ ÷”¨°¾__yM1tÉ?uÆþIkÄgæ@þ[¢†°XÃJ£j·:nkÅ¢u ‘}âGzö­/IµèЬ¼48q¦F°ŽR¼=ûì{´¯RýicS ÕÛ íNtÍÙï£,w4rêì®»~x(©Uñ§#Ñ&œÕ¤>ÎåÍÓ9’Ö{9eV­[Öjâ²ãu]˜å2›qÑšÕJç0€sÄ|Êëè0튔bÁ>“{×_F`Ø©ºê:µä,v¤ðfc1±"«ÔÍän1#=· Âøv~H½ÐßA¾¿Ü€Óš]Õ; I¾÷ç‚Qi†î¹9ywÔKG˜áñ zQY—§ÃÕZ07§X‚ Áh;ÁM)iÌCH-¯T‘ë|A0{Ò½LÚ–TâÖkÜ’dÀ“rmm»”جPF³ÖcbE§T€ÒxKºû’Ó®7±²(\4ŽÃ¸Uu@j™yĵ;³µ!Á¢b.W¤=mõ´êµK k ¸K^ÜÛ#p*Ü14qkZç5ïë †°5Ï%ÍÛ<Õ¤×Ô¥ê†C Õ´¼ú$ƒÖ“”]Ù¬qÞÚ[4©ý!ûÏ—Áb쳐XµA¬â~`›Çr¸8ìùÝ䫦<>ä÷«?xs´ÇÑ /á;¹øüÊÈÙà{"@Žïzâ¬[âß‚ U_<ÇŸ½4èN˜ú61®qŠu ¦þF£»äJ_ˆÙÎ~ ÞAã–݄ϗrŠD;xTž‘ô`É«…suãO`?³à™ô Lý#Íc5öoæØ‚y´´÷«ZR§<&JÇ+éâô´€i!Àˆ0æAoàðLèÖ-2ŸõW.’t^–(KÁmHµV@xÜÇy®Ñø­â^:Ú3w· 7½¹°ñ¸â¹®:',«Mœ—n­Á+Ãbš LÈ‘ÄnRÓÅœ%¦²‰¨ùQ:¤f‚ "PÕtô¸…cæl…&˜Ú˜Ôkv‹ž+vŠ,=¢v­6—Xy*¥t£«<™:“aîϲ=¦6rO]XI¿Œ÷¤zÚ­›¶ 6÷”w\d ü~v®ˆÌk«^m<ÿ ¢‰Õ\)ùºŽ;… lîÙÅEŠ®cѾ@vnMÏ,¼“ñ•ŽBxðÃzãÇç%3ˆ"}Ù•Åî> BÉú;Ò]V+P˜F_´ßé> Øše|ï‡ÄOmFæÇ ãqÞ$/xÐx­z`ï9"œÜij‚!7.\Td…9M‡•iŽ‹¾‘50ÞŽn¥ß4ÉôO ¹*í^QêËÜÇÌ8=ާs‰'ÂëÙ«á%Pú[O †ÅP¯Vsް.‰,kc¶ ¬A9n˜XÎ-ÞšN["¹QÕ‰ƒMýÁߺXJæÍaLj¾×Ãmã¾ãÚ uñÒþåQô¦¥ /ÄUx:‚ÍÜ’ Đ©ØÝ3V¨‰ÕnÐ6ó*óúK­«…c ¯U òhsý­jóÔj#,ímŒRµ«lbïUTŒÑ8†Ä0œÏr`ð¡¬É Ї ë"À² ™ 6¥ f¶ ¢ÚoܱԷ-<Àî)†a¶ž'Ú»¨TXqØæ¶÷YÄHy˜9ÈIW­YÀuMFë ºÏ’AqÌ4·/Ú †ô'i$øä­=Ä Ý|öK×40è|È6p‘0§)o¥ctî§H+CA-“ xØ|ÐXАç l8íºð3Ø:³¤¬KX¯UÿÙ #!/usr/bin/perl # # fixproc [-min n] [-max n] [-check | -kill | -restart | -exist | -fix] proc ... # # fixproc exit code: # 0 ok # 1 check failed # 2 cannot restart # 3 cannot kill # 4 fix failed if fix is defined as kill or restart, then # cannot kill or cannot restart is return instead # 10 fixproc error # # # Fixes a process named "proc" by performing the specified action. The # actions can be check, kill, restart, exist, or fix. The action is specified # on the command line or is read from a default database, which describes # the default action to take for each process. The database format and # the meaning of each action are described below. # # database format # --------------- # # name foo required # cmd /a/b/name args required # min number optional, defaults to 1 # max number optional, defaults to 1 # # check {null, exist, shell} optional, defaults to exist if not defined # [shell command shell commands needed only if check=shell # ... # shell command # end_shell] keyword end_shell marks end of shell commands # fix {kill, restart, shell} required # [shell command shell commands needed only if fix=shell # ... # shell command # end_shell] keyword end_shell marks end of shell commands # # Blank lines and lines beginning with "#" are ignored. # # # Example: # # name test1 # cmd nice /home/kong/z/test1 > /dev/null & # max 2 # fix shell # xterm& # nice /home/kong/z/test1 > /dev/null & # end_shell # # # actions # ------- # There are 5 possible actions: kill, restart, fix, exist, check. Fix is # defined to be the kill action, the restart action, or a series of shell # commands. Check is optionally defined in the database. If check is not # defined, it defaults to exist. # # If the action is specified on the cmd line, it is executed regardless of # check. The commands executed for each action type is as follow: # # switch action: # kill: # kill process, wait 5 seconds, kill -9 if still exist # if still exist # return "cannot kill" # else # return "ok" # # restart: # execute kill # if kill returned "cannot kill" # return "cannot kill" # restart by issuing cmd to shell # if check defined # execute check # if check succeeds # return "ok" # else # return "cannot restart" # # fix: # if fix=kill # execute kill # else if fix=restart # execute restart # else # execute shell commands # execute check # # check: # if check defined as null # return "fixproc error" # else # execute check # if check succeeds # return (execute exist) # return "check failed" # # exist: # if proc exists in ps && (min <= num. of processes <= max) # return "ok" # else # return "check failed" # # # If the action is not specified on the cmd line, the default action is the # fix action defined in the database. Fix is only executed if check fails: # # if fix defined # if check is not defined as null # execute check # if check succeeds # return "ok" # execute action defined for fix # else # return "fixproc error" # # # If proc is not specified on the command line, return "fixproc error." # Multiple proc's can be defined on the cmd line. When an error occurs # when multiple proc's are specified, the first error encountered halts the # script. # # For check shell scripts, any non-zero exit code means the check has failed. # # # Timothy Kong 3/1995 use File::Temp qw(tempfile); $database_file = '/local/etc/fixproc.conf'; $debug = 0; # specify debug level using -dN # currently defined: -d1 $no_error = 0; $check_failed_error = 1; $cannot_restart_error = 2; $cannot_kill_error = 3; $cannot_fix_error = 4; $fixproc_error = 10; $min = 1; $max = 1; $cmd_line_action = ''; %min = (); %max = (); %cmd = (); %check = (); %fix = (); $shell_lines = (); @proc_list = (); $shell_header = "#!/bin/sh\n"; $shell_end_marker = 'shell_end_marker'; &read_args(); &read_database(); # &dump_database(); # debug only # change the default min. and max. number of processes allowed if ($min != 1) { for $name ( keys (%min) ) { $min{$name} = $min; } } if ($max != 1) { for $name ( keys (%max) ) { $max{$name} = $max; } } # work on one process at a time for $proc ( @proc_list ) { $error_code = &work_on_proc ($proc); ############# uncomment next line when fully working ############ # exit $error_code if ($error_code); die "error_code = $error_code\n" if ($error_code); } # create an executable shell script file sub create_sh_script { local ($file) = pop (@_); local ($fh) = pop (@_); local ($i) = pop (@_); printf (STDERR "create_sh_script\n") if ($debug > 0); $! = $fixproc_error; while ( $shell_lines[$i] ne $shell_end_marker ) { printf ($fh "%s", $shell_lines[$i]); $i++; } close ($fh); chmod 0755, $file; } sub do_fix { local ($proc) = pop(@_); printf (STDERR "do_fix\n") if ($debug > 0); if ($fix{$proc} eq '') { $! = $fixproc_error; die "$0: internal error 4\n"; } if ($fix{$proc} eq 'kill') { return &do_kill ($proc); } elsif ($fix{$proc} eq 'restart') { return &do_restart ($proc); } else { # it must be "shell", so execute the shell script defined in database local ($tmpfh, $tmpfile) = tempfile("fix_XXXXXXXX", DIR => "/tmp"); &create_sh_script ($fix{$proc}, $tmpfh, $tmpfile); # return code is number divided by 256 $error_code = (system "$tmpfile") / 256; unlink($tmpfile); return ($fix_failed_error) if ($error_code != 0); # sleep needed here? return &do_exist ($proc); } } sub do_check { local ($proc) = pop(@_); printf (STDERR "do_check\n") if ($debug > 0); if ($check{$proc} eq '') { $! = $fixproc_error; die "$0: internal error 2\n"; } if ($check{$proc} ne 'exist') { # if not "exist", then it must be "shell", so execute the shell script # defined in database local ($tmpfh, $tmpfile) = tempfile("check_XXXXXXXX", DIR => "/tmp"); &create_sh_script ($fix{$proc}, $tmpfh, $tmpfile); # return code is number divided by 256 $error_code = (system "$tmpfile") / 256; unlink($tmpfile); return ($check_failed_error) if ($error_code != 0); # check passed, continue } return &do_exist ($proc); } sub do_exist { local ($proc) = pop(@_); printf (STDERR "do_exist\n") if ($debug > 0); # do ps, check to see if min <= no. of processes <= max $! = $fixproc_error; open (COMMAND, "/bin/ps -e | /bin/grep $proc | /bin/wc -l |") || die "$0: can't run ps-grep-wc command\n"; $proc_count = ; if (($proc_count < $min{$proc}) || ($proc_count > $max{$proc})) { return $check_failed_error; } return $no_error; } sub do_kill { local ($proc) = pop(@_); local ($second_kill_needed); printf (STDERR "do_kill\n") if ($debug > 0); # first try kill $! = $fixproc_error; open (COMMAND, "/bin/ps -e | /bin/grep $proc |") || die "$0: can't run ps-grep-awk command\n"; while () { # match the first field of ps -e $! = $fixproc_error; /^\s*(\d+)\s/ || die "$0: can't match ps -e output\n"; system "kill $1"; } # if process still exist, try kill -9 sleep 2; $! = $fixproc_error; open (COMMAND, "/bin/ps -e | /bin/grep $proc |") || die "$0: can't run ps-grep-awk command\n"; $second_kill_needed = 0; while () { # match the first field of ps -e $! = $fixproc_error; /^\s*(\d+)\s/ || die "$0: can't match ps -e output\n"; system "kill -9 $1"; $second_kill_needed = 1; } return ($no_error) if ($second_kill_needed == 0); # see if kill -9 worked sleep 2; $! = $fixproc_error; open (COMMAND, "/bin/ps -e | /bin/grep $proc |") || die "$0: can't run ps-grep-awk command\n"; while () { # a process still exist, return error return $cannot_kill_error; } return $no_error; # good, all dead } sub do_restart { local ($proc) = pop(@_); local ($error_code); printf (STDERR "do_restart\n") if ($debug > 0); $error_code = &do_kill ($proc); return $error_code if ($error_code != $no_error); die "$0: internal error 3\n" if ($cmd{$proc} eq ''); system "$cmd{$proc}"; # sleep needed here? if ($check{$proc} ne 'null') { return $no_error if (&do_check($proc) == $no_error); return $cannot_restart_error; } } sub work_on_proc { local ($proc) = pop(@_); local ($error_code); printf (STDERR "work_on_proc\n") if ($debug > 0); if ($cmd_line_action eq '') { # perform action from database if ($check{$proc} ne 'null') { $error_code = &do_check ($proc); if ($error_code != $check_failed_error) { return $error_code; } } return &do_fix ($proc); } else { # perform action from command line $error_code = $no_error; if ($cmd_line_action eq 'kill') { $error_code = &do_kill ($proc); } elsif ($cmd_line_action eq 'restart') { $error_code = &do_restart ($proc); } elsif ($cmd_line_action eq 'fix') { $error_code = &do_fix ($proc); } elsif ($cmd_line_action eq 'check') { if ( $check{$proc} eq 'null' ) { exit $fixproc_error; } $error_code = &do_check ($proc); } elsif ($cmd_line_action eq 'exist') { $error_code = &do_exist ($proc); } else { $! = $fixproc_error; die "$0: internal error 1\n"; } } } sub dump_database { local ($name); for $name (keys(%cmd)) { printf ("name\t%s\n", $name); printf ("cmd\t%s\n", $cmd{$name}); printf ("min\t%s\n", $min{$name}); printf ("max\t%s\n", $max{$name}); if ( $check{$name} =~ /[0-9]+/ ) { printf ("check\tshell\n"); $i = $check{$name}; while ( $shell_lines[$i] ne $shell_end_marker ) { printf ("%s", $shell_lines[$i]); $i++; } } else { printf ("check\t%s\n", $check{$name}); } if ( $fix{$name} =~ /[0-9]+/ ) { printf ("fix\tshell\n"); $i = $fix{$name}; while ( $shell_lines[$i] ne $shell_end_marker ) { printf ("%s", $shell_lines[$i]); $i++; } } else { printf ("fix\t%s\n", $fix{$name}); } printf ("\n"); } } sub read_database { local ($in_check_shell_lines) = 0; local ($in_fix_shell_lines) = 0; local ($name) = ''; local ($str1); local ($str2); $! = $fixproc_error; open (DB, $database_file) || die 'cannot open database file $database_file\n'; while () { if ((! /\S/) || (/^[ \t]*#.*$/)) { # ignore blank lines or lines beginning with "#" } elsif ($in_check_shell_lines) { if ( /^\s*end_shell\s*$/ ) { $in_check_shell_lines = 0; push (@shell_lines, $shell_end_marker); } else { push (@shell_lines, $_); } } elsif ($in_fix_shell_lines) { if ( /^\s*end_shell\s*$/ ) { $in_fix_shell_lines = 0; push (@shell_lines, $shell_end_marker); } else { push (@shell_lines, $_); } } else { if ( ! /^\s*(\S+)\s+(\S.*)\s*$/ ) { $! = $fixproc_error; die "$0: syntax error in database\n$_"; } $str1 = $1; $str2 = $2; if ($str1 eq 'name') { &finish_db_entry($name); $name = $str2; } elsif ($str1 eq 'cmd') { $! = $fixproc_error; die "$0: cmd specified before name in database\n$_\n" if ($name eq ''); die "$0: cmd specified multiple times for $name in database\n" if ($cmd{$name} ne ''); $cmd{$name} = $str2; } elsif ($str1 eq 'min') { $! = $fixproc_error; die "$0: min specified before name in database\n$_\n" if ($name eq ''); die "$0: min specified multiple times in database\n$_\n" if ($min{$name} ne ''); die "$0: non-numeric min value in database\n$_\n" if ( ! ($str2 =~ /[0-9]+/ )); $min{$name} = $str2; } elsif ($str1 eq 'max') { $! = $fixproc_error; die "$0: max specified before name in database\n$_\n" if ($name eq ''); die "$0: max specified multiple times in database\n$_\n" if ($max{$name} ne ''); die "$0: non-numeric max value in database\n$_\n" if ( ! ($str2 =~ /[0-9]+/ )); $max{$name} = $str2; } elsif ($str1 eq 'check') { $! = $fixproc_error; die "$0: check specified before name in database\n$_\n" if ($name eq ''); die "$0: check specified multiple times in database\n$_\n" if ($check{$name} ne ''); if ( $str2 eq 'shell' ) { # if $check{$name} is a number, it is a pointer into # $shell_lines[] where the shell commands are kept $shell_lines[$#shell_lines+1] = $shell_header; $check{$name} = $#shell_lines; $in_check_shell_lines = 1; } else { $check{$name} = $str2; } } elsif ($str1 eq 'fix') { $! = $fixproc_error; die "$0: fix specified before name in database\n$_\n" if ($name eq ''); die "$0: fix specified multiple times in database\n$_\n" if ($fix{$name} ne ''); if ( $str2 eq 'shell' ) { # if $fix{$name} is a number, it is a pointer into # $shell_lines[] where the shell commands are kept $shell_lines[$#shell_lines+1] = $shell_header; $fix{$name} = $#shell_lines; $in_fix_shell_lines = 1; } else { $fix{$name} = $str2; } } } } &finish_db_entry($name); } sub finish_db_entry { local ($name) = pop(@_); if ($name ne '') { $! = $fixproc_error; die "$0: fix not defined for $name in database\n" if ($fix{$name} eq ''); die "$0: cmd not defined for $name in database\n" if ($cmd{$name} eq ''); $check{$name} = 'exist' if ($check{$name} eq ''); $max{$name} = 1 if ($max{$name} eq ''); $min{$name} = 1 if ($min{$name} eq ''); } } sub read_args { local ($i) = 0; local ($arg); local ($action_arg_count) = 0; while ( $i <= $#ARGV ) { $arg = $ARGV[$i]; if (($arg eq '-min') || ($arg eq '-max')) { if (($i == $#ARGV - 1) || ($ARGV[$i+1] =~ /\D/)) # \D is non-numeric { $! = $fixproc_error; die "$0: numeric arg missing after -min or -max\n"; } if ($arg eq '-min') { $min = $ARGV[$i+1]; } else { $max = $ARGV[$i+1]; } $i += 2; } elsif ($arg eq '-kill') { $cmd_line_action = 'kill'; $action_arg_count++; $i++; } elsif ($arg eq '-check') { $cmd_line_action = 'check'; $action_arg_count++; $i++; } elsif ($arg eq '-restart') { $cmd_line_action = 'restart'; $action_arg_count++; $i++; } elsif ($arg eq '-exist') { $cmd_line_action = 'exist'; $action_arg_count++; $i++; } elsif ($arg eq '-fix') { $cmd_line_action = 'fix'; $action_arg_count++; $i++; } elsif ($arg =~ /-d(\d)$/) { $debug = $1; $i++; } elsif ($arg =~ /^-/) { $! = $fixproc_error; die "$0: unknown switch $arg\n"; } else { push (@proc_list, $arg); $i++; } } $! = $fixproc_error; die "$0: no process specified\n" if ($#proc_list == -1); die "$0: more than one action specified\n" if ($action_arg_count > 1); }