void test_remove_manager_unix_socket_on_create (void) { cut_assert_true(milter_manager_configuration_is_remove_manager_unix_socket_on_create(config)); milter_manager_configuration_set_remove_manager_unix_socket_on_create(config, FALSE); cut_assert_false(milter_manager_configuration_is_remove_manager_unix_socket_on_create(config)); }
static void milter_assert_default_configuration_helper (MilterManagerConfiguration *config) { cut_assert_false(milter_manager_configuration_is_privilege_mode(config)); cut_assert_equal_string( MILTER_MANAGER_DEFAULT_CONNECTION_SPEC, milter_manager_configuration_get_manager_connection_spec(config)); cut_assert_equal_string( NULL, milter_manager_configuration_get_controller_connection_spec(config)); cut_assert_equal_string( MILTER_MANAGER_DEFAULT_EFFECTIVE_USER, milter_manager_configuration_get_effective_user(config)); cut_assert_equal_string( MILTER_MANAGER_DEFAULT_EFFECTIVE_GROUP, milter_manager_configuration_get_effective_group(config)); cut_assert_equal_string( MILTER_MANAGER_DEFAULT_PID_FILE, milter_manager_configuration_get_pid_file(config)); cut_assert_equal_string( NULL, milter_manager_configuration_get_custom_configuration_directory(config)); cut_assert_equal_uint( 0660, milter_manager_configuration_get_manager_unix_socket_mode(config)); cut_assert_equal_string( MILTER_MANAGER_DEFAULT_SOCKET_GROUP, milter_manager_configuration_get_manager_unix_socket_group(config)); cut_assert_equal_uint( 0660, milter_manager_configuration_get_controller_unix_socket_mode(config)); cut_assert_equal_string( NULL, milter_manager_configuration_get_controller_unix_socket_group(config)); cut_assert_true(milter_manager_configuration_is_remove_manager_unix_socket_on_close(config)); cut_assert_true(milter_manager_configuration_is_remove_controller_unix_socket_on_close(config)); cut_assert_true(milter_manager_configuration_is_remove_manager_unix_socket_on_create(config)); cut_assert_true(milter_manager_configuration_is_remove_controller_unix_socket_on_create(config)); cut_assert_false(milter_manager_configuration_is_daemon(config)); cut_assert_equal_uint( 10, milter_manager_configuration_get_maintenance_interval(config)); cut_assert_equal_uint( MILTER_CLIENT_DEFAULT_SUSPEND_TIME_ON_UNACCEPTABLE, milter_manager_configuration_get_suspend_time_on_unacceptable(config)); cut_assert_equal_uint( MILTER_CLIENT_DEFAULT_MAX_CONNECTIONS, milter_manager_configuration_get_max_connections(config)); cut_assert_equal_uint( 0, milter_manager_configuration_get_max_file_descriptors(config)); gcut_assert_equal_enum( MILTER_TYPE_STATUS, MILTER_STATUS_ACCEPT, milter_manager_configuration_get_fallback_status(config)); cut_assert_equal_string( MILTER_MANAGER_PACKAGE_PLATFORM, milter_manager_configuration_get_package_platform(config)); cut_assert_equal_string( MILTER_MANAGER_PACKAGE_OPTIONS, milter_manager_configuration_get_package_options(config)); cut_assert_equal_uint( 0, milter_manager_configuration_get_connection_check_interval(config)); gcut_assert_equal_enum( MILTER_TYPE_CLIENT_EVENT_LOOP_BACKEND, MILTER_CLIENT_EVENT_LOOP_BACKEND_GLIB, milter_manager_configuration_get_event_loop_backend(config)); cut_assert_equal_uint( 0, milter_manager_configuration_get_n_workers(config)); cut_assert_equal_uint( 0, milter_manager_configuration_get_default_packet_buffer_size(config)); cut_assert_equal_boolean( TRUE, milter_manager_configuration_get_use_syslog(config)); cut_assert_equal_string( NULL, milter_manager_configuration_get_syslog_facility(config)); cut_assert_equal_uint( MILTER_CHUNK_SIZE, milter_manager_configuration_get_chunk_size(config)); cut_assert_equal_uint( 0, milter_manager_configuration_get_max_pending_finished_sessions(config)); if (expected_children) g_object_unref(expected_children); expected_children = milter_manager_children_new(config, loop); if (actual_children) g_object_unref(actual_children); actual_children = milter_manager_children_new(config, loop); milter_manager_configuration_setup_children(config, actual_children, NULL); milter_assert_equal_children(expected_children, actual_children); g_object_unref(actual_children); actual_children = NULL; }
gboolean milter_manager_main (void) { MilterClient *client; MilterManager *manager; MilterManagerController *controller; MilterManagerConfiguration *config; MilterEventLoop *loop; gboolean remove_socket, daemon; GError *error = NULL; struct sigaction shutdown_client_action; struct sigaction reload_configuration_request_action; struct sigaction reopen_log_action; manager = the_manager; config = milter_manager_get_configuration(manager); if (option_config_dir) { milter_manager_configuration_prepend_load_path(config, option_config_dir); if (!milter_manager_reload(manager, &error)) { milter_manager_error("[manager][configuration][reload]" "[command-line-load-path][error] %s", error->message); g_error_free(error); error = NULL; } } if (getuid() != 0) milter_manager_configuration_set_privilege_mode(config, FALSE); client = MILTER_CLIENT(manager); g_signal_connect(client, "error", G_CALLBACK(cb_error), NULL); append_custom_configuration_directory(config); load_configuration(manager); if (option_show_config) { gchar *dumped_config; dumped_config = milter_manager_configuration_dump(config); if (dumped_config) { g_print("%s", dumped_config); if (!g_str_has_suffix(dumped_config, "\n")) g_print("\n"); g_free(dumped_config); } return TRUE; } update_max_file_descriptors(manager); if (milter_manager_configuration_is_privilege_mode(config) && !start_process_launcher_process(manager)) { return FALSE; } remove_socket = milter_manager_configuration_is_remove_manager_unix_socket_on_create(config); milter_client_set_remove_unix_socket_on_create(client, remove_socket); if (!milter_client_listen(client, &error)) { milter_manager_error("failed to listen: %s", error->message); g_error_free(error); return FALSE; } if (!milter_client_drop_privilege(client, &error)) { milter_manager_error("failed to drop privilege: %s", error->message); g_error_free(error); return FALSE; } loop = milter_client_get_event_loop(client); controller = milter_manager_controller_new(manager, loop); if (controller && !milter_manager_controller_listen(controller, &error)) { milter_manager_error("failed to listen controller socket: %s", error->message); g_error_free(error); error = NULL; g_object_unref(controller); controller = NULL; } daemon = milter_client_is_run_as_daemon(client); if (daemon) { if (milter_client_daemonize(client, &error)) { io_detached = TRUE; } else { milter_manager_error("failed to daemonize: %s", error->message); g_error_free(error); if (controller) g_object_unref(controller); return FALSE; } } the_manager = manager; #define SETUP_SIGNAL_ACTION(handler) \ handler ## _action.sa_handler = handler; \ sigemptyset(&handler ## _action.sa_mask); \ handler ## _action.sa_flags = 0 SETUP_SIGNAL_ACTION(shutdown_client); SETUP_SIGNAL_ACTION(reload_configuration_request); SETUP_SIGNAL_ACTION(reopen_log); #undef SETUP_SIGNAL_ACTION #define SET_SIGNAL_ACTION(SIGNAL, signal, action) \ if (sigaction(SIG ## SIGNAL, \ &action, \ &default_sig ## signal ## _action) == -1) \ set_sig ## signal ## _action = FALSE SET_SIGNAL_ACTION(INT, int, shutdown_client_action); SET_SIGNAL_ACTION(TERM, term, shutdown_client_action); SET_SIGNAL_ACTION(HUP, hup, reload_configuration_request_action); SET_SIGNAL_ACTION(USR1, usr1, reopen_log_action); #undef SET_SIGNAL_ACTION if (!milter_client_run(client, &error)) { milter_manager_error("failed to start milter-manager process: %s", error->message); g_error_free(error); } #define UNSET_SIGNAL_ACTION(SIGNAL, signal) \ if (set_sig ## signal ## _action) \ sigaction(SIG ## SIGNAL, &default_sig ## signal ## _action, NULL) UNSET_SIGNAL_ACTION(SEGV, segv); UNSET_SIGNAL_ACTION(ABRT, abort); UNSET_SIGNAL_ACTION(INT, int); UNSET_SIGNAL_ACTION(TERM, term); UNSET_SIGNAL_ACTION(HUP, hup); UNSET_SIGNAL_ACTION(USR1, usr1); #undef UNSET_SIGNAL_ACTION if (controller) g_object_unref(controller); return TRUE; }