mariadb: Use double quotes where possible
authorMichal Hrusecky <michal.hrusecky@turris.com>
Thu, 1 Oct 2020 14:10:10 +0000 (16:10 +0200)
committerMichal Hrusecky <michal.hrusecky@turris.com>
Fri, 2 Oct 2020 08:06:38 +0000 (10:06 +0200)
Just to make sure, add double quotes around strings and various
variables. In some cases it could prevent some issues, in other cases it
is just a good practice.

Signed-off-by: Michal Hrusecky <michal.hrusecky@turris.com>
utils/mariadb/files/mysqld.init

index 717e8d68d04254ec1707371bc416f5550ab9436b..54fe53389e5c2bfe41a03fa8f66cb690d002d776 100644 (file)
@@ -9,12 +9,12 @@ NAME=mysqld
 LOGGER="/usr/bin/logger -p user.err -s -t $NAME --"
 [ -x "$LOGGER" ] || LOGGER="echo"
 
-MYSQLADMIN=/usr/bin/mysqladmin
-MYSQLD=/usr/bin/$NAME
-MYSQLDSAFE=/usr/bin/mysqld_safe
+MYSQLADMIN="/usr/bin/mysqladmin"
+MYSQLD="/usr/bin/$NAME"
+MYSQLDSAFE="/usr/bin/mysqld_safe"
 
 # mysqladmin likes to read /root/.my.cnf which could cause issues.
-export HOME=/etc/mysql
+export HOME="/etc/mysql"
 
 # Safeguard (relative paths, core dumps...)
 cd /
@@ -41,8 +41,8 @@ mysqld_status() {
        fi
 
        ps_alive=0
-       pidfile=$(mysqld_get_param pid-file)
-       if [ -f "$pidfile" ] && kill -0 $(cat "$pidfile") >/dev/null 2>&1; then
+       pidfile="$(mysqld_get_param pid-file)"
+       if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" >/dev/null 2>&1; then
                ps_alive=1
        fi
 
@@ -63,85 +63,85 @@ start() {
 
        hint="please fix your server configuration in /etc/mysql/"
 
-       for i in $MYSQLD $MYSQLADMIN $MYSQLDSAFE; do
-               if [ ! -x $i ]; then
-                       $LOGGER $i is missing
+       for i in "$MYSQLD" "$MYSQLADMIN" "$MYSQLDSAFE"; do
+               if [ ! -x "$i" ]; then
+                       $LOGGER "$i is missing"
                        exit 1
                fi
        done
 
-       if [ ! -r $conf ]; then
-               $LOGGER $conf cannot be read
+       if [ ! -r "$conf" ]; then
+               $LOGGER "$conf cannot be read"
                exit 1
        fi
 
-       config_load $NAME
+       config_load "$NAME"
 
        config_get_bool enabled general enabled 0
-       if [ $enabled -eq 0 ]; then
-               $LOGGER service not enabled in /etc/config/$NAME
+       if [ "$enabled" -eq 0 ]; then
+               $LOGGER "service not enabled in /etc/config/$NAME"
                exit 1
        fi
 
        config_get options general options
 
-       datadir=$(mysqld_get_param datadir)
-       tmpdir=$(mysqld_get_param tmpdir)
+       datadir="$(mysqld_get_param datadir)"
+       tmpdir="$(mysqld_get_param tmpdir)"
 
        if [ -z "$datadir" ]; then
-               $LOGGER datadir is not set
-               $LOGGER $hint
+               $LOGGER "datadir is not set"
+               $LOGGER "$hint"
                exit 1
        fi
 
        if [ -z "$tmpdir" ]; then
-               $LOGGER tmpdir is not set
-               $LOGGER $hint
+               $LOGGER "tmpdir is not set"
+               $LOGGER "$hint"
                exit 1
        fi
 
        if [ ! -f "$datadir/mysql/tables_priv.MAD" ]; then
                args="--force"
-               basedir=$(mysqld_get_param basedir)
+               basedir="$(mysqld_get_param basedir)"
                [ -n "$basedir" ] && args="$args --basedir=$basedir"
 
-               $LOGGER Cannot detect privileges table. You might need to run
-               $LOGGER \'mysql_install_db "$args"\'
-               $LOGGER to initialize the system tables.
+               $LOGGER "Cannot detect privileges table. You might need to run"
+               $LOGGER "'mysql_install_db \"$args\"'"
+               $LOGGER "to initialize the system tables."
                exit 1
        fi
 
        # Start daemon
        if mysqld_status check_alive; then
-               $LOGGER already running
+               $LOGGER "server is already running"
        else
-               for i in $logdir $rundir; do
+               for i in "$logdir" "$rundir"; do
                        opts="-m 0750"
-                       if ! [ -e $i ]; then
+                       if ! [ -e "$i" ]; then
                                # $rundir needs to be accessible for
                                # clients
-                               if [ $i = $rundir ]; then
+                               if [ "$i" = "$rundir" ]; then
                                        opts=
                                fi
-                               mkdir -p $opts $i
-                               [ -d $i ] && chown mariadb:mariadb $i
+                               mkdir -p $opts "$i"
+                               [ -d "$i" ] && chown mariadb:mariadb "$i"
                        fi
                done
 
-               $MYSQLDSAFE $options >/dev/null 2>&1 &
+               "$MYSQLDSAFE" $options >/dev/null 2>&1 &
        fi
 }
 
 stop() {
        if ! mysqld_status check_dead; then
-               $MYSQLADMIN shutdown
+               "$MYSQLADMIN" shutdown
        fi
 }
 
 reload() {
        if mysqld_status check_alive; then
-               $MYSQLADMIN reload
+               "$MYSQLADMIN" reload
        else
-               $LOGGER not running
+               $LOGGER "server is not running"
        fi
 }