Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 3bf404c

Browse files
committed
sigqueue/pthread_sigqueue: cleanup.
Remove the explicit memset() from one of the two callers, and use explicit initialization for both. This makes it clearer that optimizing the zeroing of the rest of the struct is the compiler's problem, not ours. Add the "missing" assignment to si_signo in pthread_sigqueue() that isn't actually necessary because the kernel will overwrite that field anyway when it copies from userspace, but which looked like a bug given the difference between the sigqueue() and pthread_sigqueue() implementations. Also reuse the result of getpid() in pthread_sigqueue() rather than calling it twice. Change-Id: I39578d80ddc5edcb7d235b078392e20f35713dba
1 parent e1c232d commit 3bf404c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

libc/bionic/pthread_sigqueue.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ __BIONIC_WEAK_FOR_NATIVE_BRIDGE
4040
int pthread_sigqueue(pthread_t t, int sig, const union sigval value) {
4141
ErrnoRestorer errno_restorer;
4242

43+
pid_t pid = getpid();
44+
4345
pid_t tid = __pthread_internal_gettid(t, "pthread_sigqueue");
4446
if (tid == -1) return ESRCH;
4547

46-
siginfo_t siginfo;
47-
siginfo.si_code = SI_QUEUE;
48-
siginfo.si_pid = getpid();
48+
siginfo_t siginfo = { .si_code = SI_QUEUE };
49+
siginfo.si_signo = sig;
50+
siginfo.si_pid = pid;
4951
siginfo.si_uid = getuid();
5052
siginfo.si_value = value;
5153

52-
return syscall(__NR_rt_tgsigqueueinfo, getpid(), tid, sig, &siginfo) ? errno : 0;
54+
return syscall(__NR_rt_tgsigqueueinfo, pid, tid, sig, &siginfo) ? errno : 0;
5355
}

libc/bionic/signal.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,8 @@ int sigpending64(sigset64_t* set) {
219219
}
220220

221221
int sigqueue(pid_t pid, int sig, const sigval value) {
222-
siginfo_t info;
223-
memset(&info, 0, sizeof(siginfo_t));
222+
siginfo_t info = { .si_code = SI_QUEUE };
224223
info.si_signo = sig;
225-
info.si_code = SI_QUEUE;
226224
info.si_pid = getpid();
227225
info.si_uid = getuid();
228226
info.si_value = value;

0 commit comments

Comments
 (0)