Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use *const pointer for NetBSD's pthread_setname_np #1608

Merged
merged 1 commit into from Nov 29, 2019

Conversation

tesuji
Copy link
Contributor

@tesuji tesuji commented Nov 28, 2019

No description provided.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @gnzlbg (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@gnzlbg
Copy link
Contributor

gnzlbg commented Nov 28, 2019

@lzutao did you run the libc-test suite on NetBSD ?

@tesuji
Copy link
Contributor Author

tesuji commented Nov 28, 2019

@gnzlbg I didn't because I don't have NetBSD machines.
On NetBSD the second argument is a printf-like string, which can refer to the value provided by the third argument.
Here is how pthread_setname_np implemented in NetBSD: https://github.com/NetBSD/src/blob/465ec24dbfce4dd9b06234d657a05da1d9777865/lib/libpthread/pthread.c#L825

int
pthread_setname_np(pthread_t thread, const char *name, void *arg)
{
	char *oldname, *cp, newname[PTHREAD_MAX_NAMELEN_NP];
	int namelen;

	if (pthread__find(thread) != 0)
		return ESRCH;

	if (thread->pt_magic != PT_MAGIC)
		return EINVAL;

	namelen = snprintf(newname, sizeof(newname), name, arg);
	if (namelen >= PTHREAD_MAX_NAMELEN_NP)
		return EINVAL;

	cp = strdup(newname);
	if (cp == NULL)
		return ENOMEM;

	pthread_mutex_lock(&thread->pt_lock);
	oldname = thread->pt_name;
	thread->pt_name = cp;
	(void)_lwp_setname(thread->pt_lid, cp);
	pthread_mutex_unlock(&thread->pt_lock);

	if (oldname != NULL)
		free(oldname);

	return 0;
}

@gnzlbg
Copy link
Contributor

gnzlbg commented Nov 28, 2019

Thanks @lzutao , that checks out. I'm generally a bit more wary of API breaking changes like this, but for NetBSD we only guarantee that libc "builds".

@bors: r+

@bors
Copy link
Contributor

bors commented Nov 28, 2019

📌 Commit f851312 has been approved by gnzlbg

@bors
Copy link
Contributor

bors commented Nov 28, 2019

⌛ Testing commit f851312 with merge f6455d1...

bors added a commit that referenced this pull request Nov 28, 2019
use *const pointer for NetBSD's pthread_setname_np
@bors
Copy link
Contributor

bors commented Nov 28, 2019

💔 Test failed - status-azure

@gnzlbg
Copy link
Contributor

gnzlbg commented Nov 29, 2019

@bors: retry

@bors
Copy link
Contributor

bors commented Nov 29, 2019

⌛ Testing commit f851312 with merge ea0a54a...

bors added a commit that referenced this pull request Nov 29, 2019
use *const pointer for NetBSD's pthread_setname_np
@bors
Copy link
Contributor

bors commented Nov 29, 2019

☀️ Test successful - checks-cirrus-freebsd-10, checks-cirrus-freebsd-11, checks-cirrus-freebsd-12, status-azure
Approved by: gnzlbg
Pushing ea0a54a to master...

@bors bors merged commit f851312 into rust-lang:master Nov 29, 2019
@tesuji tesuji deleted the netbsd-mut-pthread_setname_np branch November 29, 2019 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants