* Entry point for the Icinga application. * * @params argc Number of command line arguments. * @params argv Command line arguments. * @returns The application's exit status. */
| 921 | * @returns The application's exit status. |
| 922 | */ |
| 923 | int main(int argc, char **argv) |
| 924 | { |
| 925 | #ifndef _WIN32 |
| 926 | String keepFDs = Utility::GetFromEnvironment("ICINGA2_KEEP_FDS"); |
| 927 | if (keepFDs.IsEmpty()) { |
| 928 | #ifdef I2_DEBUG |
| 929 | Utility::CloseAllFDs({0, 1, 2}, [](int fd) { |
| 930 | std::cerr << "Closed FD " << fd << " which we inherited from our parent process." << std::endl; |
| 931 | }); |
| 932 | #else /* I2_DEBUG */ |
| 933 | Utility::CloseAllFDs({0, 1, 2}); |
| 934 | #endif /* I2_DEBUG */ |
| 935 | } |
| 936 | #endif /* _WIN32 */ |
| 937 | |
| 938 | /* must be called before using any other libbase functions */ |
| 939 | Application::InitializeBase(); |
| 940 | |
| 941 | /* Set command-line arguments. */ |
| 942 | Application::SetArgC(argc); |
| 943 | Application::SetArgV(argv); |
| 944 | |
| 945 | #ifdef _WIN32 |
| 946 | if (argc > 1 && strcmp(argv[1], "--scm-install") == 0) { |
| 947 | return SetupService(true, argc - 2, &argv[2]); |
| 948 | } |
| 949 | |
| 950 | if (argc > 1 && strcmp(argv[1], "--scm-uninstall") == 0) { |
| 951 | return SetupService(false, argc - 2, &argv[2]); |
| 952 | } |
| 953 | |
| 954 | if (argc > 1 && strcmp(argv[1], "--scm") == 0) { |
| 955 | SERVICE_TABLE_ENTRY dispatchTable[] = { |
| 956 | { "icinga2", ServiceMain }, |
| 957 | { nullptr, nullptr } |
| 958 | }; |
| 959 | |
| 960 | StartServiceCtrlDispatcher(dispatchTable); |
| 961 | Application::Exit(EXIT_FAILURE); |
| 962 | } |
| 963 | #endif /* _WIN32 */ |
| 964 | |
| 965 | int rc = Main(); |
| 966 | |
| 967 | Application::Exit(rc); |
| 968 | } |
nothing calls this directly
no test coverage detected