Browse Source

Enter endless loop on I/O errors

Christoph Stelz 3 months ago
parent
commit
bb1f51ff64
1 changed files with 15 additions and 13 deletions
  1. 15 13
      src/ipc_debug.cpp

+ 15 - 13
src/ipc_debug.cpp

@@ -72,6 +72,14 @@ void debug_ipc_init() {
 
 }
 
+void endless_loop() {
+    printf("Entering endless loop, attach debugger to PID %i \n", getpid());
+    fflush(stdout);
+    while (1) {
+        sleep(1);
+    }
+}
+
 template<typename T>
 void debug_ipc_assert_equal(T value) {
     if (debug_ipc_file == nullptr) {
@@ -107,7 +115,7 @@ void debug_ipc_assert_equal(T value) {
 
         if (written != 1) {
             printf("[IPCDBG] Could not write enough bytes. Error: %s\n", strerror(errno));
-            exit(-1);
+            endless_loop();
         }
     }
 }
@@ -127,7 +135,7 @@ void debug_ipc_assert_equal_vector(std::vector<T> value) {
 
         if (read != array_byte_length) {
             printf("[IPCDBG] Could not read enough bytes. Error: %s\n", strerror(errno));
-            exit(-1);
+            endless_loop();
         }
 
         assert(reinterpret_cast<uint64_t>(buffer.data()) % 8 == 0); // Make sure the array is properly aligned
@@ -139,13 +147,10 @@ void debug_ipc_assert_equal_vector(std::vector<T> value) {
                 std::cout << "[IPCDBG] Assertion failed in vector  at index " << i 
                     << ". Root has " << local_array[i] << " but client has " << other_array[i] << std::endl;
                 print_backtrace();
-                printf("Entering endless loop, attach debugger to PID %i \n", getpid());
-                fflush(stdout);
-                while (1) {
-                    sleep(1);
-                }
+                endless_loop();
             }
         }
+
     } else {
         fwrite(value.data(), 1, array_byte_length, debug_ipc_file);
     }
@@ -191,17 +196,14 @@ void debug_ipc_assert_equal_array(void *value, size_t size) {
 
         if (read != size) {
             printf("[IPCDBG] Could not read enough bytes. Error: %s\n", strerror(errno));
-            exit(-1);
+            endless_loop();
         }
 
         for (size_t i = 0; i < size; i++) {
             if (array[i] != other_array[i]) {
                 printf("[IPCDBG] Assertion failed in byte %lu!\n", i);
                 print_backtrace();
-                printf("Entering endless loop, attach debugger to PID %i \n", getpid());
-                while (1) {
-                    sleep(1);
-                }
+                endless_loop();
             }
         }
     } else {
@@ -209,7 +211,7 @@ void debug_ipc_assert_equal_array(void *value, size_t size) {
 
         if (written != size) {
             printf("[IPCDBG] Could not write enough bytes. Error: %s\n", strerror(errno));
-            exit(-1);
+            endless_loop();
         }
     }
 }