Skip to content

Build fails is pthread_getname_np is unavailable, since nothing actually checks for it #1220

@barracuda156

Description

@barracuda156

Describe the bug

This code does not work as supposed to, if pthread_getname_np is unavailable:

int aws_thread_name(struct aws_allocator *allocator, aws_thread_id_t thread_id, struct aws_string **out_name) {
*out_name = NULL;
#if defined(AWS_PTHREAD_GETNAME_TAKES_2ARGS) || defined(AWS_PTHREAD_GETNAME_TAKES_3ARGS) || \
defined(AWS_PTHREAD_GET_NAME_TAKES_2_ARGS)
char name[THREAD_NAME_BUFFER_SIZE] = {0};
# ifdef AWS_PTHREAD_GETNAME_TAKES_3ARGS
if (pthread_getname_np(thread_id, name, THREAD_NAME_BUFFER_SIZE)) {
# elif AWS_PTHREAD_GETNAME_TAKES_2ARGS
if (pthread_getname_np(thread_id, name)) {
# elif AWS_PTHREAD_GET_NAME_TAKES_2ARGS
if (pthread_get_name_np(thread_id, name)) {
# endif
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
}
*out_name = aws_string_new_from_c_str(allocator, name);
return AWS_OP_SUCCESS;
#else
return aws_raise_error(AWS_ERROR_PLATFORM_NOT_SUPPORTED);
#endif
}

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The build must check for pthread_getname_np and fall back to AWS_ERROR_PLATFORM_NOT_SUPPORTED, but not fail to compile.

Current Behavior

thread.c:512:9: error: implicit declaration of function 'pthread_getname_np'

Reproduction Steps

Run the build on a system without pthread_getname_np.

Possible Solution

Add a check for the function in question.

Additional Information/Context

No response

aws-c-common version used

0.12.4

Compiler and version used

gcc 14.2.0

Operating System and version

macOS 10.5.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions