LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Boot script query ( /etc/rc.d/rc.S/M/0) (https://www.linuxquestions.org/questions/slackware-14/boot-script-query-etc-rc-d-rc-s-m-0-a-883080/)

Keith Hedger 05-27-2011 02:35 PM

Boot script query ( /etc/rc.d/rc.S/M/0)
 
Got a query on some odd scripting in the boot up/ shutdown scripts, these scripts in turn call other scripts in /etc/rc.d but do so in an odd way and I want to know why this is, if you look in /etc/rc.d/rc.M the way the scripts are called is different
hal is called by
Code:

sh /etc/rc.d/rc.hald start
acpid is called by
Code:

. /etc/rc.d/rc.acpid start
cups is called by
Code:

/etc/rc.d/rc.cups start
The . in the acpid call tells the interpreter to include the file rather than run as a separate script, and there are other examples, from line 56 of /etc/rc.d/rc.0
Code:

# Run any local shutdown scripts:
if [ -x /etc/rc.d/rc.local_shutdown ]; then
  /etc/rc.d/rc.local_shutdown stop
fi

# Stop the Apache web server:
if [ -x /etc/rc.d/rc.httpd ]; then
  /etc/rc.d/rc.httpd stop
fi

# Stop the MySQL database:
if [ -r /var/run/mysql/mysql.pid ]; then
  . /etc/rc.d/rc.mysqld stop
fi

# Stop the Samba server:
if [ -x /etc/rc.d/rc.samba ]; then
  . /etc/rc.d/rc.samba stop
fi

# Shut down the NFS server:
if [ -x /etc/rc.d/rc.nfsd ]; then
  /etc/rc.d/rc.nfsd stop
fi

Is there any reason for these different ways of calling the scripts?

Alien Bob 05-27-2011 04:32 PM

Including other rc scripts through the use of the "source" command (which is the dot command's actual name) saves creating a sub-shell. Forking a subshell adds a little bit of overhead to your boot time.

However, if the script which gets sourced contains an "exit" statement it becomes a different story. Look at the rc.hald script which checks for the existence of dbus and aborts with "exit 1" if dbus is not found.
Now, if rc.hald would have been sourced it would be effectively part of rc.M. The "exit 1" statement would then abort rc.M as well, the result would be a broken system because most of rc.M would not be executed. Therefore, rc.hald is started in a subshell so that in case of that error exit, rc.M can just continue with the other bits and pieces.

Eric

Keith Hedger 05-28-2011 05:05 AM

Thanks! didn't think to check for an exit statement in the scripts, but it still seems odd to mix the two different ways of running the rc scripts just to save a small bit of boot time.


All times are GMT -5. The time now is 08:04 AM.