[PATCH 3/5] base/workers: Fix detection of check basename for special workers

Andreas Ericsson ae at op5.se
Mon Nov 5 23:56:55 CET 2012


On 11/05/2012 02:58 PM, robin.sonefors at op5.com wrote:
> From: Robin Sonefors <robin.sonefors at op5.com>
> 
> strrchr may search from the end of the string, but it still expects the
> pointer it is provided to point to the beginning of the string. Thus, we'd
> only check if the last byte was a slash, rather than for the last slash.
> 
> Manipulating the cmd_name for basename discovery is unnecessary, so
> don't.
> 
> Signed-off-by: Robin Sonefors <robin.sonefors at op5.com>
> ---
>   base/workers.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/base/workers.c b/base/workers.c
> index 0f33a8a..7042724 100644
> --- a/base/workers.c
> +++ b/base/workers.c
> @@ -807,14 +807,12 @@ static worker_process *get_worker(worker_job *job)
>   	cmd_name = job->command;
>   	if ((space = strchr(cmd_name, ' ')) != NULL) {
>   		*space = '\0';
> -		slash = strrchr(space - 1, '/');
> +		slash = strrchr(cmd_name, '/');

Actually, nvm about the comment thing. *space = '\0' means strrchr()
works. I was thinking memrchr() was needed, but it isn't. Nice work.

-- 
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.

------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d




More information about the Developers mailing list