Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 579062 - sys-apps/gentoo-functions: fails with `set -u` due to unset CONSOLETYPE
Summary: sys-apps/gentoo-functions: fails with `set -u` due to unset CONSOLETYPE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
Depends on:
Reported: 2016-04-05 01:13 UTC by Stuart Shelton
Modified: 2016-04-12 23:14 UTC (History)
0 users

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

Attachments patch to add shellcheck compliance (gentoo-functions-0.10-shellcheck.patch,4.82 KB, patch)
2016-04-12 23:14 UTC, Stuart Shelton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stuart Shelton 2016-04-05 01:13:55 UTC from sys-apps/gentoo-functions-0.10 causes scripts which source it to fail under 'set -u' (fail on use of unbound variables) due to CONSOLETYPE (line 423) being used undefined.

However, I also notice that starts with:

# All functions in this file should be written in POSIX sh. Please do
# not use bashisms.

... but then proceeds to use 'local' (sometimes with multiple arguments) and 'test -nt', both of which are valid in bash but are undefined in POSIX sh.


Instead targeting dash or bb ash may give the desired flexibility without needing nasty workarounds to attain strict POSIX compliance...
Comment 1 Mike Gilbert gentoo-dev 2016-04-05 13:14:57 UTC
In the future, please file separate bugs for separate issues.
Comment 2 SpanKY gentoo-dev 2016-04-12 08:21:33 UTC
Gentoo has long accepted `local` as usable even in "POSIX" shell code as all relevant shells have long supported it.  this isn't specific to gentoo-functions.
Comment 3 Stuart Shelton 2016-04-12 10:06:23 UTC
Sure, that part may well be a documentation issue... perhaps a link to a wiki page or similar documenting the features beyond what is supported by pure POSIX sh which are considered to be standard/supported for Gentoo?

(I guess we're going for anything supported by ash/dash, to provide the option for a reduced shell for use by init/openrc?  I've read reports of Debian booting noticeably faster when they moved from bash to dash as /bin/sh for system scripts.)
Comment 4 SpanKY gentoo-dev 2016-04-12 16:22:08 UTC
(In reply to Stuart Shelton from comment #3)

"whatever ash/dash supports" is not our bar.  it's "whatever is in POSIX and `local`".  when we weighed the benefits of `local` vs finding a relevant shell that *didn't* support it (which we couldn't), it was pretty easy to just say "`local` is allowed".  it's been discussed on the gentoo-dev list but i don't know it's been spelled out in the wiki.
Comment 5 Stuart Shelton 2016-04-12 23:14:45 UTC
Created attachment 430268 [details, diff] patch to add shellcheck compliance

Okay, cool - how about then:

# All functions in this file should be written in POSIX sh, with the
# addition of "local" to set variable scope. Please do not use other
# bashisms.

(plus the change of "${CONSOLETYPE}" to "${CONSOLETYPE:-}" on line 423)?

In case anyone's interested I've attached a patch which passes shellcheck validation, FWIW.