Build faild on systems without clock_gettime

Issue #998 resolved
Lutz Mader created an issue

Hello Tildeslash,
nice to see some problems are fixed, unfortunately some older systems do no support “clock_gettime”. Yo are right, CLOCK_MONOTONIC_RAW became available with MacOS 10.12, but older releases do not support “clock_gettime”, therefore CLOCK_MONOTONIC can not used also.

See issue #995, “Start delay period may be incorrect if system clock changes significantly during start up” for more information.

I add a fix to build monit 5.29.0 on older systems again.

Sorry, with regards,
Lutz

Appendage:
Build failed on older MacOS system without clock_gettime.

I fixed the problem by an additional #ifdef in libmonit/src/system/Time.c to get the old behaviour back again.

libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I./src -I./src -I./src/exceptions -I./src/io -I./src/net -I./src/util -I./src/thread -Wno-address -Wno-pointer-sign -g -O2 -Wextra -fstack-protector-all -DREENTRANT -D_GNU_SOURCE -Wall -Wunused -Wno-unused-label -funsigned-char -std=c99 -c src/system/Time.c  -fno-common -DPIC -o src/system/.libs/Time.o
src/system/Time.c:1286:6: warning: implicit declaration of function
      'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
        if (clock_gettime(CLOCK_MONOTONIC, &t) != 0)
            ^
src/system/Time.c:1286:20: error: use of undeclared identifier 'CLOCK_MONOTONIC'
        if (clock_gettime(CLOCK_MONOTONIC, &t) != 0)
                          ^
1 warning and 1 error generated.
make[3]: *** [src/system/Time.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

I will append a fix soon.

Comments (5)

  1. Tildeslash repo owner

    Build problems on older MacOS systems without “clock_gettime“, therefore CLOCK_MONOTONIC is not available. See issue #998 Build faild on systems without clock_gettime for additional information.

    → <<cset ac82b0477107>>

  2. Tildeslash repo owner

    Thanks for the path Lutz. We have refactored it a bit, please can you check if it compiles on that old system? (all systems we have work fine with clock_gettime and monotonic clock).

  3. Lutz Mader reporter

    Hello Tildeslash,
    thanks for your fast help.

    After bootstrap the repository the configure output contain an additional “clock_gettime” information line, a snipped only.

    checking for timegm... yes
    checking for getgrouplist... yes
    checking for getrandom... no
    checking for arc4random_buf... yes
    checking for clock_gettime... no
    checking for gcc... (cached) gcc
    checking whether we are using the GNU C compiler... (cached) yes
    checking whether gcc accepts -g... (cached) yes
    checking for gcc option to accept ISO C89... (cached) none needed
    checking whether gcc understands -c and -o together... (cached) yes
    checking dependency style of gcc... (cached) none
    checking for g++... g++
    checking whether we are using the GNU C++ compiler... yes
    checking whether g++ accepts -g... yes
    checking dependency style of g++... none
    checking how to run the C++ preprocessor... g++ -E
    checking for ld used by g++... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
    

    And libmonit/config.log contain some informations too.

    configure:12926: checking for clock_gettime
    configure:12926: gcc -o conftest -g -O2 -Wextra -fstack-protector-all   conftest.c -lm -lpthread -lz  >&5
    Undefined symbols for architecture x86_64:
      "_clock_gettime", referenced from:
          _main in conftest-6d5da3.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    An additional hint will given by make also.

    libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I./src -I./src -I./src/exceptions -I./src/io -I./src/net -I./src/util -I./src/thread -Wno-address -Wno-pointer-sign -g -O2 -Wextra -fstack-protector-all -DREENTRANT -D_GNU_SOURCE -Wall -Wunused -Wno-unused-label -funsigned-char -std=c99 -c src/system/Time.c  -fno-common -DPIC -o src/system/.libs/Time.o
    src/system/Time.c:1296:10: warning: "no monotonic clock available, fall back to gettimeofday" [-W#warnings]
            #warning "no monotonic clock available, fall back to gettimeofday"
             ^
    1 warning generated.
    

    Nice to see this, I can build Monit 5.29.0 on old MacOS systems without “clock_gettime” also, now.

    I find systems up to MacOS 10.13 without “clock_gettime”.

    Thanks for all help,
    with regards,
    Lutz

  4. Log in to comment