2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
14 #include <sys/types.h>
22 extern "C" int game_main(const char *szCmdLine);
25 #if defined(PLAT_UNIX) && !defined(__EMSCRIPTEN__)
26 static void daemonize()
32 } else if (pid != 0) {
40 signal(SIGHUP, SIG_IGN);
46 } else if (pid != 0) {
50 if (chdir("/") == -1) {
60 open("/dev/null", O_RDONLY);
61 open("/dev/null", O_WRONLY);
62 open("/dev/null", O_RDWR);
68 int main(int argc, char *argv[])
75 #if defined(PLAT_UNIX) && !defined(__EMSCRIPTEN__)
76 // if we are standalone headless, daemonize
78 bool standalone = false;
80 for (i = 1; i < argc; i++) {
81 if ( !daemon && SDL_strstr(argv[i], "-daemon") ) {
86 if ( SDL_strstr(argv[i], "-standalone") ) {
90 if ( !SDL_strcmp(argv[i], "-b") ) {
96 if (standalone && daemon) {
100 // make sure we create files with user access only
101 umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
104 for (i = 1; i < argc; i++) {
105 len += strlen(argv[i]) + 1;
109 argptr = (char *)SDL_malloc(len+5);
111 if (argptr == NULL) {
112 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Ran out of memory in main()!", NULL);
116 memset(argptr, 0, len+5);
118 for (i = 1; i < argc; i++) {
119 SDL_strlcat(argptr, argv[i], len+5);
120 SDL_strlcat(argptr, " ", len+5);
125 retr = game_main(argptr);
126 } catch(const std::exception &e) {
127 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", e.what(), NULL);
129 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Exception caught in main()!", NULL);