(dom_alive), create a state enumeration (domainstates) and use it
instead.
Instead of three states (new, alive, and, effectively, 'troubled') go
to five: new, alive, pinging, lost, and dead.
Domains start in the NEW state. When we get a reply from a server, the
state goes to ALIVE. The state is set to PINGING when we ping the
server (once a minute normally) and if the ping times out, it goes to
LOST. If we stay lost for a minute, go to DEAD, and in DEAD, do
exponential backoff of nag_servers calls.
Getting rid of the broken logic attached to the 'troubled' state fixes
PR 15355 (ypbind defeats disk idle spindown) -- it will now only
rewrite the binding file when the binding changes.
Also, fix the HEURISTIC code so it doesn't trigger except in ALIVE
state. I think this was the source of a lot of the spamming behavior
seen in PR 32519, which is now fixed.
Might also fix PR 23135 (broadcast ypbind sometimes fails to find
servers).
Processing arguments just sets flags -- may as well do it first, and
this way detection of silly errors isn't contingent on having things
fully configured and operating.
"evil", this isn't one of them. Since the logic involved is to wait
until the default domain binds before backgrounding, call the variable
"started" instead.
per-domain. Also, use the file for the domain we're servicing instead
of always the file for the default domain.
Partly from Wolfgang Stukenbrock's patch in PR 43900.
is used the messages are sent via printf instead of syslog(3).
Also, make sure that none of the calls include a trailing newline and
issue a trailing newline in the -d case so they actually print properly.
(This was noted by Wolfgang Stukenbrock in PR 43900.)
And finally, fix some cases that could in some circumstances print
uninitialized errnos.
not just the yp_get_default_domain() domain), we must remove
any old binding files from /var/yp/binding (BINDINGDIR) from
previous runs, or the non-yp_get_default_domain()'s will not
bind properly. add a purge_bindingdir() function that basically
does "rm BINDINGDIR/*.[0-9]" at ypbind startup time.
example case of where this is an issue: bind a second (non-default)
domain. ypbind will create and flock a /var/yp/binding/xxx.2
file for it. stop and restart ypbind. the old /var/yp/binding/xxx.2
file will remain from the previous run. since it is not flock()'d
by the new instance of ypbind, libc functions like yp_master() will
fail without even bothering to talk to ypbind itself. (and ypbind
is totally unaware of the old file...)
to a 2-clause licence (retaining UCB clauses (1) and (2)), per PR
22409 from Joel Baker, approved by Theo de Raadt, and ratified by
myself - the only discrepancy being the handling of the original
clause 3 in src/usr.sbin/yppoll/yppoll.c.
Remove dom_server_port from struct _dom_binding. It's never initialised
and used in only one place, where dom_server_addr.sin_port was probably
intended.