LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Bedrock Linux (https://www.linuxquestions.org/questions/bedrock-linux-118/)
-   -   Minor question about the code of the init script (https://www.linuxquestions.org/questions/bedrock-linux-118/minor-question-about-the-code-of-the-init-script-4175662968/)

ychaouche 10-22-2019 11:58 AM

Minor question about the code of the init script
 
In reading bedrock init's code, I found references to echo and cut, apparently to extract part of a string.

Code:

# Around line 364
complete_upgrade

init_timeout="$(cfg_values "init" "timeout")"
def_tuple="$(cfg_values "init" "default")"
def_stratum="$(deref "$(echo "${def_tuple}" | cut -d: -f1)")"
def_cmd="$(echo "${def_tuple}" | cut -d: -f2-)"
def_path=""

def_tuple should be of the form

Code:

void:/sbin/init
As described in the shipped /etc/bedrock.conf file

Code:

#
# Init to utilize by default if timeout expires.  Format is
#
#    default = <stratum>:<path>
#
# For example, to use void's /sbin/init, use:
#
#    default = void:/sbin/init
#
default =

If that's the case, then I propose to replace echo and cut with bash's % and # string operators, like so :

Code:

# Around line 364
complete_upgrade

init_timeout="$(cfg_values "init" "timeout")"
def_tuple="$(cfg_values "init" "default")"
def_stratum="$(deref ${def_tuple%:*}"
def_cmd="$(deref ${def_tuple#*:}"
def_path=""

Code:

ychaouche#ychaouche-PC 15:47:32 ~/MUSIQUE/CONTENT/BRASIL $ def_tuple=void:/sbin/init
ychaouche#ychaouche-PC 17:48:01 ~/MUSIQUE/CONTENT/BRASIL $ echo ${def_tuple%:*}
void
ychaouche#ychaouche-PC 17:48:06 ~/MUSIQUE/CONTENT/BRASIL $ echo ${def_tuple#*:}
/sbin/init
ychaouche#ychaouche-PC 17:48:11 ~/MUSIQUE/CONTENT/BRASIL $


Comments ?

ParadigmComplex 10-22-2019 04:06 PM

This isn't running in bash, but the busybox sh we are using does provide that as well. That should work.

However, I don't want to make changes to working code that don't have discernible improvements, as all it does is introduce unnecessary risk without meaningful benefit. There's work towards a proper test suite infrastructure. Once that's in place with adequate tests to confirm such changes won't break something we can revisit the possibility.


All times are GMT -5. The time now is 07:57 PM.