Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 442028 - sys-apps/openrc: fix checkbashisms errors where possible
Summary: sys-apps/openrc: fix checkbashisms errors where possible
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: OpenRC Team
URL: http://thread.gmane.org/gmane.linux.d...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-06 11:42 UTC by Michael Palimaka (kensington)
Modified: 2024-08-23 14:44 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 (RETIRED) 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.
Comment 11 kfm 2024-08-23 14:37:53 UTC
(In reply to SpanKY from comment #10)
> (In reply to comment #5)
> 
> "command" is not an alternative to "type" when it comes to functions

This is not the case. The meaningful differences between type and command -v for resolving functions are as follows.

Firstly, type was (and still is) an XSI extension.

Secondly, command -v used to require support for the User Portability Utilities option but this constraint was lifted in Issue 7.

Thirdly, the output of type is unspecified. Not that bootmisc was doing so, but it should never be parsed in portable code.

Anyway, I see that bootmisc no longer uses type. As there hasn't been any further discussion for some 12 years, I think that this bug should be closed.
Comment 12 kfm 2024-08-23 14:44:17 UTC
Closing, per my previous comment. I briefly checked bootmisc for POSIX violations and found that only the use of "local" counts as one at this point.