ps output redirection problem

Ignacio García Pérez iggarpe at terra.es
Thu Mar 29 09:04:51 UTC 2007


Denis Vlasenko escribió:
> On Wednesday 28 March 2007 23:05, Bernhard Fischer wrote:
>   
>> On Wed, Mar 28, 2007 at 03:25:29PM +0200, Ignacio García Pérez wrote:
>>     
>>> Made some more tests...
>>>
>>> I installed bash and tried ps with the same baffling results, which 
>>> means the problem is not in the busybox shell I'm using (ash).
>>>
>>> Again, any clues welcome...
>>>       
>
> libc bug in printf("%.*s\n", MAX_INT, buffer);
>
> Wroked around by replacing MAX_INT by 30000 here:
>
>         terminal_width = 30000;
>         if (isatty(1)) {
>                 get_terminal_width_height(1, &terminal_width, NULL);
>                 terminal_width--;
>         }
>   

Thanks for the hint, though I already found out. IMHO my fix is better. 
See my attached patch. Basically, I save the buffer width when it is 
first calculated and truncate it by inserting a null if the terminal 
width is smaller. It costs a static int and a couple of "if" (which 
probably save quite a lot of cycles into the printf code BTW).

Sure, 30000 should be ok, but also should MAX_INT, so let's not rely on 
a "sufficiently large" value.

Best regards.







More information about the busybox mailing list