Lines Matching defs:instance

44  * - instance specific events originating from the SMF master restarter.
54 * Inetd implements a state machine for each instance. The states within the
56 * specializations of the offline state for when an instance exceeds one of
57 * its DOS limits. The state of an instance can be changed as a
59 * started up. The ongoing state of an instance is stored in the SMF
61 * to view the state of each instance, and, if inetd was to terminate
65 * of a state transition to aid/ effect a change in an instance's state. The
77 * When the event has been processed (which may be delayed if the instance
244 exec_method(instance_t *instance, instance_method_t method, method_info_t *mi,
272 "Invalid configuration for instance %s, placing in maintenance"),
277 * Returns B_TRUE if the instance is in a suitable state for inetd to stop.
289 * Given the instance fmri, obtain the corresonding scf_instance.
301 error_msg(gettext("Failed to get instance for %s"), fmri);
325 error_msg(gettext("Failed to get instance for %s"), fmri);
334 * Updates the current and next repository states of instance 'inst'. If
360 error_msg(gettext("Failed to update state of instance %s in "
401 error_msg(gettext("Failed to update state of instance %s in "
581 * Perform TCP wrappers checks on this instance. Due to the fact that the
584 * opposed to making use of instance FMRIs. Sigh.
588 tcp_wrappers_ok(instance_t *instance)
592 basic_cfg_t *cfg = instance->config->basic;
604 daemon_name = instance->config->methods[
616 instance->conn_fd, NULL);
624 req.sink(instance->conn_fd);
631 req.sink(instance->conn_fd);
645 * Handler registered with the timer queue code to remove an instance from
653 instance_t *instance = arg;
655 assert(instance->cur_istate == IIS_OFFLINE_CONRATE);
656 instance->timer_id = -1;
657 update_state(instance, IIS_OFFLINE, RERR_RESTART);
658 process_offline_inst(instance);
662 * Check whether this instance in the offline state is in transition to
685 * Schedule a timer to bring the instance out of the
705 * Create a socket bound to the instance's configured address. If the
721 "Socket creation failure for instance %s, proto %s: %s"),
728 "instance %s, proto %s: %s"), fmri, proto, strerror(errno));
738 "service instance %s, proto %s: %s"), fmri,
749 "service instance %s, proto %s: %s"), fmri, proto,
762 "Failed to bind to the port of service instance %s, "
776 error_msg(gettext("Failed getsockname for instance %s, "
806 instance_t *instance = arg;
808 switch (instance->cur_istate) {
817 (void) fprintf(stderr, "%s:%d: Unknown instance state %d.\n",
818 __FILE__, __LINE__, instance->cur_istate);
823 instance->bind_timer_id = -1;
824 create_bound_fds(instance);
828 * For each of the fds for the given instance that are bound, if 'listen' is
834 poll_bound_fds(instance_t *instance, boolean_t listen, char *proto_name)
836 basic_cfg_t *cfg = instance->config->basic;
860 * to add a bound fd to the poll set for the given instance.
863 handle_bind_failure(instance_t *instance)
865 basic_cfg_t *cfg = instance->config->basic;
872 if (instance->bind_timer_id != -1)
881 (++instance->bind_fail_count > cfg->bind_fail_max))) ||
882 ((instance->bind_timer_id = iu_schedule_timer(timer_queue,
883 cfg->bind_fail_interval, retry_bind, instance)) == -1)) {
886 instance->bind_fail_count = 0;
888 switch (instance->cur_istate) {
900 "all protocols for instance %s, "
902 instance->fmri);
903 update_state(instance, IIS_DEGRADED, RERR_NONE);
904 instance->bind_retries_exceeded = B_TRUE;
908 destroy_bound_fds(instance);
916 error_msg(gettext("Too many bind failures for instance "
917 "%s, transitioning to maintenance"), instance->fmri);
918 update_state(instance, IIS_MAINTENANCE,
924 "protocols for instance %s, instance will go to "
925 "degraded"), instance->fmri);
928 * completes the instance goes to the degraded state.
930 instance->bind_retries_exceeded = B_TRUE;
935 "%s:%d: Unknown instance state %d.\n",
936 __FILE__, __LINE__, instance->cur_istate);
940 } else if (instance->cur_istate == IIS_OFFLINE) {
945 update_state(instance, IIS_OFFLINE_BIND, RERR_NONE);
1067 * Independent of the transport, for each of the entries in the instance's
1071 * to the port associated with the instance's service name. On any successful
1072 * binds the instance is taken online. Failed binds are handled by
1076 create_bound_fds(instance_t *instance)
1078 basic_cfg_t *cfg = instance->config->basic;
1091 pi->listen_fd = create_bound_endpoint(instance,
1103 pi->listen_fd = create_bound_socket(instance,
1121 close_net_fd(instance, pi->listen_fd);
1126 unregister_rpc_service(instance->fmri, pi->ri);
1127 if (register_rpc_service(instance->fmri, pi->ri) ==
1129 close_net_fd(instance, pi->listen_fd);
1139 switch (instance->cur_istate) {
1146 if (success && run_method(instance, IM_ONLINE, NULL) == -1)
1147 return; /* instance gone to maintenance */
1155 if (poll_bound_fds(instance, B_TRUE, NULL) != 0) {
1162 instance->bind_fail_count = 0;
1173 (void) fprintf(stderr, "%s:%d: Unknown instance state %d.\n",
1174 __FILE__, __LINE__, instance->cur_istate);
1180 handle_bind_failure(instance);
1185 * function unregisters the instance from rpcbind if it's an RPC service,
1189 destroy_bound_fds(instance_t *instance)
1191 basic_cfg_t *cfg = instance->config->basic;
1198 unregister_rpc_service(instance->fmri, pi->ri);
1200 close_net_fd(instance, pi->listen_fd);
1206 if (instance->bind_timer_id != -1)
1207 cancel_bind_timer(instance);
1209 instance->bind_retries_exceeded = B_FALSE;
1264 * instance.
1417 "Failed to read state of instance %s: %s"),
1422 debug_msg("instance with no previous int state - "
1456 "instance %s from repository: %s"), inst->fmri,
1478 "of %s method of instance %s"), START_METHOD_NAME,
1491 * Remove the passed instance from inetd control.
1494 remove_instance(instance_t *instance)
1496 switch (instance->cur_istate) {
1500 destroy_bound_fds(instance);
1503 cancel_bind_timer(instance);
1506 cancel_inst_timer(instance);
1511 unregister_instance_methods(instance);
1513 uu_list_remove(instance_list, instance);
1514 destroy_instance(instance);
1518 * Refresh the configuration of instance 'inst'. This method gets called as
1519 * a result of a refresh event for the instance from the master restarter, so
1520 * we can rely upon the instance's running snapshot having been updated from
1559 * Take the instance to the copies
1607 * Try to avoid the overhead of taking an instance
1611 * of the instance with its new configuration. This
1615 * the instance.
1617 * instance have changed in the new configuration.
1618 * Without taking the instance offline when the
1619 * start method changed the instance may be running
1621 * binary); and without taking the instance offline
1624 * not be picked up until the instance next goes
1659 * Since the instance isn't being
1682 debug_msg("Unhandled current state %d for instance in "
1690 * instance.
1693 handle_restarter_event(instance_t *instance, restarter_event_type_t event,
1708 update_state(instance, instance->cur_istate, RERR_NONE);
1711 refresh_instance(instance);
1715 * We've got a restart event, so if the instance is online
1720 switch (instance->cur_istate) {
1723 destroy_bound_fds(instance);
1724 (void) run_method(instance, IM_OFFLINE, NULL);
1728 remove_instance(instance);
1732 switch (instance->cur_istate) {
1739 * restarter. Take the instance to the offline resting
1742 if (instance->cur_istate == IIS_OFFLINE_BIND) {
1743 cancel_bind_timer(instance);
1744 } else if (instance->cur_istate ==
1746 cancel_inst_timer(instance);
1748 update_state(instance, IIS_OFFLINE, RERR_RESTART);
1754 switch (instance->cur_istate) {
1765 if (!(instance->config->basic->iswait &&
1766 (uu_list_first(instance->start_pids) != NULL))) {
1767 create_bound_fds(instance);
1769 update_state(instance, IIS_ONLINE, RERR_NONE);
1775 * The instance should be disabled, so run the
1776 * instance's disabled method that will do the work
1779 (void) run_method(instance, IM_DISABLE, NULL);
1785 * The master restarter has requested the instance
1789 update_state(instance, IIS_MAINTENANCE, RERR_RESTART);
1799 * The instance should be disabled. Firstly, as for
1803 * work to take the instance from offline to
1806 cancel_bind_timer(instance);
1807 update_state(instance, IIS_OFFLINE, RERR_RESTART);
1808 (void) run_method(instance, IM_DISABLE, NULL);
1814 * The master restarter has requested the instance
1819 cancel_bind_timer(instance);
1820 update_state(instance, IIS_MAINTENANCE, RERR_RESTART);
1831 * The instance needs to be disabled. Do the same work
1833 * take the instance offline.
1835 destroy_bound_fds(instance);
1841 instance->disable_req = B_TRUE;
1842 (void) run_method(instance, IM_OFFLINE, NULL);
1848 * The master restarter has requested the instance be
1857 instance->maintenance_req = B_TRUE;
1863 * stop listening on the instance's network file
1867 destroy_bound_fds(instance);
1868 (void) run_method(instance, IM_OFFLINE, NULL);
1875 update_state(instance, IIS_DISABLED, RERR_NONE);
1895 * The instance needs enabling. Commence reading its
1896 * configuration and if successful place the instance
1900 destroy_instance_cfg(instance->config);
1901 instance->config = read_instance_cfg(instance->fmri);
1902 if (instance->config != NULL) {
1903 update_state(instance, IIS_OFFLINE,
1905 process_offline_inst(instance);
1907 log_invalid_cfg(instance->fmri);
1908 update_state(instance, IIS_MAINTENANCE,
1917 * The master restarter has requested the instance be
1921 update_state(instance, IIS_MAINTENANCE, RERR_RESTART);
1931 * The master restarter has requested that the instance
1933 * and if successful place the instance in the offline
1937 destroy_instance_cfg(instance->config);
1938 instance->config = read_instance_cfg(instance->fmri);
1939 if (instance->config != NULL) {
1940 update_state(instance, IIS_OFFLINE,
1942 process_offline_inst(instance);
1949 * just place the instance in disabled even
1954 * instance to disabled. If disable isn't
1959 if ((read_enable_merged(instance->fmri,
1961 update_state(instance, IIS_DISABLED,
1964 log_invalid_cfg(instance->fmri);
1965 update_state(instance, IIS_MAINTENANCE,
1977 * The instance wants disabling. Take the instance
1980 * the work to take the instance to the disabled state.
1982 cancel_inst_timer(instance);
1983 update_state(instance, IIS_OFFLINE, RERR_RESTART);
1984 (void) run_method(instance, IM_DISABLE, NULL);
1990 * The master restarter has requested the instance
1995 cancel_inst_timer(instance);
1996 update_state(instance, IIS_MAINTENANCE, RERR_RESTART);
2005 * The instance wants disabling. Update the state
2009 update_state(instance, IIS_OFFLINE, RERR_RESTART);
2010 (void) run_method(instance, IM_DISABLE, NULL);
2016 * The master restarter has requested the instance be
2020 update_state(instance, IIS_MAINTENANCE, RERR_RESTART);
2026 debug_msg("handle_restarter_event: instance in an "
2039 * is for an instance we're not already managing we read its state, add it to
2050 instance_t *instance;
2079 * Check if we're currently managing the instance which the event
2093 for (instance = uu_list_first(instance_list); instance != NULL;
2094 instance = uu_list_next(instance_list, instance)) {
2095 if (strcmp(instance->fmri, fmri) == 0)
2099 if (instance == NULL) {
2102 debug_msg("New instance to manage: %s", fmri);
2104 if (((instance = create_instance(fmri)) == NULL) ||
2105 (retrieve_instance_state(instance) != 0) ||
2106 (retrieve_method_pids(instance) != 0)) {
2107 destroy_instance(instance);
2112 if (((err = iterate_repository_contracts(instance, 0))
2115 "Failed to adopt contracts of instance %s: %s"),
2116 instance->fmri, strerror(err));
2117 destroy_instance(instance);
2122 uu_list_node_init(instance, &instance->link, instance_pool);
2123 (void) uu_list_insert_after(instance_list, NULL, instance);
2130 if ((instance->cur_istate != IIS_DISABLED) &&
2131 (instance->cur_istate != IIS_MAINTENANCE) &&
2132 (instance->cur_istate != IIS_UNINITIALIZED)) {
2133 instance->config = read_instance_cfg(instance->fmri);
2134 if (instance->config == NULL) {
2135 log_invalid_cfg(instance->fmri);
2136 update_state(instance, IIS_MAINTENANCE,
2145 debug_msg("Event type: %d for instance: %s", event_type,
2146 instance->fmri);
2149 * If the instance is currently running a method, don't process the
2150 * event now, but attach it to the instance for processing when
2151 * the instance finishes its transition.
2153 if (INST_IN_TRANSITION(instance)) {
2154 debug_msg("storing event %d for instance %s", event_type,
2155 instance->fmri);
2156 instance->pending_rst_event = event_type;
2158 handle_restarter_event(instance, event_type, B_TRUE);
2169 * Do the state machine processing associated with the termination of instance
2241 * If the instance has a pending event process it and initiate the
2250 debug_msg("Injecting pending event %d for instance %s",
2260 * of the specified instance's non-start method with the specified status.
2270 error_msg(gettext("The %s method of instance %s failed, "
2299 * An instance method never returned a supported return code.
2303 debug_msg("The %s method of instance %s returned "
2319 * the instance's state to degraded.
2335 * This instance was found during refresh to need
2368 * inetd is stopping, and this instance hasn't
2466 * are. We call the SMF refresh function to refresh each instance so that
2468 * running snapshot of each instance being updated from the configuration
2482 error_msg(gettext("Failed to refresh instance %s: %s"),
2659 passes_basic_exec_checks(const char *instance, const char *method,
2668 "Can't stat the %s method of instance %s: %s"),
2669 method, instance, strerror(errno));
2680 "The %s method of instance %s isn't a regular file"),
2681 method, instance);
2684 error_msg(gettext("The %s method instance %s doesn't have "
2685 "any execute permissions set"), method, instance);
2693 exec_method(instance_t *instance, instance_method_t method, method_info_t *mi,
2701 basic_cfg_t *cfg = instance->config->basic;
2708 if (!tcp_wrappers_ok(instance))
2733 args = expand_address(instance, pi);
2748 "the %s method of instance %s"),
2749 methods[method].name, instance->fmri);
2764 if (instance->remote_addr.ss_family == AF_INET) {
2765 struct in_addr *in = SS_SINADDR(instance->remote_addr);
2773 addr6 = (uint32_t *)SS_SINADDR(instance->remote_addr);
2779 ntohs(SS_PORT(instance->remote_addr));
2781 if (getsockname(instance->conn_fd, (struct sockaddr *)&ss,
2815 "for the %s method of instance %s");
2818 "control for the %s method of instance %s");
2821 "instance %s to a pool due to a system "
2828 error_msg(msg, methods[method].name, instance->fmri);
2837 "for the %s method of instance %s");
2842 "instance %s to a pool due to invalid "
2848 "instance %s to a pool due to invalid "
2862 "%s method of instance %s (%s: %s)"),
2863 methods[method].name, instance->fmri, errf,
2871 "method of instance %s (out of memory)");
2876 "method of instance %s (no passwd or shadow "
2885 error_msg(msg, methods[method].name, instance->fmri);
2893 (void) dup2(instance->conn_fd, STDIN_FILENO);
2905 env = set_smf_env(mthd_ctxt, instance, methods[method].name);
2919 gettext("Failed to exec %s method of instance %s: %s"),
2920 methods[method].name, instance->fmri, strerror(errno));
2922 if ((method == IM_START) && (instance->config->basic->iswait)) {
2933 consume_wait_data(instance, 0);
2961 smf_kill_process(instance_t *instance, int sig)
2967 for (rv = uu_list_first(instance->start_pids);
2969 rv = uu_list_next(instance->start_pids, rv)) {
2974 "start process (%ld) of instance %s: %s"),
2975 rv->val, instance->fmri, strerror(errno));
2982 * Runs the specified method of the specified service instance.
2985 * instance may be in the midst of.
2989 * instance's cur state to the method's associated 'run' state and the next
2994 run_method(instance_t *instance, instance_method_t method,
3002 instance_cfg_t *cfg = instance->config;
3008 * Don't bother updating the instance's state for the start method
3012 update_instance_states(instance, get_method_state(method),
3022 if ((method == IM_OFFLINE) && instance->config->basic->iswait) {
3023 warn_msg(gettext("inetd_offline method for instance %s "
3025 instance->fmri);
3027 ret = smf_kill_process(instance, sig);
3028 process_non_start_term(instance, ret);
3031 process_non_start_term(instance, IMRET_SUCCESS);
3040 process_non_start_term(instance, IMRET_SUCCESS);
3046 ret = iterate_repository_contracts(instance, sig);
3050 "to contracts of instance %s: %s"), sig,
3051 instance->fmri, strerror(ret));
3054 process_non_start_term(instance, IMRET_SUCCESS);
3060 ret = smf_kill_process(instance, sig);
3061 process_non_start_term(instance, ret);
3070 if ((mthd_ctxt = read_method_context(instance->fmri,
3076 * of exec failures, so we can modify the instance state if necessary.
3078 if (!passes_basic_exec_checks(instance->fmri, methods[method].name,
3084 if (contract_prefork(instance->fmri, method) == -1)
3093 "Unable to fork %s method of instance %s: %s"),
3094 methods[method].name, instance->fmri, strerror(serrno));
3099 exec_method(instance, method, mi, mthd_ctxt, start_info);
3113 if (register_method(instance, child_pid, cid, method,
3123 "%s method of instance %s"), methods[method].name,
3124 instance->fmri);
3126 process_non_start_term(instance, IMRET_FAILURE);
3129 add_method_ids(instance, child_pid, cid, method);
3138 inet_ntop_native(instance->remote_addr.ss_family,
3139 SS_SINADDR(instance->remote_addr), buf,
3141 ntohs(SS_PORT(instance->remote_addr)));
3159 destroy_bound_fds(instance);
3160 update_state(instance, IIS_MAINTENANCE, RERR_FAULT);
3164 process_non_start_term(instance, IMRET_FAILURE);
3171 pending_connections(instance_t *instance, proto_info_t *pi)
3173 if (instance->config->basic->istlx) {
3183 accept_connection(instance_t *instance, proto_info_t *pi)
3188 if (instance->config->basic->istlx) {
3193 fd = tlx_accept(instance->fmri, (tlx_info_t *)pi,
3194 &(instance->remote_addr));
3199 size = sizeof (instance->remote_addr);
3201 (struct sockaddr *)&(instance->remote_addr), &size);
3219 process_nowait_request(instance_t *instance, proto_info_t *pi)
3221 basic_cfg_t *cfg = instance->config->basic;
3227 if ((instance->conn_fd = accept_connection(instance, pi)) == -1) {
3238 * is done. If the configured rate is exceeded, the instance is taken
3240 * bring the instance back online after the configured offline time.
3243 if (instance->conn_rate_count++ == 0) {
3244 instance->conn_rate_start = time(NULL);
3245 } else if (instance->conn_rate_count >
3249 if ((now - instance->conn_rate_start) > 1) {
3250 instance->conn_rate_start = now;
3251 instance->conn_rate_count = 1;
3280 instance->fmri, cfg->conn_rate_offline);
3282 close_net_fd(instance, instance->conn_fd);
3283 instance->conn_fd = -1;
3285 destroy_bound_fds(instance);
3287 instance->conn_rate_count = 0;
3289 instance->conn_rate_exceeded = B_TRUE;
3290 (void) run_method(instance, IM_OFFLINE, NULL);
3297 ret = run_method(instance, IM_START, pi);
3299 close_net_fd(instance, instance->conn_fd);
3300 instance->conn_fd = -1;
3305 instance->copies++;
3310 if (copies_limit_exceeded(instance)) {
3332 instance->fmri);
3333 destroy_bound_fds(instance);
3334 (void) run_method(instance, IM_OFFLINE, NULL);
3345 process_wait_request(instance_t *instance, const proto_info_t *pi)
3347 basic_cfg_t *cfg = instance->config->basic;
3352 instance->conn_fd = pi->listen_fd;
3358 * select readable again, and inetd will fork another instance of
3363 if (instance->fail_rate_count++ == 0) {
3364 instance->fail_rate_start = time(NULL);
3365 } else if (instance->fail_rate_count > cfg->wait_fail_cnt) {
3368 if ((now - instance->fail_rate_start) >
3370 instance->fail_rate_start = now;
3371 instance->fail_rate_count = 1;
3404 "maintenance"), instance->fmri);
3405 instance->fail_rate_count = 0;
3407 destroy_bound_fds(instance);
3409 instance->maintenance_req = B_TRUE;
3410 (void) run_method(instance, IM_OFFLINE, NULL);
3416 ret = run_method(instance, IM_START, pi);
3418 instance->conn_fd = -1;
3423 * server for a wait type instance.
3425 (void) poll_bound_fds(instance, B_FALSE, pi->proto);
3430 * Process any networks requests for each proto for each instance.
3435 instance_t *instance;
3437 for (instance = uu_list_first(instance_list); instance != NULL;
3438 instance = uu_list_next(instance_list, instance)) {
3446 switch (instance->cur_istate) {
3455 cfg = instance->config->basic;
3461 pending_connections(instance, pi)) {
3463 process_wait_request(instance, pi);
3465 process_nowait_request(instance, pi);
3499 instance_t *instance;
3555 * Process any instance restarter events.
3576 for (instance = uu_list_first(instance_list);
3577 instance != NULL;
3578 instance = uu_list_next(instance_list, instance)) {
3579 if (!instance_stopped(instance)) {
3581 instance->fmri);
3586 if (instance == NULL)
3652 /* Setup instance list. */
3657 gettext("Failed to create instance pool"),
3663 gettext("Failed to create instance list"),
3815 "how to enable \"%s\", the inetd instance.\n"
3825 "the inetd instance, and modify it according to the syntax:\n"
3852 * check if the instance fmri environment variable has been set by