Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 592470 - sys-apps/gentoo-functions: consoletype failure aborts scripts with set -e
Summary: sys-apps/gentoo-functions: consoletype failure aborts scripts with set -e
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: William Hubbs
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2016-08-30 20:43 UTC by James Le Cuirot
Modified: 2023-02-06 04:07 UTC (History)
3 users (show)

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


Attachments
Prevent consoletype failure from aborting scripts with set -e (0001-Prevent-consoletype-failure-from-aborting-scripts-wi.patch,791 bytes, patch)
2016-08-30 20:43 UTC, James Le Cuirot
Details | Diff
Use absolute path to consoletype as /sbin is not in user PATH (0002-Use-absolute-path-to-consoletype-as-sbin-is-not-in-u.patch,798 bytes, patch)
2016-08-30 20:46 UTC, James Le Cuirot
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Le Cuirot gentoo-dev 2016-08-30 20:43:19 UTC
Created attachment 444480 [details, diff]
Prevent consoletype failure from aborting scripts with set -e

The call to consoletype usually fails when run as non-root as /sbin isn't in the user PATH. The PATH issue could be fixed but any failure breaks scripts that have set -e. Prepending the call with ! counteracts this. See the first patch.
Comment 1 James Le Cuirot gentoo-dev 2016-08-30 20:46:50 UTC
Created attachment 444482 [details, diff]
Use absolute path to consoletype as /sbin is not in user PATH

This second patch calls consoletype with an absolute PATH. This doesn't take account of EPREFIX. I don't know whether you'd prefer to call hprefixify in the ebuild or have the Makefile take care of it with sed or something.
Comment 2 Mike Gilbert gentoo-dev 2016-08-30 20:51:54 UTC
(In reply to James Le Cuirot from comment #1)

Another option would be to move consoletype to /bin; I see no reason to have it in sbin.
Comment 3 James Le Cuirot gentoo-dev 2016-08-30 20:55:38 UTC
(In reply to Mike Gilbert from comment #2)
> Another option would be to move consoletype to /bin; I see no reason to have
> it in sbin.

That did cross my mind as well. Up to you.
Comment 4 Mike Gilbert gentoo-dev 2016-08-30 21:49:04 UTC
(In reply to James Le Cuirot from comment #0)

I think this patch breaks set -e when consoletype happens to be in PATH. The exclamation mark just toggles the exit status between 0 and non-zero.
Comment 5 James Le Cuirot gentoo-dev 2016-08-30 21:56:42 UTC
(In reply to Mike Gilbert from comment #4)
> 
> I think this patch breaks set -e when consoletype happens to be in PATH. The
> exclamation mark just toggles the exit status between 0 and non-zero.

Check man set, it causes the exit status to be ignored. I was going to do "|| true" but wondered if there is another way and turns out there is. I tested it in bash and dash.
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-02-06 04:07:27 UTC
Resolved by:

commit 1c801ce130726a81c59b96cdf4e2bef27893e0b7
Author: Kerin Millar <kfm@plushkava.net>
Date:   Thu Jul 28 01:57:17 2022 +0100

    functions.sh: fix TTY detection

    The use of stdout as an argument in consoletype seems to be based
    on a misunderstanding. It doesn't do anything except guarantee
    the exit status is 0. The value is thrown away anyway.

    This fixes e.g. elibtoolize (from elt-patches) having no colour
    for its e.g. ewarn/einfo/etc because when invoked from an ebuild,
    it's detected as serial.

    Use a simpler test instead. We may want to clean up the logic
    in consoletype in future too (just drop lines 82-85?).

    Signed-off-by: Kerin Millar <kfm@plushkava.net>
    Signed-off-by: Sam James <sam@gentoo.org>