printf without any argument exits ash

Michael Abbott michael at araneidae.co.uk
Tue Dec 16 09:55:32 UTC 2008


I meant to send this last week.

On Wed, 10 Dec 2008, Denys Vlasenko wrote:
> > But, when I run "printf" without any argument, it simply kills the shell
> http://busybox.net/downloads/fixes-1.13.1/busybox-1.13.1-printf.patch

A couple of thoughts:

1. This patch needs to be added to the 1.12 patches (it applies cleanly to 
1.12.3 without any modification).  Except...

2. Eww.

Clearly the problem is that bb_show_usage() exits after showing applet 
specific usage, but when it's called as a built-in from a shell this isn't 
the right behaviour.  

I see, for example, that rm.c also claims to be a NOFORK applet (shouldn't 
printf.c say so as well?), but it happily manages to call bb_show_usage() 
without killing the shell.  Or is it lying about not being forked...?

Sorry, I should be answering my own questions by inspecting the code -- 
but I don't know my way around well enough.  For example, where is the 
FORK/NOFORK status determined?

A quick dig is interesting.  If I take rm.c at face value, there's an 
interesting discrepancy.  `rm` definitely shows usage without exiting 
the shell, and clearly does so by calling bb_show_usage(), which 
clearly exits by calling xfunc_die() ... which is where things get 
interesting.  I'm not too sure about the context, but it looks to me as if 
we *should* be exiting by a longjmp (which is what I was expecting).

Thus this begs the question: why didn't printf take the longjmp?  Surely 
the patch should address that underlying problem rather than the nasty 
local hack which we actually see!



More information about the busybox mailing list