Skip to content

QNX: spawning a thread with a long name panics when libstd's debug assertions are enabled #114966

@japaric

Description

@japaric

I tried this code:

 let name = "a".repeat(1024); thread::Builder::new() .name(name) .spawn(|| { println!("it works!"); }) .unwrap() .join() .unwrap();

I expected to see this happen: "it works" is printed

Instead, this happened: the program panicked due to this debug assertion

#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto"))]
pub fn set_name(name: &CStr) {
weak! {
fn pthread_setname_np(
libc::pthread_t, *const libc::c_char
) -> libc::c_int
}
if let Some(f) = pthread_setname_np.get() {
let res = unsafe { f(libc::pthread_self(), name.as_ptr()) };
debug_assert_eq!(res, 0);
}
}

According to the QNX documentation the maximum length a thread name can have is _NTO_THREAD_NAME_MAX. The NTO implementation of this function should truncate the thread name like, for example, the Linux implementation does. I'll submit a fix.

Meta

I used the x86_64-pc-nto-qnx710 compilation target.

rustc --version --verbose:

rustc 1.73.0-nightly (180dffba1 2023-08-14) binary: rustc commit-hash: 180dffba142c47240ca0d93096ce90b9fd97c8d7 commit-date: 2023-08-14 host: x86_64-unknown-linux-gnu release: 1.73.0-nightly LLVM version: 17.0.0 

Not including a backtrace because all the reported functions in the backtrace were <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-neutrinoOS: QNX Neutrino, a POSIX-compatible real-time operating systemT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions