import ipaddress
import stat
import shutil
+import shlex, subprocess
+
+from subprocess import Popen, TimeoutExpired, PIPE
# Third party modules
import six
from six.moves.urllib.parse import urlunsplit
# Own modules
-from .common import pp, to_bool, to_bytes
+from .common import pp, to_bool, to_bytes, to_str
from .cfg_app import PpCfgAppError, PpConfigApplication
from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile
-__version__ = '0.7.1'
+__version__ = '0.7.2'
LOG = logging.getLogger(__name__)
try:
self.replace_configfiles()
+ if not self.check_namedconf():
+ self.restore_configfiles()
+ self.exit(99)
except Exception:
self.restore_configfiles()
raise
shutil.rmtree(self.tempdir, False, emit_rm_err)
self.tempdir = None
+ # -------------------------------------------------------------------------
+ def check_namedconf(self):
+
+ LOG.info("Checking syntax correctness of named.conf ...")
+ cmd = shlex.split(self.cmd_checkconf)
+ LOG.debug("Executing: {}".format(' '.join(cmd)))
+
+ std_out = None
+ std_err = None
+ ret_val = None
+
+ with Popen(cmd, stdout=PIPE, stderr=PIPE) as proc:
+ try:
+ std_out, std_err = proc.communicate(timeout=10)
+ except TimeoutExpired:
+ proc.kill()
+ std_out, std_err = proc.communicate()
+ ret_val = proc.wait()
+
+ LOG.debug("Return value: {!r}".format(ret_val))
+ if std_out and std_out.strip():
+ s = to_str(std_out.strip())
+ LOG.debug("Output on STDOUT: {}".format(s))
+ if std_err and std_err.strip():
+ s = to_str(std_err.strip())
+ LOG.warn("Output on STDERR: {}".format(s))
+
+ if ret_val:
+ return False
+
+ return True
+
# =============================================================================