Skip to content

Commit

Permalink
posix: signal: include_next to get the libc signal() decl
Browse files Browse the repository at this point in the history
Although the ANSI C version of signal() is not yet supported in
Zephyr, because Zephyr does not use process-wide signals, some
users rely on its declaration.

Include the libc version of signal.h when POSIX signals are
not configured.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
  • Loading branch information
cfriedt committed Aug 9, 2023
1 parent 9bd8c7a commit a27c16f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 18 additions & 6 deletions include/zephyr/posix/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#ifndef ZEPHYR_INCLUDE_POSIX_SIGNAL_H_
#define ZEPHYR_INCLUDE_POSIX_SIGNAL_H_

#ifdef CONFIG_POSIX_SIGNAL

#include "posix_types.h"

#ifdef __cplusplus
extern "C" {
#endif
#define SIG_DFL ((sighandler_t)0)
#define SIG_ERR ((sighandler_t)1)
#define SIG_IGN ((sighandler_t)-1)

#ifdef CONFIG_POSIX_SIGNAL
#define SIGHUP 1 /**< Hangup */
#define SIGINT 2 /**< Interrupt */
#define SIGQUIT 3 /**< Quit */
Expand Down Expand Up @@ -49,7 +50,9 @@ extern "C" {
#define SIGRTMAX (SIGRTMIN + CONFIG_POSIX_RTSIG_MAX)
#define _NSIG (SIGRTMAX + 1)

BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= 0);
#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
unsigned long sig[DIV_ROUND_UP(_NSIG, BITS_PER_LONG)];
Expand All @@ -61,7 +64,6 @@ int sigfillset(sigset_t *set);
int sigaddset(sigset_t *set, int signo);
int sigdelset(sigset_t *set, int signo);
int sigismember(const sigset_t *set, int signo);
#endif /* CONFIG_POSIX_SIGNAL */

#ifndef SIGEV_NONE
#define SIGEV_NONE 1
Expand Down Expand Up @@ -90,8 +92,18 @@ struct sigevent {
pthread_attr_t *sigev_notify_attributes;
};

/* Note: signal() is intentionally unimplemented in Zephyr */
typedef void (*sighandler_t)(int signo);
sighandler_t signal(int signum, sighandler_t handler);

#ifdef __cplusplus
}
#endif

#else

#include_next <signal.h>

#endif /* CONFIG_POSIX_SIGNAL */

#endif /* ZEPHYR_INCLUDE_POSIX_SIGNAL_H_ */
2 changes: 2 additions & 0 deletions lib/posix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <zephyr/posix/signal.h>

BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= 0);

#define SIGNO_WORD_IDX(_signo) (signo / BITS_PER_LONG)
#define SIGNO_WORD_BIT(_signo) (signo & BIT_MASK(LOG2(BITS_PER_LONG)))

Expand Down

0 comments on commit a27c16f

Please sign in to comment.