/* * Destroy session context. */ void pool_session_context_destroy(void) { if (session_context) { pool_clear_sent_message_list(); free(session_context->message_list.sent_messages); pool_memory_delete(session_context->memory_context, 0); if (pool_config->memory_cache_enabled) { pool_discard_query_cache_array(session_context->query_cache_array); session_context->num_selects = 0; } if (session_context->query_context) pool_query_context_destroy(session_context->query_context); } /* XXX For now, just zap memory */ memset(&session_context_d, 0, sizeof(session_context_d)); session_context = NULL; }
/* * trigger_failover_command: execute specified command at failover. * command_line is null-terminated string. */ static int trigger_failover_command(int node, const char *command_line) { int r = 0; String *exec_cmd; char port_buf[6]; char buf[2]; BackendInfo *info; if (command_line == NULL || (strlen(command_line) == 0)) return 0; /* check nodeID */ if (node < 0 || node > NUM_BACKENDS) return -1; info = pool_get_node_info(node); if (!info) return -1; buf[1] = '\0'; pool_memory = pool_memory_create(PREPARE_BLOCK_SIZE); if (!pool_memory) { pool_error("trigger_failover_command: pool_memory_create() failed"); return -1; } exec_cmd = init_string(""); while (*command_line) { if (*command_line == '%') { if (*(command_line + 1)) { char val = *(command_line + 1); switch (val) { case 'p': /* port */ snprintf(port_buf, sizeof(port_buf), "%d", info->backend_port); string_append_char(exec_cmd, port_buf); break; case 'D': /* database directory */ string_append_char(exec_cmd, info->backend_data_directory); break; case 'd': /* node id */ snprintf(port_buf, sizeof(port_buf), "%d", node); string_append_char(exec_cmd, port_buf); break; case 'h': /* host name */ string_append_char(exec_cmd, info->backend_hostname); break; case 'm': /* new master node id */ snprintf(port_buf, sizeof(port_buf), "%d", get_next_master_node()); string_append_char(exec_cmd, port_buf); break; case 'M': /* old master node id */ snprintf(port_buf, sizeof(port_buf), "%d", MASTER_NODE_ID); string_append_char(exec_cmd, port_buf); break; case '%': /* escape */ string_append_char(exec_cmd, "%"); break; default: /* ignore */ break; } command_line++; } } else { buf[0] = *command_line; string_append_char(exec_cmd, buf); } command_line++; } if (strlen(exec_cmd->data) != 0) { pool_log("execute command: %s", exec_cmd->data); r = system(exec_cmd->data); } pool_memory_delete(pool_memory, 0); pool_memory = NULL; return r; }