Merge "debuggerd: set the name of the signal sender."
This commit is contained in:
commit
3d0a87bd5b
1 changed files with 28 additions and 0 deletions
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
|
@ -35,6 +36,31 @@ struct signal_message {
|
||||||
int signal;
|
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.
|
// Fork a process to send signals for the worker processes to use after they've dropped privileges.
|
||||||
bool start_signal_sender() {
|
bool start_signal_sender() {
|
||||||
if (signal_pid != 0) {
|
if (signal_pid != 0) {
|
||||||
|
|
@ -56,6 +82,8 @@ bool start_signal_sender() {
|
||||||
} else if (fork_pid == 0) {
|
} else if (fork_pid == 0) {
|
||||||
close(sfd[1]);
|
close(sfd[1]);
|
||||||
|
|
||||||
|
set_signal_sender_process_name();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
signal_message msg;
|
signal_message msg;
|
||||||
int rc = TEMP_FAILURE_RETRY(read(sfd[0], &msg, sizeof(msg)));
|
int rc = TEMP_FAILURE_RETRY(read(sfd[0], &msg, sizeof(msg)));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue