Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 629226 - postgres.eclass: calls 'sort -nr' in global scope
Summary: postgres.eclass: calls 'sort -nr' in global scope
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal critical (vote)
Assignee: PgSQL Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 629222
  Show dependency tree
 
Reported: 2017-08-28 18:12 UTC by Michał Górny
Modified: 2017-09-05 17:19 UTC (History)
0 users

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


Attachments
postgres.eclass Bash sort patch (postgres-eclass-bash-sort.patch,1.15 KB, patch)
2017-08-30 11:39 UTC, Aaron W. Swenson
Details | Diff
postgres.eclass Simple sort patch (postgres-eclass-simple-sort.patch,2.50 KB, patch)
2017-09-03 14:22 UTC, Aaron W. Swenson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2017-08-28 18:12:39 UTC
postgres.eclass:	readarray -t POSTGRES_COMPAT < <(printf '%s\n' "${POSTGRES_COMPAT[@]}" | sort -nr)

Calling external commands during metadata regen is forbidden by PMS, and breaks new secure cache regen, e.g.:

 * ERROR: dev-db/pgpool2-3.6.4 failed (depend phase):
 *   External commands disallowed during metadata regen: sort -nr
 * 
 * Call stack:
 *          isolated-functions.lib, line 345:  Called source '/home/mgorny/tmp/gentoo/dev-db/pgpool2/pgpool2-3.6.4.ebuild'
 *            pgpool2-3.6.4.ebuild, line   8:  Called inherit 'postgres-multi'
 *    ebuild-default-functions.lib, line 209:  Called __internal_inherit 'postgres-multi'
 *               ebuild-daemon.lib, line  29:  Called __qa_invoke 'source' '/home/mgorny/tmp/gentoo/eclass/postgres-multi.eclass'
 *          isolated-functions.lib, line 345:  Called source '/home/mgorny/tmp/gentoo/eclass/postgres-multi.eclass'
 *           postgres-multi.eclass, line   4:  Called inherit 'multibuild' 'postgres'
 *    ebuild-default-functions.lib, line 209:  Called __internal_inherit 'postgres'
 *               ebuild-daemon.lib, line  29:  Called __qa_invoke 'source' '/home/mgorny/tmp/gentoo/eclass/postgres.eclass'
 *          isolated-functions.lib, line 345:  Called source '/home/mgorny/tmp/gentoo/eclass/postgres.eclass'
 *                 postgres.eclass, line  54:  Called command_not_found_handle 'sort' '-nr'
 *              ebuild-daemon.bash, line 383:  Called die
Comment 1 Aaron W. Swenson gentoo-dev 2017-08-30 11:39:59 UTC
Created attachment 491104 [details, diff]
postgres.eclass Bash sort patch

Would something like the attached be okay?
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2017-08-30 11:58:39 UTC
If it works, I suppose it's fine for now. However, I'm not sure we want to keep version_sort long-term. Wouldn't it be better to just hardcode the order in the eclass? i.e. do something like:

  _POSTGRES_ALL_VERSIONS=( ... )

and then:

  for x in "${_POSTGRES_ALL_VERSIONS[@]}"; do
    if has "${x}" "${POSTGRES_COMPAT[@]}"; then
      ...
    fi
  done

Having the list also makes it easier to validate for invalid POSTGRES_COMPAT or disable the old versions via eclass. See how python*-r1 handle that.

As a side note, editing user-specified variables is a bad idea. You have no guarantee that Portage won't source the ebuild again, resetting your altered POSTGRES_COMPAT.
Comment 3 Aaron W. Swenson gentoo-dev 2017-09-03 14:22:51 UTC
Created attachment 492138 [details, diff]
postgres.eclass Simple sort patch

I'm not particularly fond of hard coding, but how about this.
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2017-09-03 15:09:26 UTC
I don't see why it wouldn't work, so feel free to commit.
Comment 5 Aaron W. Swenson gentoo-dev 2017-09-05 17:19:41 UTC
commit 2345402051e4b0c12cbc7b3a16fd20decbd0d4b3
Author: Aaron W. Swenson <titanofold@gentoo.org>
Date:   Tue Sep 5 12:59:44 2017 -0400

    postgres{,-multi}.eclass: Improvements and bug fix

    Improve documentation comments to eliminate warnings and make the
    resulting man pages look better.

    Use a simple sort instead of the external sort program because calling
    external commands during metadata regen is forbidden by PMS and breaks
    new secure cache regen.

    Gentoo-Bug: 629226

commit 9e0ba9394f263cb8201c48d4a52157b00fe5a795 (HEAD -> master, origin/master, origin/HEAD)
Author: Aaron W. Swenson <titanofold@gentoo.org>
Date:   Tue Sep 5 13:15:18 2017 -0400

    app-portage/eclass-manpages: Snapshot bump 20170905

    New snapshot bump (20170905) including the most recent change in
    postres{,-multi}.eclass doc changes.

    Package-Manager: Portage-2.3.6, Repoman-2.3.1