static void general_display(int log_level, int seq, char* name, void* value, int vlen, int type) { int netslen; int slen; HA_MSG_ASSERT(value); HA_MSG_ASSERT(name); slen = fieldtypefuncs[type].stringlen(strlen(name), vlen, value); netslen = fieldtypefuncs[type].netstringlen(strlen(name), vlen, value); cl_log(log_level, "MSG[%d] : [(%s)%s=%p(%d %d)]", seq, FT_strings[type], name, value, slen, netslen); }
static void struct_memfree( void* value) { struct ha_msg* msg; if (!value){ cl_log(LOG_ERR, "value is NULL"); return ; } msg = (struct ha_msg*) value; ha_msg_del(msg); return ; }
static int netstring2struct(const void* value, size_t vlen, void** retvalue, size_t* ret_vlen) { struct ha_msg* msg; if ( !value || !retvalue || !ret_vlen){ cl_log(LOG_ERR, " netstring2struct:" "invalid input arguments"); return HA_FAIL; } msg = netstring2msg(value, vlen, 0); if (!msg){ cl_log(LOG_ERR, "netstring2struct:" "netstring2msg failed"); return HA_FAIL; } *retvalue =(void* ) msg; *ret_vlen = 0; return HA_OK; }
static int string2list(void* value, size_t vallen, int depth, void** nv, size_t* nlen) { GList* list; if (!value || !nv || !nlen || depth < 0){ cl_log(LOG_ERR, "string2struct:invalid input"); return HA_FAIL; } list = string_list_unpack(value, vallen); if (list == NULL){ cl_log(LOG_ERR, "ha_msg_addraw_ll():" "unpack_string_list failed: %s", (char*)value); return(HA_FAIL); } cl_free(value); *nv = (void*)list; *nlen = string_list_pack_length(list); return HA_OK; }
static int unametonum(const char * lname, int llen) { char loginname[64]; struct passwd* pwd; if (llen >= (int)sizeof(loginname)) { cl_log(LOG_ERR , "user id name [%s] is too long", loginname); return -1; } strncpy(loginname, lname, llen); loginname[llen] = EOS; if (isdigit((int) loginname[0])) { return atoi(loginname); } if ((pwd = getpwnam(loginname)) == NULL) { cl_log(LOG_ERR , "Invalid user id name [%s]", loginname); return -1; } return (int)pwd->pw_uid; }
int stop_addr6(struct in6_addr* addr6, int prefix_len, char* prov_ifname) { char* if_name; if(OCF_NOT_RUNNING == status_addr6(addr6,prefix_len,prov_ifname)) { return OCF_SUCCESS; } if_name = get_if(addr6, &prefix_len, prov_ifname); if (NULL == if_name) { cl_log(LOG_ERR, "no valid mechanisms."); /* I think this should be a success exit according to LSB. */ return OCF_ERR_GENERIC; } /* Unassign the address */ if (0 != unassign_addr6(addr6, prefix_len, if_name)) { cl_log(LOG_ERR, "failed to assign the address to %s", if_name); return OCF_ERR_GENERIC; } return OCF_SUCCESS; }
static void stdmsg_log(int priority, const char * fmt, ...) { va_list ap; char buf[MAXLINE]; if ( DEBUG_MODE == FALSE && priority == LOG_DEBUG ) { return; } va_start(ap, fmt); vsnprintf(buf, sizeof(buf)-1, fmt, ap); va_end(ap); cl_log(priority, "%s", buf); }
void sysrq_trigger(char t) { FILE *procf; procf = fopen("/proc/sysrq-trigger", "a"); if (!procf) { cl_perror("Opening sysrq-trigger failed."); return; } cl_log(LOG_INFO, "sysrq-trigger: %c\n", t); fprintf(procf, "%c\n", t); fclose(procf); return; }
/* set syslog facility config variable */ static int set_facility(const char * value) { int i; i = cl_syslogfac_str2int(value); if (i >= 0) { cl_log(LOG_INFO, "setting log facility to %s", value); logd_config.log_facility = i; return(TRUE); } else { return(FALSE); } }
static int servant_check_timeout_inconsistent(struct sector_header_s *hdr) { if (timeout_watchdog != hdr->timeout_watchdog) { cl_log(LOG_WARNING, "watchdog timeout: %d versus %d on this device", (int)timeout_watchdog, (int)hdr->timeout_watchdog); return -1; } if (timeout_allocate != hdr->timeout_allocate) { cl_log(LOG_WARNING, "allocate timeout: %d versus %d on this device", (int)timeout_allocate, (int)hdr->timeout_allocate); return -1; } if (timeout_loop != hdr->timeout_loop) { cl_log(LOG_WARNING, "loop timeout: %d versus %d on this device", (int)timeout_loop, (int)hdr->timeout_loop); return -1; } if (timeout_msgwait != hdr->timeout_msgwait) { cl_log(LOG_WARNING, "msgwait timeout: %d versus %d on this device", (int)timeout_msgwait, (int)hdr->timeout_msgwait); return -1; } return 0; }
static int slot_msg_wrapper(const char* devname, int mode, const void* argp) { int rc = 0; struct sbd_context *st; const struct slot_msg_arg_t* arg = (const struct slot_msg_arg_t*)argp; st = open_device(devname, LOG_WARNING); if (!st) return -1; cl_log(LOG_INFO, "Delivery process handling %s", devname); rc = slot_msg(st, arg->name, arg->msg); close_device(st); return rc; }
static void send_to_client(const dopd_client_t *client, const char *rc_string) { IPC_Channel *channel = client->channel; HA_Message *msg_out; msg_out = ha_msg_new(3); ha_msg_add(msg_out, F_TYPE, "outdater_rc"); ha_msg_add(msg_out, F_ORIG, node_name); ha_msg_add(msg_out, F_DOPD_VALUE, rc_string); if (msg2ipcchan(msg_out, channel) != HA_OK) { cl_log(LOG_ERR, "Could not send message to the client"); } }
/* *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; }
void maximize_priority(void) { if (skip_rt) { cl_log(LOG_INFO, "Not elevating to realtime (-R specified)."); return; } sbd_make_realtime(0, 256, 256); if (ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_RT, 1)) != 0) { cl_perror("ioprio_set() call failed."); } }
static void quorumd_stop(void) { cl_log(LOG_DEBUG, "quorum plugin: quorumd, quorumd_stop()"); if (repeat_timer != 0) { g_source_remove(repeat_timer); repeat_timer = 0; } if (session != NULL) { gnutls_bye (session, GNUTLS_SHUT_WR); gnutls_deinit (session); close(sock); session = NULL; } cur_quorum = -1; }
void Gmain_timeout_remove(guint tag) { GSource* source = g_main_context_find_source_by_id(NULL,tag); struct GTimeoutAppend* append = GTIMEOUT(source); if (source == NULL){ cl_log(LOG_ERR, "Attempt to remove timeout (%u)" " with NULL source", tag); }else{ g_assert(IS_TIMEOUTSRC(append)); g_source_remove(tag); } return; }
static struct IPC_MESSAGE* ipc_bufpool_msg_new(void) { struct IPC_MESSAGE * temp_msg; temp_msg = malloc(sizeof(struct IPC_MESSAGE)); if (temp_msg == NULL){ cl_log(LOG_ERR, "ipc_bufpool_msg_new:" "allocating new msg failed"); return NULL; } memset(temp_msg, 0, sizeof(struct IPC_MESSAGE)); return temp_msg; }
void cl_perror(const char * fmt, ...) { const char * err; va_list ap; char buf[MAXLINE]; err = strerror(errno); va_start(ap, fmt); vsnprintf(buf, MAXLINE, fmt, ap); va_end(ap); cl_log(LOG_ERR, "%s: %s", buf, err); }
int advt_addr6(struct in6_addr* addr6, int prefix_len, char* prov_ifname) { /* First, we need to find a proper device to assign the address */ char* if_name = get_if(addr6, &prefix_len, prov_ifname); int i; if (NULL == if_name) { cl_log(LOG_ERR, "no valid mechanisms"); return OCF_ERR_GENERIC; } /* Send unsolicited advertisement packet to neighbor */ for (i = 0; i < UA_REPEAT_COUNT; i++) { send_ua(addr6, if_name); sleep(1); } return OCF_SUCCESS; }
static void ipc_bufpool_msg_done(struct IPC_MESSAGE * msg) { struct ipc_bufpool* pool; if (msg == NULL){ cl_log(LOG_ERR, "ipc_bufpool_msg_done:" "invalid input"); return; } pool = (struct ipc_bufpool*)msg->msg_private; ipc_bufpool_unref(pool); free(msg); }
void ipc_bufpool_unref(struct ipc_bufpool* pool){ if (pool == NULL){ cl_log(LOG_ERR, "unref_pool:" " invalid input"); return; } pool->refcount --; if (pool->refcount <= 0){ ipc_bufpool_del(pool); } return; }
static void sbd_membership_destroy(gpointer user_data) { cl_log(LOG_WARNING, "Lost connection to %s", name_for_cluster_type(get_cluster_type())); if (get_cluster_type() != pcmk_cluster_unknown) { #if SUPPORT_COROSYNC && CHECK_TWO_NODE cmap_destroy(); #endif } set_servant_health(pcmk_health_unclean, LOG_ERR, "Cluster connection terminated"); notify_parent(); /* Attempt to reconnect, the watchdog will take the node down if the problem isn't transient */ sbd_membership_connect(); }
void inherit_compress(void) { char* inherit_env = NULL; inherit_env = getenv(TRADITIONAL_COMPRESSION); if (inherit_env != NULL && *inherit_env != EOS) { gboolean value; if (cl_str_to_boolean(inherit_env, &value)!= HA_OK){ cl_log(LOG_ERR, "inherit traditional_compression failed"); }else{ cl_set_traditional_compression(value); } } }
int cl_file_exists(const char* filename) { struct stat st; if (filename == NULL){ cl_log(LOG_ERR, "%s: NULL filename", __FUNCTION__); return FALSE; } if (lstat(filename, &st) == 0){ return S_ISREG(st.st_mode); } return FALSE; }
static void flush_func(gpointer key, gpointer value, gpointer user_data) { struct IPC_CHANNEL *ipc_client = (struct IPC_CHANNEL *)key; int do_warn = 0; while(ipc_client->ops->is_sending_blocked(ipc_client)) { /* FIXME misbehaving client can live lock whole ccm layer! */ if (10 == ++do_warn) { cl_log(LOG_WARNING, "ipc channel blocked, farside_pid=%u", ipc_client->farside_pid); } cl_shortsleep(); if(ipc_client->ops->resume_io(ipc_client) == IPC_BROKEN) { break; } } }
static int list2string(char* buf, char* maxp, void* value, size_t len, int depth) { int listlen; GList* list = (GList*) value; (void)len; (void)depth; listlen = string_list_pack(list , buf, maxp); if (listlen == 0){ cl_log(LOG_ERR, "list2string():" "string_list_pack() failed"); return -1; } return listlen; }
int watchdog_init(void) { if (watchdogfd < 0 && watchdogdev != NULL) { watchdogfd = open(watchdogdev, O_WRONLY); if (watchdogfd >= 0) { cl_log(LOG_NOTICE, "Using watchdog device '%s'", watchdogdev); if ((watchdog_init_interval() < 0) || (watchdog_tickle() < 0)) { return -1; } }else{ cl_perror("Cannot open watchdog device '%s'", watchdogdev); return -1; } } return 0; }
static int binary2string(char* buf, char* maxp, void* value, size_t len, int depth) { int baselen; int truelen = 0; (void)depth; baselen = B64_stringlen(len) + 1; if ( buf + baselen > maxp){ cl_log(LOG_ERR, "binary2string: out of bounary"); return -1; } truelen = binary_to_base64(value, len, buf, baselen); return truelen; }
/** * *@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; }
/* * Delete an IPC_channel from the gmainloop world... */ gboolean G_main_del_IPC_Channel(GCHSource* chp) { GSource* source = (GSource*) chp; if (chp == NULL || chp->gsourceid <= 0) { return FALSE; } if (debug_level > 1) { cl_log(LOG_DEBUG, "%s(sock=%d)",__FUNCTION__, chp->infd.fd); } g_source_remove(chp->gsourceid); chp->gsourceid = 0; /* chp should (may) now be undefined */ g_source_unref(source); return TRUE; }