fedora-sysv / initscripts

📜 Scripts to bring up network interfaces and legacy utilities in Fedora.
GNU General Public License v2.0
45 stars 52 forks source link

Make the init.d/network and init.d/functions available on Busybox's shell #397

Closed mengtanhzc closed 2 years ago

mengtanhzc commented 2 years ago

396

In some embedded environments, instead of using GNU Bash for size reasons, the Ash (shell provided by busybox) is used. But init.d/network and init.d/functions are not very well adapted for Ash. Here are the two problems I found:

1) Use killproc to kill the given service process Steps:

    #!/bin/bash
    . /etc/init.d/functions

    test()
    {
        sleep 30 &
        killproc sleep
    }
    test

run this testcase returns an error, and sleep is not killed:

./test_killproc.sh: line 126: remainning+=2039 : not found

This is because Ash cannot use "+=" for string concatenation.

2) I found out that here string(<<<) and c-style for-loop( for (( ; ; )) ) are used in network-scripts. But Ash doesn't support them either. So when I run: "/etc/rc.d/init.d/network status" gives these errors:

    # /etc/rc.d/init.d/network: ./network-functions: line 166: syntax error: unexpected redirection
    # /etc/rc.d/init.d/network: ./network-functions: line 575: syntax error: bad for loop variable

The last two patches are used to fix this problem.

The problems mentioned above can all be verified simply on busybox v1.32.1. For example:

   $ /bin/busybox bash -c "str+=$char"
   bash: str+=: not found

   $ /bin/busybox bash -c "grep hello <<< "hello world""
   world: line 1: syntax error: unexpected redirection

   $ /bin/busybox bash -c "for (( idx=0; idx<5; idx++ )); do date; done"
   bash: syntax error: bad for loop variable

Thanks in advance.