int init_server_ipc_comms( char *channel_name, gboolean (*channel_client_connect)(IPC_Channel *newclient,gpointer user_data), void (*channel_connection_destroy)(gpointer user_data)) { /* the clients wait channel is the other source of events. * This source delivers the clients connection events. * listen to this source at a relatively lower priority. */ char commpath[SOCKET_LEN]; IPC_WaitConnection *wait_ch; sprintf(commpath, CRM_STATE_DIR "/%s", channel_name); wait_ch = wait_channel_init(commpath); if (wait_ch == NULL) { return 1; } G_main_add_IPC_WaitConnection( G_PRIORITY_LOW, wait_ch, NULL, FALSE, channel_client_connect, channel_name, channel_connection_destroy); crm_debug_3("Listening on: %s", commpath); return 0; }
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; }
/** * *@return non-zero on failure */ int create_connection(void) { char path[] = IPC_PATH_ATTR; char commpath[] = RECOVERYMGRSOCKPATH; struct IPC_WAIT_CONNECTION* wconn; GHashTable* wconnattrs; /* Create a "waiting for connection" object */ wconnattrs = g_hash_table_new(g_str_hash, g_str_equal); g_hash_table_insert(wconnattrs, path, commpath); wconn = ipc_wait_conn_constructor(IPC_ANYTYPE, wconnattrs); if (wconn == NULL) { cl_log(LOG_CRIT, "Unable to create wcon of type %s", IPC_ANYTYPE ); return 1; } /* Create a source to handle new connection requests */ G_main_add_IPC_WaitConnection(G_PRIORITY_HIGH, wconn , NULL, FALSE, pending_conn_dispatch, wconn, NULL); g_main_set_poll_func(cl_glibpoll); /* Create the mainloop and run it... */ mainloop = g_main_new(FALSE); g_main_run(mainloop); wconn->ops->destroy(wconn); /* free script hash table */ g_hash_table_foreach_remove(scripts, hash_remove_func, NULL); /*unlink(PIDFILE); */ return 0; }