Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-4743

mysqld_safe cleaning (or possible replacement)

    XMLWordPrintable

Details

    Description

      The mysqld_safe script has some part of it that could be cleaned or simplified (or replaced with a Perl script for example which would be more portable as many shells doesnt follow the POSIX thoroughly and many syntaxes are shell dependant, not to mention the tools such as sed or grep used on the script that might not act the same on different systems).

      Here are some examples and ideas :

            PROC=`ps xaww | grep "$ledir/$MYSQLD\>" | grep -v "grep" | grep "pid-file=$pid_file" | sed -n '$p'` 
       
            for T in $PROC
            do
              break
            done

      sed -n '$p' returns only the last line (it does the same as tail -1) and the loop is used to return only the first argument of the $PROC output (which is the PID) but this construction/logic is not the most simple/readable.
      Here is a simpler approach :

      T=$(ps --no-headers -C mysqld -o pid,command |grep -m1 -E "$ledir/$MYSQLD .*--pid-file=$pid_file(\$|\s)" |cut -d' ' -f1)


      fmode=`echo "$UMASK" | sed -e 's/[^0246]//g'`
      octalp=`echo "$fmode"|cut -c1`
      fmlen=`echo "$fmode"|wc -c|sed -e 's/ //g'`
      if [ "x$octalp" != "x0" -o "x$UMASK" != "x$fmode" -o "x$fmlen" != "x5" ]
      then
        fmode=0640
        [...]
      fi
      fmode=`echo "$fmode"|cut -c3-4`
      fmode="6$fmode"
      if [ "x$UMASK" != "x0$fmode" ]
      then
        echo "UMASK corrected from $UMASK to 0$fmode ..."
      fi

      Can be replaced by :

      if ! echo $UMASK |grep -qE '^06[0246]{2}$'
      then
        fmode=0640
        [...]
      else
        fmode=$UMASK
      fi


      SET_USER=2
      parse_arguments `$print_defaults $defaults --loose-verbose --mysqld`
      if test $SET_USER -eq 2
      then
        SET_USER=0
      fi

      Why set SET_USER=2 to re-set it to 0, plus the SET_USER variable is only tested once to check if its value = 1, so leaving only the parse_arguments would do the same.


      Throwing a warning if "my_print_defaults" hasnt been found could be a good thing.


      fmlen=`echo "$fmode"|wc -c|sed -e 's/ //g'`

      Can be replaced by :

      fmlen="${#fmode}"


      if test -w / -o "$USER" = "root"

      Checking that the user has the write permission on / could be a bit far fetched to check if its a root user that would have a different name, checking if its uid is 0 could be a better check.


          if [...]
          then
              :
          else

      This construction can be replaced by

          if ! [...]
          then


      Using ps xaww |grep XXX isnt really clean to determine how many processes are running, as it is already limited to Linux, using directly the informations on /proc or ps -o, for example :

      numofproces=`ps xaww | grep -v "grep" | grep "$ledir/$MYSQLD\>" | grep -c "pid-file=$pid_file"`

      Can be replaced with :

      ps --no-headers -C mysqld -o command |grep -cE "$ledir/$MYSQLD .*--pid-file=$pid_file(\$|\s)"


      Replacing the `cmd` syntax with the easier to read $(cmd) one.
      Some tests use the if test [...]; then syntax while others use the if [ [...] ]; then one.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jb-boin Jean Weisbuch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.