Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d0a87bd authored by Josh Gao's avatar Josh Gao Committed by Gerrit Code Review
Browse files

Merge "debuggerd: set the name of the signal sender."

parents b2cb35ef f3dde2f8
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -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)));