Repository: envoyproxy/envoy
File: source/server/hot_restart_impl.cc (C++)

Code before:
// performed the multiplication in OptionsImpl which produced incorrect server info output.
// TODO(zuercher): ideally, the base_id would be separated from the restart_epoch in
// the socket names to entirely prevent collisions between consecutive base ids.
HotRestartImpl::HotRestartImpl(uint32_t base_id, uint32_t restart_epoch,
                               const std::string& socket_path, mode_t socket_mode,
                               bool skip_hot_restart_on_no_parent, bool skip_parent_stats)
    : base_id_(base_id), scaled_base_id_(base_id * 10),
      as_child_(HotRestartingChild(scaled_base_id_, restart_epoch, socket_path, socket_mode,
                                   skip_hot_restart_on_no_parent, skip_parent_stats)),
      as_parent_(HotRestartingParent(scaled_base_id_, restart_epoch, socket_path, socket_mode)),
      shmem_(attachSharedMemory(scaled_base_id_, restart_epoch)), log_lock_(shmem_->log_lock_),
      access_log_lock_(shmem_->access_log_lock_) {
  // If our parent ever goes away just terminate us so that we don't have to rely on ops/launching
  // logic killing the entire process tree. We should never exist without our parent.
  int rc = prctl(PR_SET_PDEATHSIG, SIGTERM);
  RELEASE_ASSERT(rc != -1, "");
}

void HotRestartImpl::drainParentListeners() {
  as_child_.drainParentListeners();
  // At this point we are initialized and a new Envoy can startup if needed.
  shmem_->flags_ &= ~SHMEM_FLAGS_INITIALIZING;
}

int HotRestartImpl::duplicateParentListenSocket(const std::string& address, uint32_t worker_index,
                                                const std::string& network_namespace) {
  return as_child_.duplicateParentListenSocket(address, worker_index, network_namespace);
}

void HotRestartImpl::registerUdpForwardingListener(
    Network::Address::InstanceConstSharedPtr address,
    std::shared_ptr<Network::UdpListenerConfig> listener_config) {
  as_child_.registerUdpForwardingListener(address, listener_config);
}

OptRef<Network::ParentDrainedCallbackRegistrar> HotRestartImpl::parentDrainedCallbackRegistrar() {
  return as_child_;
}

void HotRestartImpl::initialize(Event::Dispatcher& dispatcher, Server::Instance& server) {
  as_parent_.initialize(dispatcher, server);
  as_child_.initialize(dispatcher);
}

absl::optional<HotRestart::AdminShutdownResponse> HotRestartImpl::sendParentAdminShutdownRequest() {
  return as_child_.sendParentAdminShutdownRequest();
}

void HotRestartImpl::sendParentTerminateRequest() { as_child_.sendParentTerminateRequest(); }

HotRestart::ServerStatsFromParent

Review comment (suggestion):
```suggestion
                                                absl::string_view network_namespace) {
```

Code after:
// performed the multiplication in OptionsImpl which produced incorrect server info output.
// TODO(zuercher): ideally, the base_id would be separated from the restart_epoch in
// the socket names to entirely prevent collisions between consecutive base ids.
HotRestartImpl::HotRestartImpl(uint32_t base_id, uint32_t restart_epoch,
                               const std::string& socket_path, mode_t socket_mode,
                               bool skip_hot_restart_on_no_parent, bool skip_parent_stats)
    : base_id_(base_id), scaled_base_id_(base_id * 10),
      as_child_(HotRestartingChild(scaled_base_id_, restart_epoch, socket_path, socket_mode,
                                   skip_hot_restart_on_no_parent, skip_parent_stats)),
      as_parent_(HotRestartingParent(scaled_base_id_, restart_epoch, socket_path, socket_mode)),
      shmem_(attachSharedMemory(scaled_base_id_, restart_epoch)), log_lock_(shmem_->log_lock_),
      access_log_lock_(shmem_->access_log_lock_) {
  // If our parent ever goes away just terminate us so that we don't have to rely on ops/launching
  // logic killing the entire process tree. We should never exist without our parent.
  int rc = prctl(PR_SET_PDEATHSIG, SIGTERM);
  RELEASE_ASSERT(rc != -1, "");
}

void HotRestartImpl::drainParentListeners() {
  as_child_.drainParentListeners();
  // At this point we are initialized and a new Envoy can startup if needed.
  shmem_->flags_ &= ~SHMEM_FLAGS_INITIALIZING;
}

int HotRestartImpl::duplicateParentListenSocket(const std::string& address, uint32_t worker_index,
                                                absl::string_view network_namespace) {
  return as_child_.duplicateParentListenSocket(address, worker_index, network_namespace);
}

void HotRestartImpl::registerUdpForwardingListener(
    Network::Address::InstanceConstSharedPtr address,
    std::shared_ptr<Network::UdpListenerConfig> listener_config) {
  as_child_.registerUdpForwardingListener(address, listener_config);
}

OptRef<Network::ParentDrainedCallbackRegistrar> HotRestartImpl::parentDrainedCallbackRegistrar() {
  return as_child_;
}

void HotRestartImpl::initialize(Event::Dispatcher& dispatcher, Server::Instance& server) {
  as_parent_.initialize(dispatcher, server);
  as_child_.initialize(dispatcher);
}

absl::optional<HotRestart::AdminShutdownResponse> HotRestartImpl::sendParentAdminShutdownRequest() {
  return as_child_.sendParentAdminShutdownRequest();
}

void HotRestartImpl::sendParentTerminateRequest() { as_child_.sendParentTerminateRequest(); }

HotRestart::ServerStatsFromParent