Not recoverable lock exception reproducer. This reliably allows the CLI to reliably put the shared memory segment lock into a bad state.
example output usage to reproduce:
fiterman@fiterman-dev:/google/src/cloud/fiterman/tlbmc_dev/google3$ blaze-bin/third_party/milotic/external/cc/tlbmc/hal/shared_mem/demo/shared_mem_cli -command get_metrics
.....
fiterman@fiterman-dev:/google/src/cloud/fiterman/tlbmc_dev/google3$ blaze-bin/third_party/milotic/external/cc/tlbmc/hal/shared_mem/demo/shared_mem_cli -command crash_test
Crashing the process under lock
Killed
fiterman@fiterman-dev:/google/src/cloud/fiterman/tlbmc_dev/google3$ blaze-bin/third_party/milotic/external/cc/tlbmc/hal/shared_mem/demo/shared_mem_cli -command get_metrics
WARNING: Logging before InitGoogle() is written to STDERR
E0000 00:00:1760066642.216733 1199762 segment_manager.cc:63] Not recoverable lock exception happened: boost::interprocess::lock_exception. Will remove the init file and shared memory, then create a new one.
W0000 00:00:1760066642.216888 1199762 segment_manager.cc:106] Creating shared memory; this should only happen once per boot.
W0000 00:00:1760066642.217411 1199762 segment_manager.cc:122] Created shared memory object; created file at : /run/tlbmc/shm_initialized
Metrics pointer is 0x7f4c932ce118
Metrics is {
....
PiperOrigin-RevId: 817811283
Change-Id: I0ec1d6ddc7a5f1d37dfb90a75c83d656e3ee40cb
diff --git a/tlbmc/hal/shared_mem/demo/shared_mem_cli.cc b/tlbmc/hal/shared_mem/demo/shared_mem_cli.cc
index 40c75de..889ca56 100644
--- a/tlbmc/hal/shared_mem/demo/shared_mem_cli.cc
+++ b/tlbmc/hal/shared_mem/demo/shared_mem_cli.cc
@@ -1,4 +1,4 @@
-#include <cstdint>
+#include <csignal> // NOLINT
#include <filesystem> // NOLINT
#include <iostream>
#include <string>
@@ -11,9 +11,10 @@
#include "tlbmc/hal/shared_mem/segment_manager.h"
#include "tlbmc/hal/shared_mem/server.h"
-ABSL_FLAG(std::string, command, "",
- "Command to execute: 'get_metrics', 'check_segment', "
- "'remove_segment', 'get_metrics_debug', 'get_sensor_value'");
+ABSL_FLAG(
+ std::string, command, "",
+ "Command to execute: 'get_metrics', 'check_segment', "
+ "'remove_segment', 'get_metrics_debug', 'get_sensor_value', 'crash_test'");
ABSL_FLAG(bool, unit_test, false, "Use shared memory for unit test.");
ABSL_FLAG(std::string, sensor_name, "", "The name of the sensor to read.");
@@ -47,6 +48,18 @@
return 0;
}
+ if (command == "crash_test") {
+ boost::interprocess::managed_shared_memory sensors_memory(
+ boost::interprocess::open_only, "TlbmcSharedMemory");
+
+ auto crash_fn = [] {
+ std::cerr << "Crashing the process under lock\n";
+ pid_t current_pid = getpid();
+ kill(current_pid, SIGKILL);
+ };
+ sensors_memory.atomic_func(crash_fn);
+ }
+
if (command == "check_segment") {
bool file_exists = false;
if (!unit_test) {