All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Mauro S." <mau.salvi@tin.it>
To: Jan Kiszka <jan.kiszka@siemens.com>,
	"xenomai@xenomai.org" <xenomai@xenomai.org>
Subject: Re: [PATCH v2] utils/net/rtnet.in: fixes after shellcheck inspection
Date: Thu, 5 May 2022 17:39:51 +0200	[thread overview]
Message-ID: <d9a4b75d-81bb-28ea-4bee-293f19637c05@tin.it> (raw)
In-Reply-To: <fc9fc714-e1e8-8132-7cc3-76e7ee1f4d87@siemens.com>

Il 05/05/22 17:25, Jan Kiszka ha scritto:
> On 05.05.22 17:12, Mauro S. wrote:
>> Signed-off-by: Mauro Salvini <mau.salvi@tin.it>
>> ---
>>   utils/net/rtnet.in | 76 +++++++++++++++++++++++-----------------------
>>   1 file changed, 38 insertions(+), 38 deletions(-)
>>
>> diff --git a/utils/net/rtnet.in b/utils/net/rtnet.in
>> index f81a7bb0a..9f136b804 100644
>> --- a/utils/net/rtnet.in
>> +++ b/utils/net/rtnet.in
>> @@ -9,7 +9,7 @@ RTNETCFG="@sysconfdir@/rtnet.conf"
>>
>>   debug_func() {
>>       echo "$*"
>> -    eval $*
>> +    eval "$@"
>>   }
>>
>>   usage() {
>> @@ -33,35 +33,35 @@ EOF
>>   init_rtnet() {
>>       modprobe rtnet >/dev/null || exit 1
>>       modprobe rtipv4 >/dev/null || exit 1
>> -    modprobe $RT_DRIVER $RT_DRIVER_OPTIONS >/dev/null || exit 1
>> +    modprobe "$RT_DRIVER" "$RT_DRIVER_OPTIONS" >/dev/null || exit 1
>>
>>       for dev in $REBIND_RT_NICS; do
>> -    if [ -d /sys/bus/pci/devices/$dev/driver ]; then
>> -        echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
>> +    if [ -d /sys/bus/pci/devices/"$dev"/driver ]; then
>> +        echo "$dev" > /sys/bus/pci/devices/"$dev"/driver/unbind
>>       fi
>> -    echo $dev > /sys/bus/pci/drivers/$RT_DRIVER/bind
>> +    echo "$dev" > /sys/bus/pci/drivers/"$RT_DRIVER"/bind
>>       done
>>
>>       for PROTOCOL in $RT_PROTOCOLS; do
>> -    modprobe rt$PROTOCOL >/dev/null || exit 1
>> +    modprobe rt"$PROTOCOL" >/dev/null || exit 1
>>       done
>>
>> -    if [ $RT_LOOPBACK = "yes" ]; then
>> +    if [ "$RT_LOOPBACK" = "yes" ]; then
>>       modprobe rt_loopback >/dev/null || exit 1
>>       fi
>>
>> -    if [ $RTCAP = "yes" ]; then
>> +    if [ "$RTCAP" = "yes" ]; then
>>       modprobe rtcap >/dev/null || exit 1
>>       fi
>>
>> -    if [ $RT_LOOPBACK = "yes" ]; then
>> +    if [ "$RT_LOOPBACK" = "yes" ]; then
>>       $RTIFCONFIG rtlo up 127.0.0.1
>>       fi
>>
>> -    if [ $RTCAP = "yes" ]; then
>> +    if [ "$RTCAP" = "yes" ]; then
>>       ifconfig rteth0 up
>>       ifconfig rteth0-mac up
>> -    if [ $RT_LOOPBACK = "yes" ]; then
>> +    if [ "$RT_LOOPBACK" = "yes" ]; then
>>           ifconfig rtlo up
>>       fi
>>       fi
>> @@ -74,9 +74,9 @@ init_rtnet() {
>>   submit_cfg() {
>>       case "$STATION_TYPE" in
>>       master)
>> -        $RTIFCONFIG rteth0 up $STATION_IP
>> +        $RTIFCONFIG rteth0 up "$STATION_IP"
>>
>> -        $TDMACFG rteth0 master $TDMA_CYCLE
>> +        $TDMACFG rteth0 master "$TDMA_CYCLE"
>>           eval "$TDMA_SLOTS"
>>
>>           IPADDR=$STATION_IP
>> @@ -96,7 +96,7 @@ submit_cfg() {
>>           ADD_STAGE1_CMDS="ifconfig vnic0 up $STATION_IP"
>>
>>           echo "$TDMA_SLOTS$ADD_STAGE1_CMDS" | \
>> -        $RTCFG rteth0 add $RTCFG_CLIENT -stage1 -
>> +        $RTCFG rteth0 add "$RTCFG_CLIENT" -stage1 -
>>           ;;
>>       backup-master)
>>           if [ ! "$STATION_IP" = "" ]; then
>> @@ -117,7 +117,7 @@ submit_cfg() {
>>           fi
>>
>>           echo "\$TDMACFG rteth0 detach;\$TDMACFG rteth0 master
>> $TDMA_CYCLE -b $TDMA_BACKUP_OFFS;$TDMA_SLOTS$ADD_STAGE1_CMDS" | \
>> -        $RTCFG rteth0 add $RTCFG_CLIENT -stage1 - $STAGE_2_OPT
>> +        $RTCFG rteth0 add "$RTCFG_CLIENT" -stage1 - "$STAGE_2_OPT"
>>           ;;
>>       esac
>>
>> @@ -142,16 +142,16 @@ start_master() {
>>       #   Sync / Master Slot / + TDMA_OFFSET us / Slave 1 /
>>       #   + TDMA_OFFSET us / Slave 2 / + TDMA_OFFSET us / ... / Slave n
>>
>> -    $RTIFCONFIG rteth0 up $IPADDR $NETMASK_OPT
>> +    $RTIFCONFIG rteth0 up "$IPADDR" $NETMASK_OPT
>>
>> -    $TDMACFG rteth0 master $TDMA_CYCLE
>> +    $TDMACFG rteth0 master "$TDMA_CYCLE"
>>       $TDMACFG rteth0 slot 0 0
>>
>>       OFFSET=$TDMA_OFFSET
>>       for SLAVE in $TDMA_SLAVES; do
>>           echo "\$TDMACFG rteth0 slot 0 $OFFSET;ifconfig vnic0 up
>> \$IPADDR \$NETMASK_OPT" | \
>> -        $RTCFG rteth0 add $SLAVE -stage1 - $STAGE_2_OPT
>> -        OFFSET=$(($OFFSET+$TDMA_OFFSET))
>> +        $RTCFG rteth0 add "$SLAVE" -stage1 - "$STAGE_2_OPT"
>> +        OFFSET=$((OFFSET+TDMA_OFFSET))
>>       done
>>       else
>>       # Get setup from TDMA_CONFIG file:
>> @@ -185,12 +185,12 @@ start_master() {
>>       # slot ...
>>       #
>>
>> -    if [ ! -r $TDMA_CONFIG ]; then
>> +    if [ ! -r "$TDMA_CONFIG" ]; then
>>           echo "Could not read $TDMA_CONFIG"
>>           exit 1
>>       fi
>>
>> -    while read ARG1 ARG2 ARG3 ARG4 ARG5 ARG6; do
>> +    while read -r ARG1 ARG2 ARG3 ARG4 ARG5 ARG6; do
>>           case "$ARG1" in
>>           "master:")
>>               submit_cfg
>> @@ -217,7 +217,7 @@ start_master() {
>>               STATION_MAC="$ARG2"
>>               ;;
>>           "stage2")
>> -            STATION_STAGE_2="$ARG2"
>> +            STATION_STAGE_2_SRC="$ARG2"
>>               ;;
>>           "slot")
>>               TDMA_SLOTS="$TDMA_SLOTS\$TDMACFG rteth0 slot $ARG2 $ARG3"
>> @@ -233,13 +233,13 @@ start_master() {
>>               TDMA_SLOTS="$TDMA_SLOTS;"
>>               ;;
>>           esac
>> -    done < $TDMA_CONFIG
>> +    done < "$TDMA_CONFIG"
>>       submit_cfg
>>       fi
>>
>> -    ifconfig vnic0 up $IPADDR $NETMASK_OPT
>> +    ifconfig vnic0 up "$IPADDR" $NETMASK_OPT
>>
>> -    echo -n "Waiting for all slaves..."
>> +    echo "Waiting for all slaves..."
>>       $RTCFG rteth0 wait
>>       $RTCFG rteth0 ready
>>       echo
> 
> Ah, this one is another function (or more cosmetic) change: "-n" means
> "no line-break", and therefore that empty "echo" at the end. You should
> make both the observer and shellcheck happy by using
> 
> printf "Line without break"
> 
> instead. Same pattern also below.

Yes, you are right. I followed too strictly the shellcheck warnings :-)

Thanks.

> 
>> @@ -251,8 +251,8 @@ if [ "$1" = "-cf" ]; then
>>       shift 2
>>   fi
>>
>> -if [ -r $RTNETCFG ]; then
>> -    . $RTNETCFG
>> +if [ -r "$RTNETCFG" ]; then
>> +    . "$RTNETCFG"
>>   else
>>       echo "Could not read $RTNETCFG"
>>       exit 1
>> @@ -281,20 +281,20 @@ case "$1" in
>>       start)
>>       init_rtnet
>>
>> -    if [ $TDMA_MODE = "master" ]; then
>> +    if [ "$TDMA_MODE" = "master" ]; then
>>           start_master
>>       else
>>           $TDMACFG rteth0 slave
>>
>> -        $RTIFCONFIG rteth0 up $IPADDR $NETMASK_OPT
>> +        $RTIFCONFIG rteth0 up "$IPADDR" "$NETMASK_OPT"
>>
>> -        echo -n "Stage 1: searching for master..."
>> -        eval "`$RTCFG rteth0 client -c`"
>> +        echo "Stage 1: searching for master..."
>> +        eval "$($RTCFG rteth0 client -c)"
>>           echo
>>
>> -        echo -n "Stage 2: waiting for other slaves..."
>> +        echo "Stage 2: waiting for other slaves..."
>>           if [ ! "$STAGE_2_DST" = "" ]; then
>> -        $RTCFG rteth0 announce -f $STAGE_2_DST
>> +        $RTCFG rteth0 announce -f "$STAGE_2_DST"
>>           echo
>>           eval "$STAGE_2_CMDS"
>>           else
>> @@ -302,7 +302,7 @@ case "$1" in
>>           echo
>>           fi
>>
>> -        echo -n "Stage 3: waiting for common setup completion..."
>> +        echo "Stage 3: waiting for common setup completion..."
>>           $RTCFG rteth0 ready
>>           echo
>>       fi
>> @@ -317,10 +317,10 @@ case "$1" in
>>       $RTIFCONFIG rteth0 down 2>/dev/null
>>       $RTIFCONFIG rtlo down 2>/dev/null
>>
>> -    rmmod tdma rtmac rtcfg rtcap rt_loopback $RT_DRIVER rtpacket rtudp
>> rttcp rtipv4 rtnet 2>/dev/null
>> +    rmmod tdma rtmac rtcfg rtcap rt_loopback "$RT_DRIVER" rtpacket
>> rtudp rttcp rtipv4 rtnet 2>/dev/null
>>
>>       for dev in $REBIND_RT_NICS; do
>> -        echo 1 > /sys/bus/pci/devices/$dev/remove
>> +        echo 1 > /sys/bus/pci/devices/"$dev"/remove
>>       done
>>       if [ ! "$REBIND_RT_NICS" = "" ]; then
>>           sleep 1
>> @@ -337,7 +337,7 @@ case "$1" in
>>
>>       capture)
>>       modprobe rtnet >/dev/null || exit 1
>> -    modprobe $RT_DRIVER $RT_DRIVER_OPTIONS >/dev/null || exit 1
>> +    modprobe "$RT_DRIVER" "$RT_DRIVER_OPTIONS" >/dev/null || exit 1
>>       modprobe rtcap >/dev/null || exit 1
>>       $RTIFCONFIG rteth0 up promisc
>>       ifconfig rteth0 up
>> @@ -349,7 +349,7 @@ case "$1" in
>>       modprobe rtipv4 >/dev/null || exit 1
>>
>>       for PROTOCOL in $RT_PROTOCOLS; do
>> -        modprobe rt$PROTOCOL >/dev/null || exit 1
>> +        modprobe rt"$PROTOCOL" >/dev/null || exit 1
>>       done
>>
>>       modprobe rt_loopback >/dev/null || exit 1
> 
> With that and if you also tested the result, we should be fine then.
> 
> Jan
> 

I'm testing it, I will send the final patch when tests are done.

Thanks

-- 
Mauro S.


  reply	other threads:[~2022-05-05 15:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03  8:22 [PATCH] utils/net/rtnet.in: fixes after shellcheck inspection Mauro S.
2022-05-05 13:03 ` Jan Kiszka
2022-05-05 15:12   ` [PATCH v2] " Mauro S.
2022-05-05 15:25     ` Jan Kiszka
2022-05-05 15:39       ` Mauro S. [this message]
2022-05-12  7:00         ` [PATCH v3] " Mauro S.
2022-06-23  6:37           ` Mauro S.
2022-06-23  7:46             ` Jan Kiszka
2022-06-23  8:05               ` Mauro S.
2022-06-23  8:37                 ` Jan Kiszka
2022-06-23  8:48                   ` Mauro S.
2022-06-23  8:59                     ` Jan Kiszka
2022-06-23  9:16                       ` Mauro S.
2022-06-23  9:35                         ` Jan Kiszka
2022-06-23 10:16                           ` Mauro S.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9a4b75d-81bb-28ea-4bee-293f19637c05@tin.it \
    --to=mau.salvi@tin.it \
    --cc=jan.kiszka@siemens.com \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.