uuidd: use UUIDD_OP_GETPID instead of magic number

Make parameters passed to call_daemon() more descriptive:
- use UUIDD_OP_GETPID instead of magic number 0
- call_daemon() takes pointer as a last argument, so pass NULL instead
  of 0

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: remove useless initialization of cleanup_socket

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: factor out pidfile creation into separate function

Introduce create_pidfile() function.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: implement --no-pid option

With this option, uuidd does not create the PID file.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: use ignore_result helper

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: implement --no-fork option

With this option, uuidd does not daemonize itself but stays
in the foreground.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: factor out socket creation into separate function

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: implement --socket-activation option

Implement --socket-activation option, which is supposed to be used
with systemd (or equivalent init system) socket activation mechanism.
With this option, the UUID daemon does not create the socket on its own,
but instead expect the connection fd to be provided by the calling
process.

This option is only available if util-linux is configured with
--enable-socket-activation option. With this configure
option, the uuidd is compiled with sd-daemon.c.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: print all debugging information to stderr

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: do not drop privileges

libuuid can (for now) spawn uuidd on-demand. To support this scenario,
uuidd should be installed setuid/setgid to have access to
/var/lib/libuuid/clock.txt. Therefore, dropping the privileges is
not functional, so removing this ability.

Moreover, the ability to spawn uuidd on-demand will be removed anyway.

References: http://www.spinics.net/lists/util-linux-ng/msg05934.html

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
libuuid: use EXIT_FAILURE

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: add systemd unit files

Add systemd unit files which use the socket activation mechanism
of systemd. The uuidd deamon is started upon first request on the
socket and quits after 1 minute of inactivity.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
libuuid: don't exec uuidd

Executing the daemon from the shared library is not quite elegant
solution. Drop this functionality and require uuidd (should it be
needed) to be started from the initscript or by socket-activation.

References: http://www.spinics.net/lists/util-linux-ng/msg05967.html

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: introduce uuidd_cxt to pass arguments to server loop

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
libuuid: avoid double open and leaking descriptor

We are opening /dev/urandom twice in uuid_generate(): first to check if
the file is available and then later __uuid_generate_random() again to
actually get the random data. Moreover, descriptor from the first open
is leaking.

Fix by passign the descriptor down the stack and reusing it there.

References: http://marc.info/?l=util-linux-ng&m=133406051131131&w=2

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
uuidd: remove unnecessary variables

Signed-off-by: Karel Zak <kzak@redhat.com>