Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 506704 - sys-apps/gentoo-functions-0.3 errors out when evaluating $COLUMNS
Summary: sys-apps/gentoo-functions-0.3 errors out when evaluating $COLUMNS
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: William Hubbs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-03 21:36 UTC by Thomas Deutschmann (RETIRED)
Modified: 2014-07-06 20:00 UTC (History)
4 users (show)

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


Attachments
Patch proposal (functions.sh_bug506704.patch,623 bytes, patch)
2014-05-09 04:38 UTC, Thomas Deutschmann (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Deutschmann (RETIRED) gentoo-dev 2014-04-03 21:36:07 UTC
Hi,

while running a remote command through app-admin/salt

  salt 'gentoo-box' cmd.run 'revdep-rebuild -ip'

I got the following error from the remote Gentoo system:

    /lib/gentoo/functions.sh: line 444: [: : integer expression expected
     * Configuring search environment for revdep-rebuild

     * Checking reverse dependencies
     * Packages containing binaries and libraries broken by a package update
     * will be emerged.

     * Collecting system binaries and libraries
     * Generated new 1_files.rr
     * Collecting complete LD_LIBRARY_PATH
     * Generated new 2_ldpath.rr
     * Checking dynamic linking consistency

     * Dynamic linking on your system is consistent... All done.

When running the same command directly on the gentoo-box through a normal SSH session, everything works.

After some debugging I noticed that "COLUMNS" isn't set when running through salt. This is causing the problem. E.g. 

  salt 'gentoo-box' cmd.run 'export COLUMNS=120 && revdep-rebuild -ip'

will make the error go away, because now "COLUMNS" is set.

So I think there is something wrong in functions.sh...

Reproducible: Always




 # emerge --info
Portage 2.2.10 (default/linux/amd64/13.0, gcc-4.8.2, glibc-2.19, 3.10.35-gentoo x86_64)
=================================================================
System uname: Linux-3.10.35-gentoo-x86_64-Intel-R-_Xeon-R-_CPU_E31270_@_3.40GHz-with-gentoo-2.2
KiB Mem:    32914920 total,  32168720 free
KiB Swap:   16777212 total,  16777212 free
Timestamp of tree: Thu, 03 Apr 2014 18:45:01 +0000
ld GNU ld (GNU Binutils) 2.24
app-shells/bash:          4.2_p46-r1
dev-lang/python:          2.7.6, 3.3.5, 3.4.0
dev-util/pkgconfig:       0.28-r1
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.12.4
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.69
sys-devel/automake:       1.14.1
sys-devel/binutils:       2.24-r2
sys-devel/gcc:            4.8.2
sys-devel/gcc-config:     1.8
sys-devel/libtool:        2.4.2
sys-devel/make:           4.0-r1
sys-kernel/linux-headers: 3.10 (virtual/os-headers)
sys-libs/glibc:           2.19

sys-apps/gentoo-functions-0.3
Comment 1 Alex Xu (Hello71) 2014-04-03 21:58:50 UTC
${VAR:-VAL} is a bashism. Consider making a function default() { if [ -n "$1" ]; then echo "$1"; else echo "$2"; fi }.
Comment 2 Thomas Deutschmann (RETIRED) gentoo-dev 2014-04-03 22:45:34 UTC
Additional information: I added added 'set -x/set +x' around line 444:

    ++ COLS=0
    ++ '[' 0 -eq 0 ']'
    ++++ stty size
    +++ set --
    +++ printf '\n'
    ++ COLS=
    ++ '[' '' -gt 0 ']'
    /lib/gentoo/functions.sh: line 445: [: : integer expression expected
    ++ COLS=80

Running "stty size" through salt will give me the following error:

stty: standard input: Inappropriate ioctl for device

...that's why line 444 will fail I guess.
Comment 3 SpanKY gentoo-dev 2014-04-07 01:00:25 UTC
${VAR:-val} is not a bashism.  please read the spec before speculating.
Comment 4 Benedikt Böhm 2014-05-01 19:26:19 UTC
having the same problem here when running repoman in jenkins (stty size fails)
Comment 5 Thomas Deutschmann (RETIRED) gentoo-dev 2014-05-08 11:19:30 UTC
FYI: The bug is still present in sys-apps/gentoo-functions-0.4.

But because in sys-apps/gentoo-functions-0.4 the file

  /lib/gentoo/functions.sh

was renamed to

  /lib/gentoo/gentoo-functions.sh

scripts like revdep-rebuild are no longer using the new gentoo-functions script so you don't see the error at the moment (until they catch up and will use the new name).
Comment 6 William Hubbs gentoo-dev 2014-05-08 16:17:53 UTC
Please test with 0.4 and report back to the bug whether or not your
issue is resolved.

Thanks,

William
Comment 7 Thomas Deutschmann (RETIRED) gentoo-dev 2014-05-08 17:17:10 UTC
(In reply to William Hubbs from comment #6)
> Please test with 0.4 and report back to the bug whether or not your
> issue is resolved.

Please see comment #5, again:

Currently you cannot reproduce the problem with sys-apps/gentoo-functions-0.4, because "revdep-rebuild" from app-portage/gentoolkit-0.3.0.9-r1 will fallback to "/etc/init.d/functions.sh" because "/lib/gentoo/functions.sh" was renamed to "/lib/gentoo/gentoo-functions.sh" in sys-apps/gentoo-functions-0.4. See "/usr/bin/revdep-rebuild" from app-portage/gentoolkit-0.3.0.9-r1:

  [...]
  if [ -e /lib/gentoo/functions.sh ]; then
      . /lib/gentoo/functions.sh
      elif [ -e /etc/init.d/functions.sh ]; then
          . /etc/init.d/functions.sh
      else
          echo "Unable to find functions.sh"
          exit 1
      fi
  fi


But when you patch "/usr/bin/revdep-rebuild" to source the new "/lib/gentoo/gentoo-functions.sh" the error will be back.

So this is *not* fixed.

...I am little bit pissed at the moment (sorry to tell you), that you even asked to verify if this was fixed in v0.4 because the faulty code which causes the problems wasn't touched in v0.4 (and it looks like you didn't read my comment #5...).
Comment 8 William Hubbs gentoo-dev 2014-05-08 22:20:33 UTC
I'll take care of the rename; that was something that should not have happened. and No, I just now read comment #5. I guess it was posted before I used pybugz to post mine.
Comment 9 William Hubbs gentoo-dev 2014-05-08 22:38:49 UTC
(In reply to William Hubbs from comment #8)
> I'll take care of the rename; that was something that should not have
> happened. and No, I just now read comment #5. I guess it was posted before I
> used pybugz to post mine.

Also, in the future, please refrain from piggy-backing unrelated issues into open bugs.

Comment #5 should have been filed as a separate bug since it was about the rename and not the original issue of this bug.


Thanks,

William
Comment 10 William Hubbs gentoo-dev 2014-05-08 23:16:18 UTC
(In reply to Alex Xu (Hello71) from comment #1)
> ${VAR:-VAL} is a bashism. Consider making a function default() { if [ -n
> "$1" ]; then echo "$1"; else echo "$2"; fi }.

You were 1/2 correct. We were using a bashism, but this wasn't it. The problem was the $COLUMNS variable itself. This is a magic variable in bash.

This was fixed in commit febbce1, and will be in 0.5.
Comment 11 William Hubbs gentoo-dev 2014-05-09 00:08:48 UTC
Thomas,

gentoo-functions-0.5 should take care of the issue. The problem was the
reference to the $COLUMNS variable, which is a bashism. This has been
removed, and COLS defaults to 80 if it doesn't get set by the
"stty size" command.

Please verify that this works.

Thanks,

William
Comment 12 Mike Gilbert gentoo-dev 2014-05-09 02:57:12 UTC
William: libeinfo looked for COLUMNS in the environment and used that before querying the tty for its size. This would allow you to override the value reported by the tty.

So no, it is not just a magic bash variable.
Comment 13 Mike Gilbert gentoo-dev 2014-05-09 03:09:01 UTC
Also, the reference to the COLUMNS variable was not problematic at all. The problem was that the stty size command was outputting an empty string, but the code did not check for that.

I think the COLUMNS check should be restored here if you want to mimic the behavior of libeinfo.
Comment 14 Thomas Deutschmann (RETIRED) gentoo-dev 2014-05-09 04:38:58 UTC
Created attachment 376600 [details, diff]
Patch proposal

The attached patch will fix the issue for me without changing the existing behavior.

Patch was created against sys-apps/gentoo-functions-0.5.
Comment 15 Anthony Basile gentoo-dev 2014-06-14 12:32:47 UTC
(In reply to Thomas D. from comment #14)
> Created attachment 376600 [details, diff] [details, diff]
> Patch proposal
> 
> The attached patch will fix the issue for me without changing the existing
> behavior.
> 
> Patch was created against sys-apps/gentoo-functions-0.5.

I'm temporarily taking care of gentoo-functions (while Williams is out).  I did push gentoo-functions-0.6 to address a missing header issue (breaking some stage builds), but did not push this out --- I'm proceeding cautiously.

Having said that, I dont' see a problem committing this: 1) it shouldn't change the existing behavior in current working cases (ie where COLUMNS is set) and 2) it fixes your problem.

I'll wait about a week for testing and either William will be back, or, if there are no problems, I'll push it out.
Comment 16 William Hubbs gentoo-dev 2014-07-06 20:00:12 UTC
This is in commit 52fbd4c and will be part of gentoo-functions-0.7.