From: Jason Ish Date: Mon, 21 May 2018 14:55:19 +0000 (-0600) Subject: python: fixes for out of tree build X-Git-Tag: suricata-4.1.0-rc1~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e06e765f39088c51a700cf232f2c3cc953929f7;p=thirdparty%2Fsuricata.git python: fixes for out of tree build Autoconf/automake and python setup.py don't play that well together with out of tree builds. Makes suricatasc not an autoconf input file, instead use the defaults module that is already being created. In the case of an out of tree build, copy the generated defaults.py to the build directory manually. --- diff --git a/configure.ac b/configure.ac index deabdb7219..bb1821c38c 100644 --- a/configure.ac +++ b/configure.ac @@ -2296,7 +2296,7 @@ AC_SUBST(CONFIGURE_SYSCONDIR) AC_SUBST(CONFIGURE_LOCALSTATEDIR) AC_SUBST(PACKAGE_VERSION) -AC_OUTPUT(Makefile src/Makefile rust/Makefile rust/Cargo.toml rust/.cargo/config qa/Makefile qa/coccinelle/Makefile rules/Makefile doc/Makefile doc/userguide/Makefile contrib/Makefile contrib/file_processor/Makefile contrib/file_processor/Action/Makefile contrib/file_processor/Processor/Makefile contrib/tile_pcie_logd/Makefile suricata.yaml etc/Makefile etc/suricata.logrotate etc/suricata.service python/Makefile python/suricata/config/defaults.py python/bin/suricatasc ebpf/Makefile) +AC_OUTPUT(Makefile src/Makefile rust/Makefile rust/Cargo.toml rust/.cargo/config qa/Makefile qa/coccinelle/Makefile rules/Makefile doc/Makefile doc/userguide/Makefile contrib/Makefile contrib/file_processor/Makefile contrib/file_processor/Action/Makefile contrib/file_processor/Processor/Makefile contrib/tile_pcie_logd/Makefile suricata.yaml etc/Makefile etc/suricata.logrotate etc/suricata.service python/Makefile python/suricata/config/defaults.py ebpf/Makefile) SURICATA_BUILD_CONF="Suricata Configuration: AF_PACKET support: ${enable_af_packet} diff --git a/python/.gitignore b/python/.gitignore index 21cc772571..25a040f658 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -3,7 +3,5 @@ build lib/ scripts-*/ -bin/suricatasc -!bin/suricatasc.in suricata/config/defaults.py !suricata/config/defaults.py.in diff --git a/python/bin/suricatasc.in b/python/bin/suricatasc similarity index 90% rename from python/bin/suricatasc.in rename to python/bin/suricatasc index 0027469cc2..99af497779 100755 --- a/python/bin/suricatasc.in +++ b/python/bin/suricatasc @@ -38,6 +38,12 @@ else: from suricata.sc import * +try: + from suricata.config import defaults + has_defaults = True +except: + has_defaults = False + parser = argparse.ArgumentParser(prog='suricatasc', description='Client for Suricata unix socket') parser.add_argument('-v', '--verbose', action='store_const', const=True, help='verbose output (including JSON dump)') parser.add_argument('-c', '--command', default=None, help='execute on single command and return JSON') @@ -46,8 +52,11 @@ args = parser.parse_args() if args.socket != None: SOCKET_PATH = args.socket +elif has_defaults: + SOCKET_PATH = os.path.join(defaults.localstatedir, "suricata-command.socket") else: - SOCKET_PATH = "@e_localstatedir@/suricata-command.socket" + print("Unable to determine path to suricata-command.socket.", file=sys.stderr) + sys.exit(1) sc = SuricataSC(SOCKET_PATH, verbose=args.verbose) try: diff --git a/python/setup.py b/python/setup.py index 08f43bf6ee..16c5572d33 100644 --- a/python/setup.py +++ b/python/setup.py @@ -3,8 +3,10 @@ from __future__ import print_function import os import re import sys +import shutil from distutils.core import setup +from distutils.command.build_py import build_py version = None if os.path.exists("../configure.ac"): @@ -18,7 +20,22 @@ if version is None: print("error: failed to parse Suricata version, will use 0.0.0", file=sys.stderr) version = "0.0.0" - + +class do_build(build_py): + def run(self): + build_py.run(self) + defaults_py_out = os.path.join( + self.build_lib, "suricata", "config", "defaults.py") + if not os.path.exists(defaults_py_out): + # Must be an out of tree build, find defaults.py. + defaults_py_in = os.path.join( + self.build_lib, "..", "suricata", "config", "defaults.py") + if os.path.exists(defaults_py_in): + shutil.copy(defaults_py_in, defaults_py_out) + else: + print("error: failed to find defaults.py") + sys.exit(1) + setup( name="suricata", description="Suricata control tools", @@ -48,4 +65,5 @@ setup( 'Programming Language :: Python', 'Topic :: System :: Systems Administration', ], + cmdclass={'build_py': do_build}, ) diff --git a/python/suricata/config/defaults.py.in b/python/suricata/config/defaults.py.in index 3156e81689..f46935189a 100644 --- a/python/suricata/config/defaults.py.in +++ b/python/suricata/config/defaults.py.in @@ -1,2 +1,3 @@ sysconfdir = "@e_sysconfdir@" datarulesdir = "@e_datarulesdir@" +localstatedir = "@e_localstatedir@"