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
12 #include <sys/types.h>
20 extern int game_main(const char *szCmdLine);
24 static void daemonize()
30 } else if (pid != 0) {
38 signal(SIGHUP, SIG_IGN);
44 } else if (pid != 0) {
48 if (chdir("/") == -1) {
58 open("/dev/null", O_RDONLY);
59 open("/dev/null", O_WRONLY);
60 open("/dev/null", O_RDWR);
66 int main(int argc, char *argv[])
74 // if we are standalone headless, daemonize
76 bool standalone = false;
78 for (i = 1; i < argc; i++) {
79 if ( !daemon && SDL_strstr(argv[i], "-daemon") ) {
84 if ( SDL_strstr(argv[i], "-standalone") ) {
88 if ( !SDL_strcmp(argv[i], "-b") ) {
94 if (standalone && daemon) {
98 // make sure we create files with user access only
99 umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
102 for (i = 1; i < argc; i++) {
103 len += strlen(argv[i]) + 1;
107 argptr = (char *)SDL_malloc(len+5);
109 if (argptr == NULL) {
110 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Ran out of memory in main()!", NULL);
114 memset(argptr, 0, len+5);
116 for (i = 1; i < argc; i++) {
117 SDL_strlcat(argptr, argv[i], len+5);
118 SDL_strlcat(argptr, " ", len+5);
123 retr = game_main(argptr);
125 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Exception caught in main()!", NULL);