- // Flag variables passed to getopt_long() later
- int do_version = 0, do_nofork = 0, do_debug = 0,
- do_nolog = 0, do_nopid = 0, do_root = 0;
- struct option longopts[] =
- {
- { "nofork", no_argument, &do_nofork, 1 },
- { "config", required_argument, NULL, 'c' },
- { "debug", no_argument, &do_debug, 1 },
- { "nolog", no_argument, &do_nolog, 1 },
- { "nopid", no_argument, &do_nopid, 1 },
- { "runasroot", no_argument, &do_root, 1 },
- { "version", no_argument, &do_version, 1 },
- { 0, 0, 0, 0 }
- };
-
- int c;
- int index;
- while ((c = getopt_long(argc, argv, ":c:", longopts, &index)) != -1)
- {
- switch (c)
- {
- case 'c':
- /* Config filename was set */
- ConfigFileName = optarg;
-#ifdef _WIN32
- TCHAR configPath[MAX_PATH + 1];
- if (GetFullPathName(optarg, MAX_PATH, configPath, NULL) > 0)
- ConfigFileName = configPath;
-#else
- char configPath[PATH_MAX + 1];
- if (realpath(optarg, configPath))
- ConfigFileName = configPath;
-#endif
- break;
- case 0:
- /* getopt_long_only() set an int variable, just keep going */
- break;
- case '?':
- /* Unknown parameter */
- default:
- /* Fall through to handle other weird values too */
- std::cout << "Unknown parameter '" << argv[optind-1] << "'" << std::endl;
- std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--nopid] [--debug] [--config <config>]" << std::endl <<
- std::string(static_cast<size_t>(8+strlen(argv[0])), ' ') << "[--runasroot] [--version]" << std::endl;
- Exit(EXIT_STATUS_ARGV);
- break;
- }
- }
-
- if (do_version)
- {
- std::cout << std::endl << INSPIRCD_VERSION << std::endl;
- Exit(EXIT_STATUS_NOERROR);
- }
-
- /* Set the finished argument values */
- Config->cmdline.nofork = (do_nofork != 0);
- Config->cmdline.forcedebug = (do_debug != 0);
- Config->cmdline.writelog = !do_nolog;
- Config->cmdline.writepid = !do_nopid;