- /* We didn't start from a TTY, we must have started from a background process -
- * e.g. we are restarting, or being launched by cron. Dont kill parent, and dont
- * close stdin/stdout
- */
- if ((!do_nofork) && (!do_testsuite))
+ int fd = open("/dev/null", O_RDWR);
+
+ fclose(stdin);
+ fclose(stderr);
+ fclose(stdout);
+
+ if (dup2(fd, STDIN_FILENO) < 0)
+ Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stdin.");
+ if (dup2(fd, STDOUT_FILENO) < 0)
+ Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stdout.");
+ if (dup2(fd, STDERR_FILENO) < 0)
+ Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stderr.");
+ close(fd);
+ }
+ else
+ {
+ Logs->Log("STARTUP", DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
+ }
+#else
+ /* Set win32 service as running, if we are running as a service */
+ SetServiceRunning();
+
+ // Handle forking
+ if(!do_nofork)
+ {
+ FreeConsole();
+ }
+
+ QueryPerformanceFrequency(&stats->QPFrequency);
+#endif
+
+ Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
+
+#ifndef _WIN32
+ std::string SetUser = Config->ConfValue("security")->getString("runasuser");
+ std::string SetGroup = Config->ConfValue("security")->getString("runasgroup");
+ if (!SetGroup.empty())
+ {
+ int ret;
+
+ // setgroups
+ ret = setgroups(0, NULL);
+
+ if (ret == -1)