comparison util/startup.lua @ 13464:2dbc169aae6a

util.startup: Abort before initialization of logging when started as root Prevents creation of log files owned by the root user which could be inaccessible once started correctly.
author Kim Alvefur <zash@zash.se>
date Sun, 24 Mar 2024 21:32:00 +0100
parents 3ce550ce44ce
children c2a476f4712a
comparison
equal deleted inserted replaced
13463:3ce550ce44ce 13464:2dbc169aae6a
690 function startup.check_user() 690 function startup.check_user()
691 local pposix = check_posix(); 691 local pposix = check_posix();
692 if not pposix then return end 692 if not pposix then return end
693 -- Don't even think about it! 693 -- Don't even think about it!
694 if pposix.getuid() == 0 and not config.get("*", "run_as_root") then 694 if pposix.getuid() == 0 and not config.get("*", "run_as_root") then
695 log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); 695 print("Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!");
696 log("error", "For more information on running Prosody as root, see https://prosody.im/doc/root"); 696 print("For more information on running Prosody as root, see https://prosody.im/doc/root");
697 os.exit(1); -- Refusing to run as root 697 os.exit(1); -- Refusing to run as root
698 end 698 end
699 end 699 end
700 700
701 local function remove_pidfile() 701 local function remove_pidfile()
862 -- previous steps to have already been performed 862 -- previous steps to have already been performed
863 prosody.process_type = "prosody"; 863 prosody.process_type = "prosody";
864 startup.parse_args(); 864 startup.parse_args();
865 startup.init_global_state(); 865 startup.init_global_state();
866 startup.read_config(); 866 startup.read_config();
867 startup.check_user();
867 startup.init_logging(); 868 startup.init_logging();
868 startup.check_user();
869 startup.init_gc(); 869 startup.init_gc();
870 startup.init_errors(); 870 startup.init_errors();
871 startup.sanity_check(); 871 startup.sanity_check();
872 startup.sandbox_require(); 872 startup.sandbox_require();
873 startup.set_function_metatable(); 873 startup.set_function_metatable();