Skip to content

Conversation

cfriedt
Copy link
Member

@cfriedt cfriedt commented Oct 13, 2025

This change corrects 2 typos in posix_signal.h and posix_time.h and additionally ensures that libc definitions of struct timespec are indicated via macro to avoid redefinition warnings / errors.

  • libc: newlib + picolibc: indicate sigevent and sigval are declared
  • libc: indicate timeval is defined
  • libc: indicate timespec is defined
  • posix: signal.h: always pull in time_t definition from libc
  • posix: signal.h: do not define struct timespec when >= c11
  • posix: time.h: timepsec is a struct not a typedef
  • posix: signal.h: sigevent is a struct not a typedef
  • posix: signal.h: reorder where sigval is declared
  • posix: signal.h: include sigev_notify_function field in struct sigevent

The issues do not affect CI or build status at the moment but do block changes slated for v4.3.0

@cfriedt cfriedt force-pushed the posix-signal-always-use-time-t-from-time-h branch from 34c10f3 to 1006361 Compare October 13, 2025 13:01
@cfriedt cfriedt changed the title posix: signal.h: always pull in time_t definition from libc posix: multiple corrections in posix_time.h and posix_signal.h Oct 13, 2025
@cfriedt cfriedt force-pushed the posix-signal-always-use-time-t-from-time-h branch 2 times, most recently from fb423c7 to 6513fbe Compare October 13, 2025 14:18
@cfriedt cfriedt requested review from jhedberg and ycsin October 13, 2025 14:48
@cfriedt cfriedt added this to the v4.3.0 milestone Oct 13, 2025
@cfriedt cfriedt added the area: POSIX POSIX API Library label Oct 13, 2025
@cfriedt cfriedt marked this pull request as ready for review October 13, 2025 14:50
@zephyrbot zephyrbot added the area: C Library C Standard Library label Oct 13, 2025
Indicate that C library headers have declared `struct sigevent` and
`struct sigval` to avoid redefinition warnings / errors.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the posix-signal-always-use-time-t-from-time-h branch from 6513fbe to 24b2761 Compare October 13, 2025 15:18
@cfriedt
Copy link
Member Author

cfriedt commented Oct 13, 2025

  • added macros to indicate that the c library has declared struct sigevent
  • added macros to indicate that the c library has declared union sigval
  • added macros to indicate that the c library has declared struct timespec

@cfriedt cfriedt closed this Oct 13, 2025
@cfriedt cfriedt reopened this Oct 13, 2025
@cfriedt cfriedt changed the title posix: multiple corrections in posix_time.h and posix_signal.h libc + posix: fix typos and avoid redeclaration warnings / errors Oct 13, 2025
@cfriedt cfriedt changed the title libc + posix: fix typos and avoid redeclaration warnings / errors libc + posix: signal.h + time.h: fix typos and avoid redeclaration warnings / errors Oct 13, 2025
In order to avoid multiple definition errors, indicate that struct
timespec is declared.

Signed-off-by: Chris Friedt <[email protected]>
In order to avoid multiple definition errors, indicate that struct
timeval is declared.

Signed-off-by: Chris Friedt <[email protected]>
Avoid redefining `time_t` by always including the definition from
`<time.h>`, since the C library may use something other than `long`.

This is still safe according to the specification, since it explicitly
states:

> Inclusion of the <signal.h> header may make visible all symbols from
> the <time.h> header.

For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html

Signed-off-by: Chris Friedt <[email protected]>
C11 requires `<time.h>` to define `struct timespec`, so do not define
it when C11 is already known.

Signed-off-by: Chris Friedt <[email protected]>
A previous typo went undetected that declared a type-defined
`timespec_t`, which is obviously incorrect, since it is only specified as
`struct timespec`.

Signed-off-by: Chris Friedt <[email protected]>
A previous typo went undetected that declared a type-defined
`sigevent_t`, which is obviously incorrect, since it is only specified as
`struct sigevent`.

Signed-off-by: Chris Friedt <[email protected]>
In order to avoid warnings, declare `union sigval` ahead of
`struct sigevent`.

Signed-off-by: Chris Friedt <[email protected]>
Previously, the `sigev_notify_function` field was missing from
`struct sigevent`.

Add it back to ensure that we are able to support realtime signals.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the posix-signal-always-use-time-t-from-time-h branch from 24b2761 to c148cf3 Compare October 14, 2025 21:08
Copy link


#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__)

union sigval; /* forward declaration (to preserve spec order) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering - can't we keep it as-is?

Copy link
Member Author

@cfriedt cfriedt Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't.

diff --git a/lib/posix/options/Kconfig.device_io b/lib/posix/options/Kconfig.device_io
index 416ccf74a62..71ff6b7b81c 100644
--- a/lib/posix/options/Kconfig.device_io
+++ b/lib/posix/options/Kconfig.device_io
@@ -6,7 +6,7 @@ menu "POSIX device I/O"
 
 config POSIX_DEVICE_IO
        bool "POSIX device I/O"
-       select REQUIRES_FULL_LIBC
+       #select REQUIRES_FULL_LIBC
        select ZVFS
        select ZVFS_POLL
        select ZVFS_SELECT
west build -p -b qemu_riscv64 -t run tests/posix/signals/ -- -DCONFIG_MINIMAL_LIBC=y -DCONFIG_COMPILER_WARNINGS_AS_ERRORS=y
...
/home/cfriedt/zephyrproject/zephyr/include/zephyr/posix/posix_signal.h:109:22: error: field 'sigev_value' has incomplete type
  109 |         union sigval sigev_value;
      |                      ^~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: C Library C Standard Library area: POSIX POSIX API Library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants