static gboolean attrd_connect(IPC_Channel * channel, gpointer user_data) { attrd_client_t *new_client = NULL; crm_trace("Connecting channel"); if (channel == NULL) { crm_err("Channel was NULL"); return FALSE; } else if (channel->ch_status != IPC_CONNECT) { crm_err("Channel was disconnected"); return FALSE; } else if (need_shutdown) { crm_info("Ignoring connection request during shutdown"); return FALSE; } crm_malloc0(new_client, sizeof(attrd_client_t)); new_client->channel = channel; crm_trace("Created channel %p for channel %s", new_client, new_client->id); /* channel->ops->set_recv_qlen(channel, 100); */ /* channel->ops->set_send_qlen(channel, 400); */ new_client->source = G_main_add_IPC_Channel(G_PRIORITY_DEFAULT, channel, FALSE, attrd_ipc_callback, new_client, attrd_connection_destroy); crm_trace("Client %s connected", new_client->id); return TRUE; }
gboolean te_connect_stonith(gpointer user_data) { int lpc = 0; int rc = ST_OK; IPC_Channel *fence_ch = NULL; if(stonith_src != NULL) { crm_debug("Still connected"); return TRUE; } for(lpc = 0; lpc < 30; lpc++) { crm_info("Attempting connection to fencing daemon..."); sleep(1); rc = stonithd_signon("tengine"); if(rc == ST_OK) { break; } if(user_data != NULL) { crm_err("Sign-in failed: triggered a retry"); G_main_set_trigger(stonith_reconnect); return TRUE; } crm_err("Sign-in failed: pausing and trying again in 2s..."); sleep(1); } CRM_ASSERT(rc == ST_OK); /* If not, we failed 30 times... just get out */ CRM_ASSERT(stonithd_set_stonith_ops_callback( tengine_stonith_callback) == ST_OK); crm_debug_2("Grabbing IPC channel"); fence_ch = stonithd_input_IPC_channel(); CRM_ASSERT(fence_ch != NULL); crm_debug_2("Attaching to mainloop"); stonith_src = G_main_add_IPC_Channel( G_PRIORITY_LOW, fence_ch, FALSE, tengine_stonith_dispatch, NULL, tengine_stonith_connection_destroy); CRM_ASSERT(stonith_src != NULL); crm_info("Connected"); return TRUE; }
static void read_msg_process(IPC_Channel* chan) { GHashTable* conn_cmd_attrs; IPC_WaitConnection* conn_cmd = NULL; char path[] = "path"; char socketpath[] = HA_LOGDAEMON_IPC; GMainLoop* mainloop; mainloop = g_main_new(FALSE); G_main_add_SignalHandler(G_PRIORITY_HIGH, SIGTERM, logd_term_action,mainloop, NULL); conn_cmd_attrs = g_hash_table_new(g_str_hash, g_str_equal); g_hash_table_insert(conn_cmd_attrs, path, socketpath); conn_cmd = ipc_wait_conn_constructor(IPC_ANYTYPE, conn_cmd_attrs); g_hash_table_destroy(conn_cmd_attrs); if (conn_cmd == NULL){ fprintf(stderr, "ERROR: create waiting connection failed"); exit(1); } /*Create a source to handle new connect rquests for command*/ G_main_add_IPC_WaitConnection( G_PRIORITY_HIGH, conn_cmd, NULL, FALSE , on_connect_cmd, chan, NULL); chan->ops->set_high_flow_callback(chan, logd_suspend_clients, NULL); chan->ops->set_low_flow_callback(chan, logd_resume_clients, NULL); chan->high_flow_mark = chan->send_queue->max_qlen; chan->low_flow_mark = (chan->send_queue->max_qlen*3)/4; G_main_add_IPC_Channel(G_PRIORITY_DEFAULT, chan, FALSE,NULL,NULL,NULL); G_main_add_SignalHandler(G_PRIORITY_DEFAULT, SIGHUP, logd_hup_action, mainloop, NULL); g_main_run(mainloop); return; }
static gboolean pe_client_connect(IPC_Channel * client, gpointer user_data) { crm_debug_3("Invoked"); if (client == NULL) { crm_err("Channel was NULL"); } else if (client->ch_status == IPC_DISCONNECT) { crm_err("Channel was disconnected"); } else { client->ops->set_recv_qlen(client, 1024); client->ops->set_send_qlen(client, 1024); G_main_add_IPC_Channel(G_PRIORITY_LOW, client, FALSE, pe_msg_callback, NULL, pe_connection_destroy); } return TRUE; }
static void add_logging_channel_mainloop(IPC_Channel* chan) { GCHSource* chp= G_main_add_IPC_Channel( G_PRIORITY_DEFAULT, chan, FALSE, NULL, NULL, destroy_logging_channel_callback); if (chp == NULL){ cl_log(LOG_INFO, "adding logging channel to mainloop failed"); } logging_chan_in_main_loop = TRUE; return; }
GCHSource* init_client_ipc_comms(const char *channel_name, gboolean (*dispatch)( IPC_Channel* source_data, gpointer user_data), void *client_data, IPC_Channel **ch) { IPC_Channel *a_ch = NULL; GCHSource *the_source = NULL; void *callback_data = client_data; a_ch = init_client_ipc_comms_nodispatch(channel_name); if(ch != NULL) { *ch = a_ch; if(callback_data == NULL) { callback_data = a_ch; } } if(a_ch == NULL) { crm_warn("Setup of client connection failed," " not adding channel to mainloop"); return NULL; } if(dispatch == NULL) { crm_warn("No dispatch method specified..." "maybe you meant init_client_ipc_comms_nodispatch()?"); } else { crm_debug_3("Adding dispatch method to channel"); the_source = G_main_add_IPC_Channel( G_PRIORITY_HIGH, a_ch, FALSE, dispatch, callback_data, default_ipc_connection_destroy); } return the_source; }
/** * Create new client (we don't know appname or pid yet) . * This is called when a connection is first established. */ static recoverymgr_client_t* recoverymgr_client_new(struct IPC_CHANNEL* ch) { recoverymgr_client_t* ret; ret = g_new(recoverymgr_client_t, 1); memset(ret, 0, sizeof(*ret)); ret->appname = NULL; ret->appinst = NULL; ret->ch = ch; ret->pid = 0; ret->deleteme = FALSE; ret->rcmsg.msg_body = &ret->rc; ret->rcmsg.msg_len = sizeof(ret->rc); ret->rcmsg.msg_done = NULL; ret->rcmsg.msg_private = NULL; ret->rc.rc = 0; if (debug >= DBGMIN) { cl_log(LOG_DEBUG, "recoverymgr_client_new: channel: 0x%x" " pid=%d" , GPOINTER_TO_UINT(ch) , ch->farside_pid); } ret->source = G_main_add_IPC_Channel(G_PRIORITY_DEFAULT , ch, FALSE, recoverymgr_dispatch, (gpointer)ret , recoverymgr_client_remove); if (!ret->source) { memset(ret, 0, sizeof(*ret)); ret=NULL; return ret; } return ret; }
static void write_msg_process(IPC_Channel* readchan) { GMainLoop* mainloop; IPC_Channel* ch = readchan; mainloop = g_main_new(FALSE); G_main_add_IPC_Channel(G_PRIORITY_DEFAULT, ch, FALSE, direct_log, mainloop, NULL); G_main_add_SignalHandler(G_PRIORITY_HIGH, SIGTERM, logd_term_write_action, mainloop, NULL); G_main_add_SignalHandler(G_PRIORITY_DEFAULT, SIGHUP, logd_hup_action, mainloop, NULL); g_main_run(mainloop); }
/* *GLoop Message Handlers */ static gboolean on_connect_cmd (IPC_Channel* ch, gpointer user_data) { ha_logd_client_t* client = NULL; /* check paremeters */ if (NULL == ch) { cl_log(LOG_ERR, "on_connect_cmd: channel is null"); return TRUE; } /* create new client */ if (NULL == (client = malloc(sizeof(ha_logd_client_t)))) { return FALSE; } memset(client, 0, sizeof(ha_logd_client_t)); client->pid = ch->farside_pid; client->chan = ch; client->logchan = (IPC_Channel*)user_data; client->g_src = G_main_add_IPC_Channel(G_PRIORITY_DEFAULT, ch, FALSE, on_receive_cmd, (gpointer)client, on_remove_client); if (client->g_src == NULL){ cl_log(LOG_ERR, "add the client to main loop failed"); free(client); return TRUE; } if (stop_reading){ G_main_IPC_Channel_pause(client->g_src); } logd_client_list = g_list_append(logd_client_list, client); return TRUE; }
static gboolean stonith_client_connect(IPC_Channel *channel, gpointer user_data) { cl_uuid_t client_id; xmlNode *reg_msg = NULL; stonith_client_t *new_client = NULL; char uuid_str[UU_UNPARSE_SIZEOF]; const char *channel_name = user_data; crm_trace("Connecting channel"); CRM_CHECK(channel_name != NULL, return FALSE); if (channel == NULL) { crm_err("Channel was NULL"); return FALSE; } else if (channel->ch_status != IPC_CONNECT) { crm_err("Channel was disconnected"); return FALSE; } else if(stonith_shutdown_flag) { crm_info("Ignoring new client [%d] during shutdown", channel->farside_pid); return FALSE; } crm_malloc0(new_client, sizeof(stonith_client_t)); new_client->channel = channel; new_client->channel_name = channel_name; crm_trace("Created channel %p for channel %s", new_client, new_client->channel_name); channel->ops->set_recv_qlen(channel, 1024); channel->ops->set_send_qlen(channel, 1024); new_client->source = G_main_add_IPC_Channel( G_PRIORITY_DEFAULT, channel, FALSE, stonith_client_callback, new_client, stonith_client_destroy); crm_trace("Channel %s connected for client %s", new_client->channel_name, new_client->id); cl_uuid_generate(&client_id); cl_uuid_unparse(&client_id, uuid_str); CRM_CHECK(new_client->id == NULL, crm_free(new_client->id)); new_client->id = crm_strdup(uuid_str); /* make sure we can find ourselves later for sync calls * redirected to the master instance */ g_hash_table_insert(client_list, new_client->id, new_client); reg_msg = create_xml_node(NULL, "callback"); crm_xml_add(reg_msg, F_STONITH_OPERATION, CRM_OP_REGISTER); crm_xml_add(reg_msg, F_STONITH_CLIENTID, new_client->id); send_ipc_message(channel, reg_msg); free_xml(reg_msg); return TRUE; }