cpukit/posix: signal() should return SIG_ERR on error

When signum is invalid, return SIG_ERR, and set errno to
indicate the cause.
This commit is contained in:
yang.zhang
2025-02-08 10:18:26 +08:00
committed by Kinsey Moore
parent 52b9cc90cb
commit ad81baf160
2 changed files with 8 additions and 1 deletions

View File

@@ -74,6 +74,8 @@ sighandler_t signal(
s.sa_flags = 0;
#endif
sigaction( signum, &s, &old );
if ( sigaction( signum, &s, &old ) < 0 )
return (SIG_ERR);
return (sighandler_t) old.sa_handler;
}

View File

@@ -139,6 +139,11 @@ void *POSIX_Init(
TEST_BEGIN();
/* invalid signum return SIG_ERR */
sighandler_t old_handler = signal( 0, SIG_DFL );
rtems_test_assert( old_handler == SIG_ERR );
rtems_test_assert( errno == EINVAL );
block_all_signals();
/* set the time of day, and print our buffer in multiple ways */