When init scripts go bad



  • This is the functional body of an init script from a frightningly expensive piece of CDS software.  All that was omitted was the usual headers about chkconfig and such:

    the software has been renamed Twitch 

    SERVER_DIR=/apps/Twitch

    SplitServerPath()
    {
       if [ -f  ./TwitchTmp.awk ] ; then
          rm ./TwitchTmp.awk
       fi
      
       echo " {                                                         " > TwitchTmp.awk  
       echo "     cmd=""                                              " > TwitchTmp.awk
       echo "     if (ACTION=="start")                                " >>TwitchTmp.awk
       echo "     {                                                     " >>TwitchTmp.awk  
       echo "        cmd="/bin/TwitchDaemon start "                 " >>TwitchTmp.awk
       echo "     }                                                     " >>TwitchTmp.awk
       echo "     if (ACTION=="stop")                                 " >>TwitchTmp.awk
       echo "     {                                                     " >>TwitchTmp.awk
       echo "        cmd="/bin/TwitchDaemon stop "                  " >>TwitchTmp.awk
       echo "     }                                                     " >>TwitchTmp.awk
       echo "     n=split( serverDir, path, ":" )                     " >>TwitchTmp.awk
       echo "     for ( i = 1; i <= n; ++i )                            " >>TwitchTmp.awk
       echo "     {                                                     " >>TwitchTmp.awk
       echo "        if( length (path[i] ) > 0)                         " >>TwitchTmp.awk
       echo "        {                                                  " >>TwitchTmp.awk
       echo "             system(path[i] cmd path[i])                   " >>TwitchTmp.awk
       echo "        }                                                  " >>TwitchTmp.awk
       echo "     }                                                     " >>TwitchTmp.awk
       echo "  }                                                        " >>TwitchTmp.awk
    }

    id > TwitchOut.txt
    SplitServerPath
    gawk -v serverDir=$SERVER_DIR -v ACTION=$1 -f TwitchTmp.awk TwitchOut.txt
    rm TwitchOut.txt
    rm TwitchTmp.awk
     

    That's right, we echo out some Awk code to try and find the app, ignoring the coded app path, and then we run the awk.  If there are multiple copies on the system for some reason, each will get started.  Oh and there are syntax errors on the echoing!

    JSP 


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.