FS#14059 - initscripts: /etc/rc.d/functions exit with 1 status

Attached to Project: Arch Linux
Opened by Sebastien Vasey (svasey) - Wednesday, 01 April 2009, 19:28 GMT
Last edited by Aaron Griffin (phrakture) - Thursday, 02 April 2009, 16:51 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Aaron Griffin (phrakture)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

In any rc script, If I do something like

#!/bin/bash

set -o errexit # This is what causes trouble

source /etc/rc.d/rc.conf
source /etc/rc.d/functions

And then try to execute the result, the /etc/rc.d/functions script exits with 1 status due to an error happening in its code.

Of course, everything works fine if errexit is not set.

I don't know if we are supposed to use bash for rc scripts, but it seems to me no error should be left unchecked.

I use initscripts-2009.03-2


Steps to reproduce:

$ bash
$ source /etc/rc.d/functions
$ echo $?
This task depends upon

Closed by  Aaron Griffin (phrakture)
Thursday, 02 April 2009, 16:51 GMT
Reason for closing:  Fixed
Additional comments about closing:  Fixed in git
Comment by Aaron Griffin (phrakture) - Wednesday, 01 April 2009, 20:39 GMT
Would it be possible to track down what is failing?
Comment by Sebastien Vasey (svasey) - Thursday, 02 April 2009, 07:17 GMT
Yes.

The problem is my /etc/rc.d/functions.d is empty (I don't know what it is for). At the end of /etc/rc.d/functions , there are the following lines

#Source additional functions at the end to allow overrides
for f in /etc/rc.d/functions.d/*; do
[ -e $f ] && . $f
done

Since /etc/rc.d/functions.d/* does not match anything, it is used literally so the test [-e /etc/rc.d/functions.d/* ] is made and fails, making the script directly exit if bash's errexit is on.

A simple fix would be

#Source additional functions at the end to allow overrides
for f in $(ls /etc/rc.d/functions.d/); do
[ -e $f ] && . $f
done
Comment by Sebastien Vasey (svasey) - Thursday, 02 April 2009, 07:31 GMT
A better fix would be


#Source additional functions at the end to allow overrides
for f in /etc/rc.d/functions.d/*; do
if [ -e "$f" ]; then . $f ; fi
done
Comment by Aaron Griffin (phrakture) - Thursday, 02 April 2009, 16:03 GMT
@Sebastien: Does the simple addition of 'if' prevent this from being an error?
Comment by Aaron Griffin (phrakture) - Thursday, 02 April 2009, 16:08 GMT Comment by Sebastien Vasey (svasey) - Thursday, 02 April 2009, 16:42 GMT
Yes. No more exit on error after this fix.

Loading...