Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pal: platform abstraction layer and strerror_r(3) wrapper #8390

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

altimeter-130ft
Copy link

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


Testing

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

  • Debug log output from testing the change

  • 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

  • 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.

Glibc has the different return type and return value semantics from
POSIX.1-2001 on strerror_r(3).  Also, the glibc strerror_r(3) may return the
pointer different from the given one.

The difference will be absorbed by the platform abstraction layer,
committed separately.

Signed-off-by: Seigo Tanimura <[email protected]>
The signature is that of POSIX.1-2001.  If the returned string is not in the
supplied buffer, copy the string to it.

Signed-off-by: Seigo Tanimura <[email protected]>
Actually, only the external behaviour is tested; there is no support for the
mock of the library functions in general.

Signed-off-by: Seigo Tanimura <[email protected]>
flb_strerror_r() always terminates the string buffer by NUL.

Signed-off-by: Seigo Tanimura <[email protected]>
flb_strerror_r() always terminates the string buffer by NUL.

Signed-off-by: Seigo Tanimura <[email protected]>
flb_strerror_r() always returns the string into the supplied buffer.

Signed-off-by: Seigo Tanimura <[email protected]>
It is the C11 edition of strerror_r(3), provided by MSVC.

Signed-off-by: Seigo Tanimura <[email protected]>
…r(3).

It is misleading that the return type of strerror_s(3) is errno_t, while its
semantics is the int a la the Unix system calls.

While I am here, fix the unintended tabs.

Signed-off-by: Seigo Tanimura <[email protected]>
Such the condition seems not treated as a runtime constraint violation.

The best solution is hence to guarantee that the zero status means that a
NUL-terminated string is returned.

Signed-off-by: Seigo Tanimura <[email protected]>
Strerror_s(3) does not detect the short buffer, and that cannot be covered by
pal.

Signed-off-by: Seigo Tanimura <[email protected]>
Copy link
Contributor

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 github-actions bot added the Stale label Apr 19, 2024
@github-actions github-actions bot removed the Stale label Aug 16, 2024
Copy link
Contributor

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 github-actions bot added the Stale label Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants