Skip to content

Commit cc2844f

Browse files
authored
Fix thread name length in exit tests' call to pthread_setname_np(). (#367)
On Linux, the maximum length of a thread's name is defined by `TASK_COMM_LEN` to be 16 bytes (including the trailing null character.) We currently manually create one thread on Linux in order to monitor for termination of exit tests' child processes. This PR changes the name of the monitor thread on Linux to one that is less than 16 characters long. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 379a1b2 commit cc2844f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Sources/Testing/ExitTests/WaitFor.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ private let _createWaitThreadImpl: Void = {
8585
}
8686
}
8787

88-
// Create the thread. We immediately detach it upon success to allow the
89-
// system to reclaim its resources when done.
88+
// Create the thread. It will run immediately; because it runs in an infinite
89+
// loop, we aren't worried about detaching or joining it.
9090
#if SWT_TARGET_OS_APPLE
9191
var thread: pthread_t?
9292
#else
@@ -96,12 +96,13 @@ private let _createWaitThreadImpl: Void = {
9696
&thread,
9797
nil,
9898
{ _ in
99-
// Set the thread name to help with diagnostics.
100-
let threadName = "swift-testing exit test monitor"
99+
// Set the thread name to help with diagnostics. Note that different
100+
// platforms support different thread name lengths. See MAXTHREADNAMESIZE
101+
// on Darwin and TASK_COMM_LEN on Linux.
101102
#if SWT_TARGET_OS_APPLE
102-
_ = pthread_setname_np(threadName)
103+
_ = pthread_setname_np("swift-testing exit test monitor")
103104
#else
104-
_ = pthread_setname_np(pthread_self(), threadName)
105+
_ = pthread_setname_np(pthread_self(), "SWT ExT monitor")
105106
#endif
106107

107108
// Run an infinite loop that waits for child processes to terminate and

0 commit comments

Comments
 (0)