FS#20620 - [initscripts] rc.sysinit double grep

Attached to Project: Arch Linux
Opened by Linas (Linas) - Thursday, 26 August 2010, 12:39 GMT
Last edited by Andrea Scarpino (BaSh) - Wednesday, 16 March 2011, 15:10 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Thomas Bächler (brain0)
Architecture All
Severity Very Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
/etc/rc.sysinit (initscripts package) in line 157-158 contains

# Set up non-root encrypted partition mappings
if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then

Instead of calling grep twice over a pipe, it can be moved into a single grep, without having to use non-standard options.
if [ -f /etc/crypttab -a -n "$(/bin/grep ^[^#] /etc/crypttab)" ]; then

Additionally, not extracting the output for just checking if something was matched should be faster.
if [ -f /etc/crypttab ] && /bin/grep -q ^[^#] /etc/crypttab; then

(this could also be applied to the mdadm.conf grep of line 139)
This task depends upon

Closed by  Andrea Scarpino (BaSh)
Wednesday, 16 March 2011, 15:10 GMT
Reason for closing:  Fixed
Comment by Glenn Matthys (RedShift) - Monday, 15 November 2010, 14:07 GMT
Status: not implemented in initscripts-2010.07-1.
Comment by Matthias Dienstbier (fs4000) - Monday, 07 February 2011, 22:08 GMT
This grep was previously also done in rc.shutdown. It was removed in the bashification and later readded only in rc.sysinit.
So at the moment there is still the old double grep in rc.sysinit and no grep at all in rc.shutdown. Please use the new grep command in both scripts.
There is always the message "Deactivating encrypted volumes:" at shutdown although I don't have any.
Comment by Dave Reisner (falconindy) - Saturday, 19 February 2011, 14:28 GMT
Still not quite a perfect solution. Looking at rc.sysinit in testing, I find this one to be simpler and more effective:

-if [[ -f /etc/crypttab && $CS && -n $(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$) ]]; then
+if [[ $CS ]] && grep -vq '^[[:space:]]*$\|^[[:space:]]*#' /etc/crypttab 2>/dev/null; then

attached in patch form against git master.
Comment by Sébastien Luttringer (seblu) - Friday, 04 March 2011, 00:20 GMT

Loading...