Page 1 of 1

Compile Nagios Core 4.2.4 on AIX 7.1 using gcc

Posted: Fri Feb 03, 2017 5:28 am
by st_voss
Hi folks,

I just want share my findings that I made when trying to run and/or compile Nagios Core 4.2.4 on AIX 7.1 using gcc.

I started with using the Nagios RPM package from http://www.perzl.org/aix/index.php?n=Main.HomePage (a well known site for AIX open source packages)
Installation was ok, but when running the nagios binary from that package some errors showed up. So I had to compile my own package.
The Nagios SRPM file from http://www.perzl.org/ already contains some patches against Nagios 4.2.4 but I had to do further changes.

1.)

AIX out of the box cannot handle long arguments (e.g. --verbose or --help) so standard getopt has to be used.
The Nagios SRPM file from http://www.perzl.org/ already has this patch:

Code: Select all

*** ./base/workers.c.ORIG       Thu Mar 26 23:07:07 2015
--- ./base/workers.c    Thu Mar 26 23:07:15 2015
***************
*** 924,930 ****

  static int spawn_core_worker(void)
  {
!       char *argvec[] = {nagios_binary_path, "--worker", qh_socket_path ? qh_socket_path : DEFAULT_QUERY_SOCKET, NULL};
        int ret;

        if ((ret = spawn_helper(argvec)) < 0)
--- 924,930 ----

  static int spawn_core_worker(void)
  {
!       char *argvec[] = {nagios_binary_path, "-W", qh_socket_path ? qh_socket_path : DEFAULT_QUERY_SOCKET, NULL};
        int ret;

        if ((ret = spawn_helper(argvec)) < 0)

I had to do an additional patch. The getopt string in base/nagios.c needs to be "+hVvdspuxTW:" instead of "+hVvdspuxTW" because the "-W" option has an argument.

Code: Select all

*** ./base/nagios.c.orig        Mon Jan 23 09:22:33 2017
--- ./base/nagios.c     Mon Jan 23 09:35:57 2017
***************
*** 258,264 ****

        /* get all command line arguments */
        while(1) {
!               c = getopt(argc, argv, "+hVvdspuxTW");

                if(c == -1 || c == EOF)
                        break;
--- 258,264 ----

        /* get all command line arguments */
        while(1) {
!               c = getopt(argc, argv, "+hVvdspuxTW:");

                if(c == -1 || c == EOF)
                        break;

2.)

wait4() seems to misbehave on AIX 7.1 when called with WNOHANG. wait4() with WNOHANG aways returns 0. So the worker threads didn't know that the monitor scripts/commands had terminated.
As a workaround I had to call check_completion() like this: check_completion(cp, 0)

Code: Select all

*** ./lib/worker.c.ori  Mon Jan 23 13:26:17 2017
--- ./lib/worker.c      Wed Jan 25 12:12:20 2017
***************
*** 382,388 ****
         * first attempt at reaping, so see if we just failed to
         * notice that things were going wrong her
         */
!       if (reason == ETIME && !check_completion(cp, WNOHANG)) {
                timeouts++;
                wlog("job %d with pid %d reaped at timeout. timeouts=%u; started=%u", cp->id, pid, timeouts, started);
                return;
--- 382,388 ----
         * first attempt at reaping, so see if we just failed to
         * notice that things were going wrong her
         */
!       if (reason == ETIME && !check_completion(cp, 0)) {
                timeouts++;
                wlog("job %d with pid %d reaped at timeout. timeouts=%u; started=%u", cp->id, pid, timeouts, started);
                return;
***************
*** 489,495 ****
                        iobroker_close(iobs, io->fd);
                        io->fd = -1;
                        if (!final)
!                               check_completion(cp, WNOHANG);
                        break;
                }

--- 489,495 ----
                        iobroker_close(iobs, io->fd);
                        io->fd = -1;
                        if (!final)
!                               check_completion(cp, 0);
                        break;
                }


3.)

A patch for timeval. Don't know if this is really needed. gcc just gave a warning.

Code: Select all

*** ./lib/worker.c.orig Mon Jan 23 13:20:05 2017
--- ./lib/worker.c      Mon Jan 23 13:15:46 2017
***************
*** 209,215 ****

  #define kvvec_add_tv(kvv, key, value) \
        do { \
!               const char *buf = mkstr("%ld.%06ld", value.tv_sec, value.tv_usec); \
                kvvec_addkv_wlen(kvv, key, sizeof(key) - 1, buf, strlen(buf)); \
        } while (0)

--- 209,215 ----

  #define kvvec_add_tv(kvv, key, value) \
        do { \
!               const char *buf = mkstr("%ld.%06ld", (long)value.tv_sec, (long)value.tv_usec); \
                kvvec_addkv_wlen(kvv, key, sizeof(key) - 1, buf, strlen(buf)); \
        } while (0)

4.)

Some patches by Mr. Perzl from the Nagios SRPM file from http://www.perzl.org/

Code: Select all

*** ./include/config.h.in.ORIG  Thu Feb 13 20:31:02 2014
--- ./include/config.h.in       Thu Feb 13 20:31:21 2014
***************
*** 268,276 ****
--- 268,278 ----
  #include <netdb.h>
  #endif

+ #ifndef _AIX51
  #undef HAVE_LIBGEN_H
  #ifdef HAVE_LIBGEN_H
  #include <libgen.h>
+ #endif
  #endif

  #undef HAVE_SYS_UN_H
*** ./configure.ORIG    Thu Feb 13 20:33:51 2014
--- ./configure Thu Feb 13 20:34:27 2014
***************
*** 7396,7402 ****
        { echo "$as_me:$LINENO: checking for extra flags needed to export symbols" >&5
  echo $ECHO_N "checking for extra flags needed to export symbols... $ECHO_C" >&6; }
        case $host_os in
!               aix4*|aix5*)
                        BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-bexpall,-brtl"
                ;;
                bsdi*)
--- 7396,7402 ----
        { echo "$as_me:$LINENO: checking for extra flags needed to export symbols" >&5
  echo $ECHO_N "checking for extra flags needed to export symbols... $ECHO_C" >&6; }
        case $host_os in
!               aix[4-9]*)
                        BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-bexpall,-brtl"
                ;;
                bsdi*)
*** ./base/Makefile.in.ORIG     Thu Feb 13 21:12:00 2014
--- ./base/Makefile.in  Thu Feb 13 21:12:26 2014
***************
*** 11,17 ****
  SRC_LIB=../lib

  CC=@CC@
! CFLAGS=-Wall -I.. @CFLAGS@ @DEFS@ -DNSCORE

  # Compiler flags for use with gprof
  #CFLAGS=-pg -DHAVE_CONFIG_H -DNSCORE
--- 11,17 ----
  SRC_LIB=../lib

  CC=@CC@
! CFLAGS=-I.. @CFLAGS@ @DEFS@ -DNSCORE

  # Compiler flags for use with gprof
  #CFLAGS=-pg -DHAVE_CONFIG_H -DNSCORE
That's it for now. I hope this information is useful.

Regards,
Stefan

Re: Compile Nagios Core 4.2.4 on AIX 7.1 using gcc

Posted: Fri Feb 03, 2017 11:07 am
by dwhitfield
@jfrickson, lead Nagios Core developer, said
very helpful!
I'm going to lock this up. If you have additional details to add, please do so at https://github.com/NagiosEnterprises/na ... issues/326

Thanks from myself as well. :)