Blob Blame History Raw
From 29cf6ce568747eca90497a29aa21927ac2b69496 Mon Sep 17 00:00:00 2001
From: Petr Spacek <pspacek@redhat.com>
Date: Mon, 31 Aug 2015 17:58:07 +0200
Subject: [PATCH] DNSSEC: prevent ipa-ods-exporter from looping after service
 auto-restart

It might happen that systemd will restart the service even if there is
no incomming connection to service socket. In that case we want to exit
because HSM synchronization is done before socket.accept() and we want
to synchronize HSM and DNS zones at the same time.

https://fedorahosted.org/freeipa/ticket/5273

Reviewed-By: Martin Basti <mbasti@redhat.com>
Reviewed-By: Oleg Fayans <ofayans@redhat.com>
---
 daemons/dnssec/ipa-ods-exporter | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/daemons/dnssec/ipa-ods-exporter b/daemons/dnssec/ipa-ods-exporter
index 62eca71da10ee6f3efd4d391a274278875714570..9544db149aed6574a8962d6c8e6b6f1bc520d6db 100755
--- a/daemons/dnssec/ipa-ods-exporter
+++ b/daemons/dnssec/ipa-ods-exporter
@@ -25,6 +25,7 @@ import logging
 import os
 import subprocess
 import socket
+import select
 import sys
 import systemd.daemon
 import systemd.journal
@@ -346,7 +347,12 @@ def receive_systemd_command(log):
         raise KeyError('Exactly one socket is expected.')
 
     sck = socket.fromfd(fds[0], socket.AF_UNIX, socket.SOCK_STREAM)
+    rlist, wlist, xlist = select.select([sck], [], [], 0)
+    if not rlist:
+        log.critical('socket activation did not return socket with a command')
+        sys.exit(0)
 
+    log.debug('accepting new connection')
     conn, addr = sck.accept()
     log.debug('accepted new connection %s', repr(conn))
 
-- 
2.5.1