master: Fix flushing changes to shadow masters on exit

There was a possibility that when stopping the master server not all
changes were successfully sent to connected metaloggers and shadow
masters. Consider the following scenario:

* master server creates a lot of changelogs and receives SIGTERM
* before exiting, the master server writes all the changes to sockets
* master server closes all sockets and terminates
* operating system flushes data from sockets' buffers in background

Now if a shadow master sends any message to the master server, the
operating system on the master server's side would drop all
unacknowledged data from socket buffers and reply with RST. This is how
TCP handles a situation when new data arrives to a socket, which is no
longer opened by any process, but exists because it waits for all the
data to be transmitted and acked. Shadow masters send many messages to
the master server which might result in a connection reset and losing
data, e.g. ANTOAN_NOP. This can be observed in
test_flushing_changes_to_shadow, which often fails.

This commit fixes the issue, by changing the exit phase from:

* write all pending messages to ma<->ml sockets
* close all ma<->ml sockets
* terminate

to:

* write all pending messages to ma<->ml sockets
* write LIZ_MATOML_END_SESSION message to each ma<->ml socket; metaloggers
  and shadow masters close connections when this message is received
* wait for sockets to be closed by shadow masters and metaloggers
* terminate

This makes sure that all changes are received by all the connected shadow
masters. The LIZ_MATOML_END_SESSION is handled by shadow masters and
metaloggers in the following way:

* old versions close the socket because of an "unknown message" error
* newer versions understand this message and close the socket in the
  packet's handler.

LIZ_MATOML_END_SESSION is always the last message sent by the master
server. No other messages would be created after sending this one.

Change-Id: Ie93fb9362f80e2c93155a5358aab3f24651abd10