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

module.h is insufficient to compile loadable module

    Details

    • Team:
      Team A
    • Sprint:
      Sprint 51 (Apr 2019)
    • Story Points:
      0.25

      Description

      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

      Result:
      Tons of compilation errors.

      Expected:
      Successful compilation.

      Speculations:
      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"

      before(!)

      #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
      +#endif
       
       #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.

        Attachments

          Activity

            People

            • Assignee:
              MVekslers Michael Veksler
              Reporter:
              cyclone Glebs Ivanovskis
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: