Bug 793536

Summary: ps axfl output not being folded when piped
Product: [openSUSE] openSUSE 12.2 Reporter: Per Jessen <per>
Component: BasesystemAssignee: Dr. Werner Fink <werner>
Status: VERIFIED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: jengelh
Version: Final   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: screenshot from openSUSE 11.0 system
screenshot from openSUSE 12.2 system

Description Per Jessen 2012-12-08 08:19:24 UTC
User-Agent:       Mozilla/5.0 (X11; Linux i686 on x86_64; rv:11.0) Gecko/20100101 Firefox/11.0

If I do "ps axfl" and some of the output is wider than my terminal window, the lines are truncated. This is normal. 

If I do "ps axfl | grep some", on an 11.0 system, the output is folded (as with "ps axflww"), and I get to see the entire line.

On openSUSE 12.2 the output after "ps axfl | grep some" is still truncated. It is as if ps doesn't recognize that the output is being piped? 
I'm not sure, but I think this behaviour could be very bad for scripts that rely on the earlier behaviour. 

Reproducible: Always
Comment 1 Jiaying Ren 2012-12-10 05:22:01 UTC
(In reply to comment #0)
> User-Agent:       Mozilla/5.0 (X11; Linux i686 on x86_64; rv:11.0)
> Gecko/20100101 Firefox/11.0
> 
> If I do "ps axfl" and some of the output is wider than my terminal window, the
> lines are truncated. This is normal. 
> 
> If I do "ps axfl | grep some", on an 11.0 system, the output is folded (as with
> "ps axflww"), and I get to see the entire line.
> 
> On openSUSE 12.2 the output after "ps axfl | grep some" is still truncated. It
> is as if ps doesn't recognize that the output is being piped? 
> I'm not sure, but I think this behaviour could be very bad for scripts that
> rely on the earlier behaviour. 
> 
> Reproducible: Always

Hi~Per,which shell did you used for testing it?Would you please tell me its version?
Comment 2 Per Jessen 2012-12-10 07:21:03 UTC
On 12.2, I'm using bash, bash-4.2-51.6.1.i586.  On 11.0, it is also bash, bash-3.2-112.1.
Comment 3 Dr. Werner Fink 2012-12-13 08:07:54 UTC
I'm not able to reproduce with 12.2:

  /suse/werner> stty size
  42 81
  /suse/werner> ps axfl | wc -L
  173

that is that the longest line of the ps command is 173 but the XTerm has only 81 columns. Do you have some environment variables set that are accordingly to the manual page of ps:

  COLUMNS

and do have installed all available updates for OS 12.2?   Just do a

  grep -rs /etc/profile.d/

to see where the variable COLUMNS is set.
Comment 4 Per Jessen 2012-12-13 08:48:29 UTC
(In reply to comment #3)
> I'm not able to reproduce with 12.2:
> 
>   /suse/werner> stty size
>   42 81
>   /suse/werner> ps axfl | wc -L
>   173
> 
> that is that the longest line of the ps command is 173 but the XTerm has only
> 81 columns. Do you have some environment variables set that are accordingly to
> the manual page of ps:
> 
>   COLUMNS
> 
> and do have installed all available updates for OS 12.2?   Just do a
> 
>   grep -rs /etc/profile.d/
> 
> to see where the variable COLUMNS is set.

Hi Werner

                 12.2               11.0
------------------------------------------------
stty size        55 236             55 236
ps axf | wc -L   236                344

echo $COLUMNS    236                236

COLUMNS isn't set anywhere in /etc/profile.d/  (on either system).

The line that isn't being folded when piped through grep is 293 long:

dupont5:~ # ps axfww | grep spamd | wc -L
293

I've just now updated again - this is the list of updates:
coreutils findutils glibc glibc-devel glibc-extra glibc-locale iproute2 iptables libiptc0 libopenssl-devel libopenssl1_0_0 libxtables7 openssl sysconfig systemd systemd-sysvinit xen-libs xen-tools-domU

After reboot - no change in behaviour wrt this issue. 

FYI, I'm accessing both systems via ssh from a Konsole window. I don't know if that makes a difference.
Comment 5 Per Jessen 2012-12-13 08:53:28 UTC
Created attachment 516854 [details]
screenshot from openSUSE 11.0 system
Comment 6 Per Jessen 2012-12-13 08:54:06 UTC
Created attachment 516855 [details]
screenshot from openSUSE 12.2 system
Comment 7 Dr. Werner Fink 2012-12-17 13:05:09 UTC
As workaround I suggesst

       unset COLUMNS
       trap '' SIGWINCH

as the bash set automatically the environment variable COLUMNS for the signal WINCH.
Comment 8 Dr. Werner Fink 2013-01-08 16:58:43 UTC
Please run

 printenv | grep COLUMNS

somehow this variable is exported by accident.  Please not this is not the line

        export LINES COLUMNS TERM

in /etc/profile as this is only active on /dev/console of /dev/tty1 on an iSeries.  Therefore this variable is exported at an other place below /etc/ or /usr/share/bash-completion or maybe in your personal setup for the bash like in ~/.profile or ~/.bashrc
Comment 9 Dr. Werner Fink 2013-01-08 17:45:56 UTC
Found this

  werner/bash> grep COLUMNS -rs bash-4.2 readline-6.2 | grep setenv
  bash-4.2/lib/readline/shell.c:  setenv ("COLUMNS", b, 1);
  readline-6.2/shell.c:  setenv ("COLUMNS", b, 1);
Comment 10 Dr. Werner Fink 2013-01-08 17:51:10 UTC
Submit request #147584 together with submit request #147585 should fix this.
Found that enforcing the bash shell option checkwinsize will cause that the variables COLUMNS and LINES become exported variables instead of internal ones.

In SR #47584 I've removed enforcing  checkwinsize and in SR #147585 I've added


        # If COLUMNS are within the environment the shell should update
        # the winsize after each job otherwise the values are wrong
        case "$(declare -p COLUMNS 2> /dev/null)" in
        *-x*COLUMNS=*) shopt -s checkwinsize
        esac

in /etc/bash.bashrc for interacrtive shells as this helps to avoid wrong COLUMNS and LINES if during a forground job in the bash the terminal has changed its columns and/or lines.
Comment 11 Bernhard Wiedemann 2013-01-08 18:00:17 UTC
This is an autogenerated message for OBS integration:
This bug (793536) was mentioned in
https://build.opensuse.org/request/show/147584 Factory / bash
https://build.opensuse.org/request/show/147585 Factory / aaa_base
Comment 12 Bernhard Wiedemann 2013-01-09 12:00:09 UTC
This is an autogenerated message for OBS integration:
This bug (793536) was mentioned in
https://build.opensuse.org/request/show/147710 Factory / bash
Comment 13 Per Jessen 2013-03-10 10:49:21 UTC
Werner, are you waiting for input from me?
Comment 14 Dr. Werner Fink 2013-03-11 07:50:37 UTC
You may test out the submit requests. Both together should fix the issue.
Comment 15 Per Jessen 2013-03-11 08:13:33 UTC
(In reply to comment #14)
> You may test out the submit requests. Both together should fix the issue.

I've tested this in 12.3rc2, and it looks fine.  What about an update for 12.2?
Comment 16 Dr. Werner Fink 2013-04-23 16:38:19 UTC
No update for 12.2
Comment 17 Swamp Workflow Management 2013-07-29 13:06:04 UTC
openSUSE-RU-2013:1271-1: An update that has 7 recommended fixes can now be installed.

Category: recommended (low)
Bug References: 382214,763591,793536,804551,806628,820149,828877
CVE References: 
Sources used:
openSUSE 12.2 (src):    bash-4.2-51.13.1