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

Commit e955efdf authored by Hansong Zhang's avatar Hansong Zhang
Browse files

GD: Open a pid file when stack is running

So that some other manager process can detect it

Test: cert/run
Bug: 181590011
Tag: #refactor
Change-Id: I340b5d25b4374d47c8c769d80fcd287b23696202
parent 5f6bda0c
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#include "stack_manager.h"

#include <fcntl.h>
#include <unistd.h>
#include <chrono>
#include <future>
#include <queue>
@@ -32,6 +34,8 @@ using ::bluetooth::os::Thread;

namespace bluetooth {

constexpr char bluetooth_pid_file[] = "/var/run/bluetooth";

void StackManager::StartUp(ModuleList* modules, Thread* stack_thread) {
  management_thread_ = new Thread("management_thread", Thread::Priority::NORMAL);
  handler_ = new Handler(management_thread_);
@@ -47,6 +51,10 @@ void StackManager::StartUp(ModuleList* modules, Thread* stack_thread) {
      "Can't start stack, last instance: %s",
      registry_.last_instance_.c_str());

  pid_fd_ = open(bluetooth_pid_file, O_WRONLY | O_CREAT, 0644);
  pid_t my_pid = getpid();
  write(pid_fd_, &my_pid, sizeof(pid_t));

  LOG_INFO("init complete");
}

@@ -70,6 +78,9 @@ void StackManager::ShutDown() {
  handler_->WaitUntilStopped(std::chrono::milliseconds(2000));
  delete handler_;
  delete management_thread_;

  unlink(bluetooth_pid_file);
  close(pid_fd_);
}

void StackManager::handle_shut_down(std::promise<void> promise) {
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ class StackManager {
  os::Thread* management_thread_ = nullptr;
  os::Handler* handler_ = nullptr;
  ModuleRegistry registry_;
  int pid_fd_ = 0;

  void handle_start_up(ModuleList* modules, os::Thread* stack_thread, std::promise<void> promise);
  void handle_shut_down(std::promise<void> promise);