-LOCAL VOID
-Show_Help( VOID )
-{
-#ifdef DEBUG
- puts( " -d, --debug log extra debug messages" );
-#endif
- puts( " -f, --config <f> use file <f> as configuration file" );
- puts( " -n, --nodaemon don't fork and don't detach from controlling terminal" );
- puts( " -p, --passive disable automatic connections to other servers" );
-#ifdef SNIFFER
- puts( " -s, --sniffer enable network sniffer and display all IRC traffic" );
+ if (chroot(Conf_Chroot) != 0) {
+ if (errno != EPERM) {
+ Log(LOG_ERR,
+ "Can't change root directory to \"%s\": %s",
+ Conf_Chroot, strerror(errno));
+ goto out;
+ }
+ } else {
+ chrooted = true;
+ Log(LOG_INFO,
+ "Changed root and working directory to \"%s\".",
+ Conf_Chroot);
+ }
+ }
+
+ /* Check user ID */
+ if (Conf_UID == 0) {
+ pwd = getpwuid(0);
+ Log(LOG_INFO,
+ "ServerUID must not be %s(0), using \"nobody\" instead.",
+ pwd ? pwd->pw_name : "?");
+ if (!NGIRCd_getNobodyID(&Conf_UID, &Conf_GID)) {
+ Log(LOG_WARNING,
+ "Could not get user/group ID of user \"nobody\": %s",
+ errno ? strerror(errno) : "not found" );
+ goto out;
+ }
+ }
+
+ /* Change group ID */
+ if (getgid() != Conf_GID) {
+ if (setgid(Conf_GID) != 0) {
+ real_errno = errno;
+ grp = getgrgid(Conf_GID);
+ Log(LOG_ERR, "Can't change group ID to %s(%u): %s",
+ grp ? grp->gr_name : "?", Conf_GID,
+ strerror(errno));
+ if (real_errno != EPERM)
+ goto out;
+ }
+ }
+
+ /* Change user ID */
+ if (getuid() != Conf_UID) {
+ if (setuid(Conf_UID) != 0) {
+ real_errno = errno;
+ pwd = getpwuid(Conf_UID);
+ Log(LOG_ERR, "Can't change user ID to %s(%u): %s",
+ pwd ? pwd->pw_name : "?", Conf_UID,
+ strerror(errno));
+ if (real_errno != EPERM)
+ goto out;
+ }
+ }
+
+ initialized = true;
+
+ /* Normally a child process is forked which isn't any longer
+ * connected to ther controlling terminal. Use "--nodaemon"
+ * to disable this "daemon mode" (useful for debugging). */
+ if (!NGIRCd_NoDaemon) {
+ pid = fork();
+ if (pid > 0) {
+ /* "Old" process: exit. */
+ exit(0);
+ }
+ if (pid < 0) {
+ /* Error!? */
+ fprintf(stderr,
+ "%s: Can't fork: %s!\nFatal error, exiting now ...\n",
+ PACKAGE_NAME, strerror(errno));
+ exit(1);
+ }
+
+ /* New child process */
+#ifndef NeXT
+ (void)setsid();
+#else
+ setpgrp(0, getpid());