/etc/defaults/services and /etc/services

Matthew Dillon dillon at apollo.backplane.com
Thu Feb 10 16:23:35 PST 2005

:although there's an ongoing discussion about the general way of
:updating system files, which will probably render my work useless,
:here's the patch to have a not-to-be-edited /etc/defaults/services and
:an optional /etc/services.
:getservent() now first tries to find a matching protocol name/port
:number in /etc/defaults/services, and, if no match was found, reads
:lines form /etc/services (if it exists).
:I also updated the getservent.5 man page to reflect these changes, but
:there's carloads more in the repository. I did not make changes to
:these files, since I'd first like to know if this
:/etc/defaults/services stuff will be integrated or not. Once I get a
:positive feedback, I'll update all the other man pages, etc.
:The patch lives here:

    Well, regardless of the cvs issue, I think there is a need to
    separate /etc/services so I definitely want to go with an
    adjustment to libc to support /etc/defaults/services.

    Your patch looks like a good first attempt.  Here are some comments:

    * I see why you created a _PATH_ETC_SERVICES but I think in this case
      it makes sense not to add that #define and to simple use the original
      _PATH_SERVICES.  To keep things similarly named change

    * Do not hardwire loops that index into the array.  Instead do something
      like this define and then use it in your loops.  In particular,
      the if (servf_count == 1) in getservent() is an example of unintentional
      disconnectedness between the size of the array and the termination
      check, using (SERVF_ARY_SIZE - 1) makes the check a lot clearer.

      #define SERVF_ARY_SIZE	(sizeof(servf)/sizeof(servf[0]))

    * getservent() needs to deal with duplicates and overrides.

    I wonder what we should do about getservent() ...  To be entirely
    correct and avoid confusing programs which use getservent(), we probably
    want to do some sort of merge.  To be entirely correct we would probably
    want to hash the service names scanned from earlier files and skip
    any that are found to match in later files.

    That seems like a waste of memory to me but on the bright side there
    aren't very many programs which actually use getservent(), and the
    memory used by the hash would be returned at the end of the scan, 
    so it might not be all that bad.

					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>

More information about the Submit mailing list