Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  2. ZBX-15677

module.h is insufficient to compile loadable module


    • Team C
    • Sprint 56 (Sep 2019), Sprint 55 (Aug 2019), Sprint 51 (Apr 2019), Sprint 54 (Jul 2019), Sprint 57 (Oct 2019), Sprint 58 (Nov 2019), Sprint 59 (Dec 2019), Sprint 60 (Jan 2020), Sprint 61 (Feb 2020), Sprint 62 (Mar 2020), Sprint 63 (Apr 2020), Sprint 64 (May 2020), Sprint 65 (Jun 2020), Sprint 66 (Jul 2020), Sprint 67 (Aug 2020)
    • 0.25

      Steps to reproduce:

      1. Download Zabbix sources or check out from repository
      2. Navigate to src/modules/dummy
      3. Comment out
        #include "sysinc.h"

        leaving just

        #include "module.h"
      4. Try to build module: $ make

      Tons of compilation errors.

      Successful compilation.

      This happens because module.h depends on zbxtypes.h, and zbxtypes.h in turn (implicitly!) depends on lots of system headers. So the only way to compile loadable module is to

      #include "sysinc.h"


      #include "module.h"

      But that's not the end of the story because sysinc.h includes system headers conditionally with conditional variables defined in another header(!!!) config.h which is generated by configure script. So one has to run $ ./configure before even attempting to build poor dummy module.

      I think this is unacceptable. Module authors need to be quite creative to work around that and this puts extra stress on build systems and continuous integration. The only reason to

      #include "zbxtypes.h"

      in module.h is definition of zbx_uint64_t:

      #if defined(_WINDOWS)
      /* ... (irrelevant while loadable modules are only available on UNIX platforms) */
      #else	/* _WINDOWS */
      /* ... */
      #	define zbx_uint64_t	uint64_t
      /* ... */
      #endif	/* _WINDOWS */

      My suggestion is to provide definition of zbx_uint64_t in module.h if it is used outside of Zabbix:

      Index: include/module.h
      --- include/module.h	(revision 89838)
      +++ include/module.h	(working copy)
      @@ -20,7 +20,10 @@
       #ifndef ZABBIX_MODULE_H
       #define ZABBIX_MODULE_H
      -#include "zbxtypes.h"
      +#ifndef zbx_uint64_t
      +#	include <stdint.h>
      +#	define zbx_uint64_t uint64_t
       #define ZBX_MODULE_OK	0
       #define ZBX_MODULE_FAIL	-1

      Since stdint.h is part of C99, this should cover most of use cases.

      With explicit inclusion of necessary headers in dummy.c:

      Index: src/modules/dummy/dummy.c
      --- src/modules/dummy/dummy.c	(revision 89838)
      +++ src/modules/dummy/dummy.c	(working copy)
      @@ -17,7 +17,10 @@
       ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
      -#include "sysinc.h"
      +#include <stdlib.h>
      +#include <string.h>
      +#include <time.h>
       #include "module.h"
       /* the variable keeps timeout setting for item processing */

      the module compiles cleanly requiring just module.h from Zabbix SVN or source tarball. Zabbix code compiles too.

            zabbix.support Zabbix Support Team
            cyclone Glebs Ivanovskis
            Team C
            4 Vote for this issue
            8 Start watching this issue