posix: pthread_sigmask should return error number when fail

According to the Posix specification:
Upon successful completion pthread_sigmask() shall return 0;
otherwise, it shall return the corresponding error number.
This commit is contained in:
yang.zhang
2025-07-01 17:10:51 +08:00
committed by Kinsey Moore
parent 58795be2cb
commit 08c005764d
4 changed files with 21 additions and 12 deletions

View File

@@ -58,8 +58,9 @@ int pthread_sigmask(
{ {
POSIX_API_Control *api; POSIX_API_Control *api;
if ( !set && !oset ) if ( !set && !oset ) {
rtems_set_errno_and_return_minus_one( EINVAL ); return EINVAL;
}
api = _Thread_Get_executing()->API_Extensions[ THREAD_API_POSIX ]; api = _Thread_Get_executing()->API_Extensions[ THREAD_API_POSIX ];
@@ -80,7 +81,7 @@ int pthread_sigmask(
api->signals_unblocked = ~*set; api->signals_unblocked = ~*set;
break; break;
default: default:
rtems_set_errno_and_return_minus_one( EINVAL ); return EINVAL;
} }
/* XXX are there critical section problems here? */ /* XXX are there critical section problems here? */

View File

@@ -57,7 +57,15 @@ int sigprocmask(
*/ */
#if defined(RTEMS_POSIX_API) #if defined(RTEMS_POSIX_API)
return pthread_sigmask( how, set, oset ); int status;
status = pthread_sigmask( how, set, oset );
if ( status == 0 ) {
return 0;
}
return -1;
#else #else
return -1; return -1;
#endif #endif

View File

@@ -535,15 +535,15 @@ void *POSIX_Init(
puts( "Init: sigaction - EINVAL (SIGKILL)" ); puts( "Init: sigaction - EINVAL (SIGKILL)" );
status = pthread_sigmask( SIG_BLOCK, NULL, NULL ); status = pthread_sigmask( SIG_BLOCK, NULL, NULL );
if ( status != -1 ) if ( status != EINVAL )
printf( "status = %d\n", status ); printf( "status = %d\n", status );
rtems_test_assert( errno == EINVAL ); rtems_test_assert( status == EINVAL );
puts( "Init: pthread_sigmask - EINVAL (set and oset invalid)" ); puts( "Init: pthread_sigmask - EINVAL (set and oset invalid)" );
status = pthread_sigmask( 999, &pending_set, NULL ); status = pthread_sigmask( 999, &pending_set, NULL );
if ( status != -1 ) if ( status != EINVAL )
printf( "status = %d\n", status ); printf( "status = %d\n", status );
rtems_test_assert( errno == EINVAL ); rtems_test_assert( status == EINVAL );
puts( "Init: pthread_sigmask - EINVAL (how invalid)" ); puts( "Init: pthread_sigmask - EINVAL (how invalid)" );
status = sigpending( NULL ); status = sigpending( NULL );
@@ -557,14 +557,14 @@ void *POSIX_Init(
if ( status != -1 ) if ( status != -1 )
printf( "status = %d\n", status ); printf( "status = %d\n", status );
rtems_test_assert( errno == EINVAL ); rtems_test_assert( errno == EINVAL );
puts( "Init: pthread_sigmask - EINVAL (timout->nsec invalid < 0)" ); puts( "Init: sigtimedwait - EINVAL (timout->nsec invalid < 0)" );
timeout.tv_nsec = 0x7fffffff; timeout.tv_nsec = 0x7fffffff;
status = sigtimedwait( &mask, &info, &timeout ); status = sigtimedwait( &mask, &info, &timeout );
if ( status != -1 ) if ( status != -1 )
printf( "status = %d\n", status ); printf( "status = %d\n", status );
rtems_test_assert( errno == EINVAL ); rtems_test_assert( errno == EINVAL );
puts( "Init: pthread_sigmask - EINVAL (timout->nsec invalid to large)" ); puts( "Init: sigtimedwait - EINVAL (timout->nsec invalid to large)" );
status = pthread_kill( Init_id, 999 ); status = pthread_kill( Init_id, 999 );
rtems_test_assert( status == EINVAL ); rtems_test_assert( status == EINVAL );

View File

@@ -99,8 +99,8 @@ Init: sigaction - EINVAL (SIGKILL)
Init: pthread_sigmask - EINVAL (set and oset invalid) Init: pthread_sigmask - EINVAL (set and oset invalid)
Init: pthread_sigmask - EINVAL (how invalid) Init: pthread_sigmask - EINVAL (how invalid)
Init: sigpending - EINVAL (set invalid) Init: sigpending - EINVAL (set invalid)
Init: pthread_sigmask - EINVAL (timout->nsec invalid < 0) Init: sigtimedwait - EINVAL (timout->nsec invalid < 0)
Init: pthread_sigmask - EINVAL (timout->nsec invalid to large) Init: sigtimedwait - EINVAL (timout->nsec invalid to large)
Init: pthread_kill - EINVAL (sig invalid) Init: pthread_kill - EINVAL (sig invalid)
Init: pthread_kill - EINVAL (signal = 0) Init: pthread_kill - EINVAL (signal = 0)
Init: pthread_kill - SUCCESSFUL (signal = SIG_IGN) Init: pthread_kill - SUCCESSFUL (signal = SIG_IGN)