1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Make changes requested by sfan5

* Use `auto` for temporary locals instead of `std::sig_atomic_t`
* Use stderr instead of stdout for logging messages.
* Remove old commented out code.
* Do not write null byte when logging.
This commit is contained in:
Josiah VanderZee 2025-05-19 14:32:59 -05:00
parent 5791f5ff8b
commit 053ff1bc23
No known key found for this signature in database
GPG key ID: C7BB8573A4ABC4B9
3 changed files with 12 additions and 21 deletions

View file

@ -22,7 +22,6 @@
#include "util/tracy_wrapper.h" #include "util/tracy_wrapper.h"
#include <IGUISpriteBank.h> #include <IGUISpriteBank.h>
#include <ICameraSceneNode.h> #include <ICameraSceneNode.h>
#include <csignal>
#include <unordered_map> #include <unordered_map>
#if USE_SOUND #if USE_SOUND
@ -148,8 +147,8 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
/* /*
Menu-game loop Menu-game loop
*/ */
bool retval = true; bool retval = true;
volatile std::sig_atomic_t *kill = porting::signal_handler_killstatus(); volatile auto *kill = porting::signal_handler_killstatus();
while (m_rendering_engine->run() && !*kill && while (m_rendering_engine->run() && !*kill &&
!g_gamecallback->shutdown_requested) { !g_gamecallback->shutdown_requested) {
@ -530,9 +529,9 @@ bool ClientLauncher::launch_game(std::string &error_message,
void ClientLauncher::main_menu(MainMenuData *menudata) void ClientLauncher::main_menu(MainMenuData *menudata)
{ {
volatile std::sig_atomic_t *kill = porting::signal_handler_killstatus(); volatile auto *kill = porting::signal_handler_killstatus();
video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); video::IVideoDriver *driver = m_rendering_engine->get_video_driver();
auto *device = m_rendering_engine->get_raw_device(); auto *device = m_rendering_engine->get_raw_device();
// Wait until app is in foreground because of #15883 // Wait until app is in foreground because of #15883
infostream << "Waiting for app to be in foreground" << std::endl; infostream << "Waiting for app to be in foreground" << std::endl;

View file

@ -46,8 +46,6 @@ extern "C" {
#endif #endif
} }
#include <csignal>
#if !defined(__cpp_rtti) || !defined(__cpp_exceptions) #if !defined(__cpp_rtti) || !defined(__cpp_exceptions)
#error Luanti cannot be built without exceptions or RTTI #error Luanti cannot be built without exceptions or RTTI
#endif #endif
@ -1140,7 +1138,7 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
return false; return false;
} }
ChatInterface iface; ChatInterface iface;
volatile std::sig_atomic_t &kill = *porting::signal_handler_killstatus(); volatile auto &kill = *porting::signal_handler_killstatus();
try { try {
// Create server // Create server
@ -1183,7 +1181,7 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
server.start(); server.start();
// Run server // Run server
volatile std::sig_atomic_t &kill = *porting::signal_handler_killstatus(); volatile auto &kill = *porting::signal_handler_killstatus();
dedicated_server_loop(server, kill); dedicated_server_loop(server, kill);
} catch (const ModError &e) { } catch (const ModError &e) {
@ -1228,7 +1226,7 @@ static bool migrate_map_database(const GameParams &game_params, const Settings &
u32 count = 0; u32 count = 0;
u64 last_update_time = 0; u64 last_update_time = 0;
volatile std::sig_atomic_t &kill = *porting::signal_handler_killstatus(); volatile auto &kill = *porting::signal_handler_killstatus();
std::vector<v3s16> blocks; std::vector<v3s16> blocks;
old_db->listAllLoadableBlocks(blocks); old_db->listAllLoadableBlocks(blocks);
@ -1282,7 +1280,7 @@ static bool recompress_map_database(const GameParams &game_params, const Setting
u32 count = 0; u32 count = 0;
u64 last_update_time = 0; u64 last_update_time = 0;
volatile std::sig_atomic_t &kill = *porting::signal_handler_killstatus(); volatile auto &kill = *porting::signal_handler_killstatus();
const u8 serialize_as_ver = SER_FMT_VER_HIGHEST_WRITE; const u8 serialize_as_ver = SER_FMT_VER_HIGHEST_WRITE;
const s16 map_compression_level = rangelim(g_settings->getS16("map_compression_level_disk"), -1, 9); const s16 map_compression_level = rangelim(g_settings->getS16("map_compression_level_disk"), -1, 9);

View file

@ -90,7 +90,7 @@ volatile std::sig_atomic_t *signal_handler_killstatus()
} }
#if !defined(_WIN32) // POSIX #if !defined(_WIN32) // POSIX
#define STDOUT 1 #define STDERR_FILENO 2
static void signal_handler(int sig) static void signal_handler(int sig)
{ {
@ -98,18 +98,12 @@ static void signal_handler(int sig)
if (sig == SIGINT) { if (sig == SIGINT) {
const char *dbg_text{"INFO: signal_handler(): " const char *dbg_text{"INFO: signal_handler(): "
"Ctrl-C pressed, shutting down.\n"}; "Ctrl-C pressed, shutting down.\n"};
write(STDOUT, dbg_text, strlen(dbg_text) + 1); write(STDERR_FILENO, dbg_text, strlen(dbg_text));
} else if (sig == SIGTERM) { } else if (sig == SIGTERM) {
const char *dbg_text{"INFO: signal_handler(): " const char *dbg_text{"INFO: signal_handler(): "
"got SIGTERM, shutting down.\n"}; "got SIGTERM, shutting down.\n"};
write(STDOUT, dbg_text, strlen(dbg_text) + 1); write(STDERR_FILENO, dbg_text, strlen(dbg_text));
} }
// Comment out for less clutter when testing scripts
/*dstream << "INFO: sigint_handler(): "
<< "Printing debug stacks" << std::endl;
debug_stacks_print();*/
g_killed = true; g_killed = true;
} else { } else {
(void)signal(sig, SIG_DFL); (void)signal(sig, SIG_DFL);