Double escaping in $ARGx$

Andreas Ericsson ae at op5.se
Tue Aug 11 19:07:23 CEST 2009


Ton Voon wrote:
> On 11 Aug 2009, at 10:40, Andreas Ericsson wrote:
> 
>> I mean that we can get rid of roughly 35-40% of the load from Nagios  
>> by
>> avoiding the extra fork()+execve() the shell causes by simply parsing
>> the command ourselves.
> 
> I see. perl does something like that. You call system() with a string  
> (like "/bin/echo here I am") and it works out if there are any shell  
> meta characters in there. If so, it invokes via the shell, otherwise  
> it splits it based on spaces and then calls execve().
> 
> So the usual definitions of "$USER1$/check_icmp -H hostname" will  
> speed up, but something like "$USER1$/check_http -H hostname -s  
> 'string'" won't.
> 

Well, parsing the single and double-quoted shell arguments is really
really trivial. runcmd already does that. It's when you need to
create pipes that it gets tricky.

> We could do something like that as well, though there's potential  
> breakage with existing configurations.
> 

There shouldn't be any breakages really. The runcmd code is fairly
well tested in that respect.

> I've never dug into perl's C code - this would be a handy excuse!
> 

I can't think why.

int has_shell_meta_chars(const char *str)
{
	const char *p;
	for (p = str; p; p++) {
		switch (*p) {
		case '\'': etc...
			return 1;
		}
	}

	return 0;
}


-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july




More information about the Developers mailing list