Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 70158 - famd does not search for a service entry in /etc/services
Summary: famd does not search for a service entry in /etc/services
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo Linux bug wranglers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-05 05:54 UTC by Chad Christopher Giffin
Modified: 2004-11-05 06:02 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
patches Lisenter.c++ to check for a service entry (fam-2.7.0-servent.patch,978 bytes, patch)
2004-11-05 05:57 UTC, Chad Christopher Giffin
Details | Diff
ebuild for revision 3 (fam-2.7.0-r3.ebuild,2.03 KB, text/plain)
2004-11-05 06:01 UTC, Chad Christopher Giffin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chad Christopher Giffin 2004-11-05 05:54:31 UTC
When famd starts, it gets assigned a random reserved port by calling bindservport().  Due to it getting a random service port, any lookups with netstat show a numbered port OR a mislabled port for famd.



Reproducible: Always
Steps to Reproduce:
1. Start famd
2. run netstat -ta
3. run lsof -i
4. compare the port used by famd with that show in netstat output

Actual Results:  
I usualy see a numeric number for the port.
Sometimes the port assigned is allocated in the services db, and if that port is
allocated, fam shows up using another services port.

Expected Results:  
famd should search for a service entry in /etc/services using getservbyname.
It should bind to a port matching the entry (if any)

here is a patch file for famd source:
--- fam-2.7.0-r2/src/Listener.c++       2003-01-19 17:37:29.000000000 -0700
+++ fam-2.7.0-r3/src/Listener.c++       2004-11-05 06:25:25.059037488 -0700
@@ -35,6 +35,7 @@
 #include <sys/stat.h>
 #include <sys/un.h>
 #include <unistd.h>
+#include <netdb.h>
 
 #include <errno.h>
 
@@ -68,6 +69,7 @@
   _ugly_sock(-1),
   local_only(lo)
 {
+    struct servent *se;
     if (started_by_inetd)
     {
        //  Portmapper already knows about
@@ -91,8 +93,13 @@
        memset(&addr, 0, sizeof addr);
        addr.sin_family = AF_INET;
         addr.sin_addr.s_addr = local_only ? htonl(INADDR_LOOPBACK) : 0;
-       addr.sin_port = htons(0);
-       if (bindresvport(sock, &addr) < 0)
+       se = getservbyname("fam","tcp");
+       if(se) {
+           addr.sin_port = se->s_port;
+       } else {
+           addr.sin_port = htons(0);
+       }
+       if (bind(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr)) < 0)
        {
            Log::perror("can't bind to reserved port");
            exit(1);
Comment 1 Chad Christopher Giffin 2004-11-05 05:57:19 UTC
Created attachment 43335 [details, diff]
patches Lisenter.c++ to check for a service entry

patches cleaning to 2.7.0-r2 source
Comment 2 Chad Christopher Giffin 2004-11-05 05:59:23 UTC
Comment on attachment 43335 [details, diff]
patches Lisenter.c++ to check for a service entry

patches cleanly to fam-2.7.0-r2
Comment 3 Chad Christopher Giffin 2004-11-05 06:01:48 UTC
Created attachment 43336 [details]
ebuild for revision 3

new ebuild file for revision 3 of famd
Comment 4 Chad Christopher Giffin 2004-11-05 06:02:40 UTC
this supplied patch and ebuild fixes everything