Print a warning when the engine is started as `root`/superuser

This is a security risk (especially when hosting a game server)
and can make audio non-functional on Linux.

(cherry picked from commit 9c34db6cb4)
This commit is contained in:
Hugo Locurcio 2021-07-31 16:23:26 +02:00 committed by Rémi Verschelde
parent f807c7e569
commit 21a68d1c44
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 7 additions and 0 deletions

View File

@ -1287,6 +1287,13 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
}
#endif
#ifdef UNIX_ENABLED
// Print warning before initializing audio.
if (OS::get_singleton()->get_environment("USER") == "root" && !OS::get_singleton()->has_environment("GODOT_SILENCE_ROOT_WARNING")) {
WARN_PRINT("Started the engine as `root`/superuser. This is a security risk, and subsystems like audio may not work correctly.\nSet the environment variable `GODOT_SILENCE_ROOT_WARNING` to 1 to silence this warning.");
}
#endif
Error err = OS::get_singleton()->initialize(video_mode, video_driver_idx, audio_driver_idx);
if (err != OK) {
return err;