@@ -374,18 +374,22 @@ static void pop_settings(void)
write_settings(current_settings());
}
-static void restore_settings(int sig)
+static void restore_settings_atexit(void)
{
if (skip_settings_restore)
- goto out;
+ return;
printf("Restore THP and khugepaged settings...");
write_settings(&saved_settings);
success("OK");
- if (sig)
- exit(EXIT_FAILURE);
-out:
- exit(exit_status);
+
+ skip_settings_restore = true;
+}
+
+static void restore_settings(int sig)
+{
+ /* exit() will invoke the restore_settings_atexit handler. */
+ exit(sig ? EXIT_FAILURE : exit_status);
}
static void save_settings(void)
@@ -415,6 +419,7 @@ static void save_settings(void)
success("OK");
+ atexit(restore_settings_atexit);
signal(SIGTERM, restore_settings);
signal(SIGINT, restore_settings);
signal(SIGHUP, restore_settings);