gearmand ignores the "listen" command-line option

Bug #1127347 reported by Kevin Bowman
40
This bug affects 6 people
Affects Status Importance Assigned to Milestone
Gearman
Fix Released
Critical
Brian Aker

Bug Description

Regardless of whether "--listen" or "-L" is used, I found that gearmand is always binding to 0.0.0.0 (instead of the "127.0.0.1" which I was trying to set it to). After fiddling with the code, I think it's related to this around line 97 in libgearman-server/struct/gearmand.h :

    if (host)
    {
      host= strdup(host_);
    }

Removing the "if" test (and always forcing it to run "host= strdup(host_);") makes the listen argument work again. I'm not familiar enough with C++ to know why the if test is there, but it seems to be causing the host property to get lost. Later in the code, if there is no host set, it defaults to "<any>" which then turns into a bind to INADDR_ANY.

Revision history for this message
Brandon Checketts (la0nchpad) wrote :

Tried with all variations of -L and --listen with and without equals sign.

root@host:/usr/local# /usr/local/sbin/gearmand --version
gearmand 1.0.3 - https://bugs.launchpad.net/gearmand

root@host:/usr/local# /usr/local/sbin/gearmand --verbose INFO --listen=10.0.0.3 -p 4477
   INFO 2013-02-20 18:49:29.086606 [ main ] Initializing Gear
   INFO 2013-02-20 18:49:29.000000 [ main ] Starting up(5013), verbose set to INFO
   INFO 2013-02-20 18:49:29.000000 [ main ] Listening on 0.0.0.0:4477 (8)
   INFO 2013-02-20 18:49:29.000000 [ main ] Listening on :::4477 (9)
   INFO 2013-02-20 18:49:29.000000 [ main ] Adding event for listening socket (8)
   INFO 2013-02-20 18:49:29.000000 [ main ] Adding event for listening socket (9)

Revision history for this message
Kevin Bowman (magicmonkey) wrote :

I've tried it on versions 1.1.5 and 1.0.3 and the problem exists on both versions:

kevin@host:~/gearman/gearmand-1.0.3$ ./gearmand/gearmand -L localhost --verbose DEBUG
./gearmand/gearmand: Could not open log file "/usr/local/var/log/gearmand.log", from "/home/kevin/gearman/gearmand-1.0.3", switching to stderr. (No such file or directory)
   INFO 2013-02-20 22:48:25.451913 [ main ] Initializing Gear
   INFO 2013-02-20 22:48:25.452062 [ main ] Starting up(5168), verbose set to DEBUG
  DEBUG 2013-02-20 22:48:25.452082 [ main ] staring up Epoch thread -> libgearman-server/timer.cc:61
  DEBUG 2013-02-20 22:48:25.452176 [ main ] Method for libevent: epoll -> libgearman-server/gearmand.cc:331
  DEBUG 2013-02-20 22:48:25.452471 [ main ] Trying to listen on 0.0.0.0:4730 -> libgearman-server/gearmand.cc:571

Note the "Trying to listen on 0.0.0.0:4730" instead of "Trying to listen on 127.0.0.1:4730"

Revision history for this message
Brian Aker (brianaker) wrote :

One is bind to any, and the other is bind to just localhost.

Revision history for this message
Kevin Bowman (magicmonkey) wrote :

Sure - my point was that passing "-L localhost" should have made it bind to 127.0.0.1, but instead it bound to 0.0.0.0.

Revision history for this message
Keyur (keyurdg) wrote :

Here's the patch to fix this:

diff --git a/gearmand-1.0.3/libgearman-server/struct/gearmand.h b/gearmand-1.0.3/libgearman-server/struct/gearmand.h
index b50ed9a..fde93ab 100644
--- a/gearmand-1.0.3/libgearman-server/struct/gearmand.h
+++ b/gearmand-1.0.3/libgearman-server/struct/gearmand.h
@@ -93,7 +93,7 @@ struct gearmand_st
     thread_add_next(NULL),
     free_dcon_list(NULL)
   {
- if (host)
+ if (host_)
     {
       host= strdup(host_);
     }

Revision history for this message
Kevin Bowman (magicmonkey) wrote :

Simplest patch ever :) Yes, that appears to work, and although I tracked it down to that code I'm slightly embarrassed I didn't spot that that was the problem...

Thanks!

Revision history for this message
Keyur (keyurdg) wrote :

Took me a couple passes at that block too :-)

Revision history for this message
Brian Aker (brianaker) wrote :

Thank you.

BTW this is why I started to use the convention of using a prefixed _ to represent a private variable, and a _ to represent an argument that is being passed to a method.

This is obviously no reflected through out this codebase.

Changed in gearmand:
importance: Undecided → Critical
Brian Aker (brianaker)
Changed in gearmand:
status: New → In Progress
assignee: nobody → Brian Aker (brianaker)
milestone: none → 1.0.4
Brian Aker (brianaker)
Changed in gearmand:
status: In Progress → Fix Released
Revision history for this message
hxdhan (hxdhan) wrote :

my gearmand version is 1.0.6,

but this issue is still exists . how to handle this.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.