Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#15713 - [initscripts] printf causes scripts to fail when argument starts with a dash

Attached to Project: Arch Linux
Opened by Jacob (Jacob_) - Wednesday, 29 July 2009, 01:37 GMT
Last edited by Aaron Griffin (phrakture) - Thursday, 30 July 2009, 03:56 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Aaron Griffin (phrakture)
Thomas Bächler (brain0)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

In /etc/rc.d/functions, printf fails when called with an argument starting with a dash, causing the script using the function to crash.

I found this when calling /etc/rc.d/net-auto from pm-suspend sleep.d, it happens when netcfg-auto-wireless calls stat_append(). As there is no attached terminal, $C_MAIN is not set, therfore printf is called with $1 as the first arg which is "- No networks available." in this case.

/etc/rc.d/functions:

stat_append() {
printf "${RESTORE_POSITION}"
printf "${C_MAIN}${1}${C_CLEAR}"
printf "${SAVE_POSITION}"
}

/usr/bin/netcfg-auto-wireless:

if [[ ! "$networks" ]]; then
stat_append "- No networks available."
stat_fail
exit 1
fi

This cases the following error:

/etc/rc.d/functions: line 99: printf: - : invalid option
printf: usage: printf [-v var] format [arguments]
[FAIL]


Possible solution for functions:

call printf with -- before the argument.

Workaround - put the following in functions.d:

stat_append() {
printf "${RESTORE_POSITION}"
printf -- "${C_MAIN}${1}${C_CLEAR}"
printf "${SAVE_POSITION}"
}


I raised this here as other scripts may run into the same issue, this may also affect other functions.


Name : initscripts
Version : 2009.03-2

Name : netcfg
Version : 2.2.1-1

Name : bash
Version : 4.0.024-1

x86_64

Steps to reproduce:

I've modified the the standard 11netcfg pm-utils script copied from /usr/lib/pm-utils/sleep.d/11netcfg:

resume_netcfg() {
netcfg2 all-resume &> /dev/null
if [ ! -e /var/run/interfaces/wlan0 ]; then
echo "No wireless"
/etc/rc.d/net-auto restart &> /tmp/wireless
else
echo "Wireless network already up"
fi
}

Turn of the radio so the network connect with fail (rfkill), then resume from sleep.
This task depends upon

Closed by  Aaron Griffin (phrakture)
Thursday, 30 July 2009, 03:56 GMT
Reason for closing:  Implemented
Additional comments about closing:  In git
Comment by Aaron Griffin (phrakture) - Wednesday, 29 July 2009, 03:34 GMT
The -- change sounds good to me. Either Thomas or I will apply it when we can :)
Comment by Thomas Bächler (brain0) - Wednesday, 29 July 2009, 07:32 GMT
This shouldn't only be stat_append, but all of the functions.
Comment by Aaron Griffin (phrakture) - Wednesday, 29 July 2009, 21:13 GMT
You think all cases of printf should use --? Only stat_append uses $1 in the text, the rest use constants...
Comment by Aaron Griffin (phrakture) - Wednesday, 29 July 2009, 21:18 GMT
I pushed the change with only stat_append changed this way. If you think all printfs should have this, let me know and I can do it (or you can)
Comment by Thomas Bächler (brain0) - Wednesday, 29 July 2009, 23:16 GMT
Ah, right. In that case it's fine.

Loading...