Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 442028

Summary: sys-apps/openrc: fix checkbashisms errors where possible
Product: Gentoo Linux Reporter: Michael Palimaka (kensington) <kensington>
Component: Current packagesAssignee: OpenRC Team <openrc>
Status: CONFIRMED ---    
Severity: normal CC: alexander, pesa
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
URL: http://thread.gmane.org/gmane.linux.debian.devel.devscripts/8483
Whiteboard:
Package list:
Runtime testing required: ---

Description Michael Palimaka (kensington) gentoo-dev 2012-11-06 11:42:29 UTC
robbat2 said on #-dev to file a bug about this.

 * QA Notice: shell script appears to use non-POSIX feature(s):
 *    possible bashism in /etc/init.d/bootmisc line 30 ([^] should be [!]):
 *              if ! rm -rf -- [^ajlq\.]* 2>/dev/null ; then

 *    possible bashism in /etc/init.d/bootmisc line 137 (type):
 *                              if type fuser >/dev/null 2>&1; then

 * QA Notice: shell script appears to use non-POSIX feature(s):
 *    possible bashism in /etc/init.d/hostname line 13 ($HOST(TYPE|NAME)):
 *      hostname=${hostname-${HOSTNAME-localhost}}

 * QA Notice: shell script appears to use non-POSIX feature(s):
 *    possible bashism in /etc/init.d/local line 22 (type):
 *      if type local_start >/dev/null 2>&1; then

 *    possible bashism in /etc/init.d/local line 42 (type):
 *      if type local_start >/dev/null 2>&1; then
Comment 1 William Hubbs gentoo-dev 2012-11-06 14:38:16 UTC
(In reply to comment #0)
>  * QA Notice: shell script appears to use non-POSIX feature(s):
>  *    possible bashism in /etc/init.d/bootmisc line 30 ([^] should be [!]):
>  *              if ! rm -rf -- [^ajlq\.]* 2>/dev/null ; then

It looks like checkbashisms is seeing the wildcard expression as the condision here?

>  *    possible bashism in /etc/init.d/bootmisc line 137 (type):
>  *                              if type fuser >/dev/null 2>&1; then

What's wrong with this? I thought type was posix?

>  * QA Notice: shell script appears to use non-POSIX feature(s):
>  *    possible bashism in /etc/init.d/hostname line 13 ($HOST(TYPE|NAME)):
>  *      hostname=${hostname-${HOSTNAME-localhost}}

This also seems to work? I tried something similar from the command line in dash?

>  * QA Notice: shell script appears to use non-POSIX feature(s):
>  *    possible bashism in /etc/init.d/local line 22 (type):
>  *      if type local_start >/dev/null 2>&1; then
> 
>  *    possible bashism in /etc/init.d/local line 42 (type):
>  *      if type local_start >/dev/null 2>&1; then

These are more complaints about type?
Comment 2 Sean McGovern 2012-11-06 14:43:06 UTC
(In reply to comment #1)
> (In reply to comment #0)
> >  * QA Notice: shell script appears to use non-POSIX feature(s):
> >  *    possible bashism in /etc/init.d/bootmisc line 30 ([^] should be [!]):
> >  *              if ! rm -rf -- [^ajlq\.]* 2>/dev/null ; then
> 
> It looks like checkbashisms is seeing the wildcard expression as the
> condision here?
> 
> >  *    possible bashism in /etc/init.d/bootmisc line 137 (type):
> >  *                              if type fuser >/dev/null 2>&1; then
> 
> What's wrong with this? I thought type was posix?
> 

It is -- see http://pubs.opengroup.org/onlinepubs/009695399/utilities/type.html
Comment 3 William Hubbs gentoo-dev 2012-11-06 14:51:55 UTC
@robbat2:
It appears that these are false positives. If you disagree, please
re-assign this to OpenRC and we can go from there.

Thanks,

William
Comment 4 Michael Palimaka (kensington) gentoo-dev 2012-11-06 14:56:41 UTC
I have posted to devscripts-devel@debian asking what they think about this issue.
Comment 5 Michael Palimaka (kensington) gentoo-dev 2012-11-06 17:08:20 UTC
Apparently 'type' is an XSI extension, rather than pure POSIX.

An example of a shell that does not support this is app-shells/posh.
Comment 6 Davide Pesavento gentoo-dev 2012-11-07 04:14:48 UTC
(In reply to comment #5)
> Apparently 'type' is an XSI extension, rather than pure POSIX.
> 
> An example of a shell that does not support this is app-shells/posh.

Maybe you could use 'command -v' rather than 'type'? Although it's not exactly the same thing...
Comment 7 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2012-11-07 05:29:09 UTC
I have fixed many bashisms.

The following are left:
1. "type" function usage. This is an POSIX XSI extension. I'm not convinced we should remove it.

2. I have marked 2 false positives where we use bashisms with fallbacks.

3. checkbashisms gets quote & heredoc handling wrong in some complex cases, leading to either parse errors:
error: init.d/net.lo.in: Unterminated quoted string found, EOF reached. Wanted: <">
error: net/ip6rd.sh:  Unterminated heredoc found, EOF reached. Wanted: <24>
error: net/iwconfig.sh.Linux.in: Unterminated quoted string found, EOF reached. Wanted: <'>
error: net/pppd.sh: Unterminated quoted string found, EOF reached. Wanted: <">

or severe false positives:
possible bashism in net/iwconfig.sh.Linux.in line 81 ([^] should be [!]):
	LC_ALL=C iwconfig "${IFACE}" | \
	sed -n -e 's/^'"$1"' *\([^ ]* [^ ]*\).*/\1/p'
Do NOT change that ^ to !, they are in the sed expression, not a pathname pattern.

4.
These are two more actual bashisms we should consider carefully:
possible bashism in sh/functions.sh.in line 65 (alias):
	alias -g '${1+"$@"}'='"$@"'
possible bashism in sh/runscript.sh.in line 205 (ulimit):
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}

alias does not take options in POSIX, and ulimit is for file size only.
Comment 8 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2012-11-07 05:29:55 UTC
$ checkbashisms $(find init.d*/* net/* sh/* scripts/* ! -name Makefile) 2>&1 |fgrep -f exclude -v

Where 'exclude'
is a file containing:
====
interpreter line
does not appear to be
(type)
if type 
&& type 
====
Comment 9 William Hubbs gentoo-dev 2012-11-07 16:22:21 UTC
@robbat2: I am moving this back to openrc since you are on the alias.
Comment 10 SpanKY gentoo-dev 2012-12-24 21:23:23 UTC
(In reply to comment #5)

"command" is not an alternative to "type" when it comes to functions

the `alias -g` isn't an issue.  if you read the code, it's only executed for zsh.