fluent-bit icon indicating copy to clipboard operation
fluent-bit copied to clipboard

pal: platform abstraction layer and strerror_r(3) wrapper

Open altimeter-130ft opened this issue 1 year ago • 1 comments

This PR is for the following changes:

  • Introduce the pal module, the platform abstraction layer.
  • Add flb_strerror_r(), the wrapper of strerror_r(3).

Fixed Issue

#8379

Background

The strerror_r(3) implementations of glibc and POSIX.1-2001 have the different signatures and usages, which causes a build error and/or an unexpected behaviour.

Please refer to Issue #8379 for the detailed analysis.

Changes

This fix implements flb_strerror_r(), the POSIX.1-2001-compliant wrapper of strerror_r(3) into pal, the new core module dedicated to encapsulate the platform dependency found on the common external features. The goal of pal is similar to the AC_LIBOBJ() macro of GNU Autoconf, except that pal holds all wrapper functions in a single source.

The wrapper functions in pal are intended for the Fluent Bit core and plugins only. The third-party libraries under lib must not call them, in order to keep their independency.

pal Source Files

  • src/flb_pal.c
  • include/fluent-bit/flb_pal.h

pal Internal Test Files

  • tests/internal/pal.c

New pal Function

  • int flb_strerror_r(int errnum, char *buf, size_t buflen); The wrapper of strerror_r(3) with the signature and semantics of POSIX.1-2001. Available if strerror_r(3) exists in the platform, regardless from its implementation.

flb_strerror_r() Callers

The strerror_r(3) calls in the following files have been converted to flb_strerror_r():

  • src/flb_io.c
  • src/flb_log.c
  • src/flb_network.c

Tested Environments

  • Debian x86_64 12.2 (strerror_r(3) standard: glibc)
  • FreeBSD/amd64 14.0-RELEASE (strerror_r(3) standard: POSIX.1-2001)
    • fluent/fluent-bit/pull/8376 included for the coverage report.

Testing

  • N/A Example configuration file for the change The issue does not depend on a specific configuration.

  • [x] Debug log output from testing the change

  • [x] Attached Valgrind output that shows no leaks or memory corruption was found

Test Results

  • Debian x86_64 12.2: logs-fluent-bit-topic-pal-strerror_r-wrapper-github-pr-debian_x86_64_12_2.zip
    • fluent-bit-cmake-topic-pal-strerror_r-wrapper-github-pr-debian_x86_64_12_2.log The cmake log.
    • fluent-bit-make-topic-pal-strerror_r-wrapper-github-pr-debian_x86_64_12_2.log The make log.
    • fluent-bit-ctest-topic-pal-strerror_r-wrapper-github-pr-debian_x86_64_12_2.log The ctest log.
    • fluent-bit-ctest-topic-pal-strerror_r-wrapper-github-pr-debian_x86_64_12_2-LastTest.log The LastTest.log file out of ctest.
    • fluent-bit-valgrind-topic-pal-strerror_r-wrapper-github-pr-debian_x86_64_12_2.log The valgrind --leak-check=full log. No memory leak happened.
    • gcov-tests-topic-pal-strerror_r-wrapper-github-pr-debian_x86_64_12_2.tar.xz The lcov coverage report.
      • The new code has been covered except for one.
        • Can we depend on the glibc strerror_r(3) never returning NULL?
  • FreeBSD/amd64 14.0-RELEASE: logs-fluent-bit-topic-pal-strerror_r-wrapper-freebsd_amd64_14_0_release.zip
    • fluent-bit-cmake-topic-pal-strerror_r-wrapper-freebsd_amd64_14_0_release.log The cmake log.
    • fluent-bit-make-topic-pal-strerror_r-wrapper-freebsd_amd64_14_0_release.log The make log.
    • fluent-bit-ctest-topic-pal-strerror_r-wrapper-freebsd_amd64_14_0_release.log The ctest log.
    • fluent-bit-ctest-topic-pal-strerror_r-wrapper-freebsd_amd64_14_0_release-LastTest.log The LastTest.log file out of ctest.
    • fluent-bit-valgrind-topic-pal-strerror_r-wrapper-freebsd_amd64_14_0_release.log The valgrind --leak-check=full log.
      • The coverage is disabled because of the Valgrind problem that makes an assertion failure.
      • Many conditional jumps or moves on uninitialised value.
        • These are the false errors; no conditional instructions have been found out of the codewalk.
      • 3 blocks are still reachable with flb_strerror_r().
        • These are for the NLS message catalogue, read only once and staying until the process exits.
      • The rest of the leaks do not involve the Fluent Bit implementation.
    • llvm-cov-tests-topic-pal-strerror_r-wrapper-freebsd_amd64_14_0_release.tar.xz The LLVM coverage report.
      • The new code has been covered.

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • N/A Run local packaging test showing all targets (including any new ones) build.
  • N/A Set ok-package-test label to test for all targets (requires maintainer to do). Packaging is not affected.

Documentation

  • ? Documentation required for this feature The pal paragraph in DEVELOPER_GUIDE.md?

Backporting

  • [x] Backport to latest stable release. This PR is the fix to a build breakage.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

altimeter-130ft avatar Jan 18 '24 15:01 altimeter-130ft

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Apr 19 '24 01:04 github-actions[bot]