[Toybox] [patch] add grep

Rob Landley rob at landley.net
Thu Jul 25 23:56:56 PDT 2013


On 07/19/2013 11:50:18 PM, Isaac wrote:
> I didn't dare to poke at that, but noticed the exit (c).
> This would break toysh and anything else that may xexec() grep, so I  
> started

Actually it's just NOFORK commands that would be broken; toysh would  
fork() and xexec() and then the child should exit() which xexit() will  
do in the normal case.

The point of nofork commands is they can run in the same process  
context which can speed up shell scripts, but each one has to be  
audited to not leak memory or filehandles or change the umask or signal  
handlers or any other persistent state change that would screw up the  
parent process. Most commands probably won't ever be NOFORK commands.

But calling any xfunction() out of lib/xwrap.c means it'd exit if it  
hit an error, and we don't want toysh exiting, hence the longjmp. At  
some point I may work out some cleanup mechanism where it'll  
automaticlly free allocations (via a linked list or something), close  
filehandles, and so on. But I haven't done so yet and I'm not sure it's  
worthwhile...

(Really xexit() just lets us call an error handler instead of exiting.  
We can set the jmp_buf before doing something that might fail, and  
handle the failure ourselves. The most important callers of xexit() are  
error_exit() and perror_exit().)

> I noticed one oddity in your style: is there any reason to use
> function (args); //normal is function(args) ?
> The latter style makes a regex search for functions simpler.

I do a space after things that _aren't_ functions, like if (walrus).

Technically sizeof(blah) isn't a function either but it acts like one,  
and in fact the parentheses are optional since it's an operator: int x  
= sizeof int; // valid statement

Rob
 1374821816.0


More information about the Toybox mailing list