debuggerd: set the name of the signal sender.

Bug: http://b/27925028
Change-Id: I6bff938e229d2368250d4b5c268fa24bd4badea0
(cherry picked from commit f3dde2f869)
This commit is contained in:
Josh Gao 2016-03-22 15:10:45 -07:00
parent 4b71388896
commit 70335deb59
1 changed files with 28 additions and 0 deletions

View File

@ -16,6 +16,7 @@
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/syscall.h>
@ -35,6 +36,31 @@ struct signal_message {
int signal;
};
static void set_signal_sender_process_name() {
#if defined(__LP64__)
static constexpr char long_process_name[] = "debuggerd64:signaller";
static constexpr char short_process_name[] = "debuggerd64:sig";
static_assert(sizeof(long_process_name) <= sizeof("/system/bin/debuggerd64"), "");
#else
static constexpr char long_process_name[] = "debuggerd:signaller";
static constexpr char short_process_name[] = "debuggerd:sig";
static_assert(sizeof(long_process_name) <= sizeof("/system/bin/debuggerd"), "");
#endif
// pthread_setname_np has a maximum length of 16 chars, including null terminator.
static_assert(sizeof(short_process_name) <= 16, "");
pthread_setname_np(pthread_self(), short_process_name);
char* progname = const_cast<char*>(getprogname());
if (strlen(progname) <= strlen(long_process_name)) {
ALOGE("debuggerd: unexpected progname %s", progname);
return;
}
memset(progname, 0, strlen(progname));
strcpy(progname, long_process_name);
}
// Fork a process to send signals for the worker processes to use after they've dropped privileges.
bool start_signal_sender() {
if (signal_pid != 0) {
@ -56,6 +82,8 @@ bool start_signal_sender() {
} else if (fork_pid == 0) {
close(sfd[1]);
set_signal_sender_process_name();
while (true) {
signal_message msg;
int rc = TEMP_FAILURE_RETRY(read(sfd[0], &msg, sizeof(msg)));