/* * _metric_control_protocol_err_code_conversion * * Convert metric control protocol err codes to API err codes * * Returns proper err code */ static int _metric_control_protocol_err_code_conversion(u_int32_t err_code) { switch(err_code) { case CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_SUCCESS: return CEREBRO_ERR_SUCCESS; case CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_VERSION_INVALID: return CEREBRO_ERR_VERSION_INCOMPATIBLE; case CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_COMMAND_INVALID: return CEREBRO_ERR_PROTOCOL; case CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_METRIC_INVALID: return CEREBRO_ERR_METRIC_INVALID; case CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_PARAMETER_INVALID: return CEREBRO_ERR_PROTOCOL; case CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_PACKET_INVALID: return CEREBRO_ERR_PROTOCOL; case CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_METRIC_MAX: return CEREBRO_ERR_METRIC_MAX; case CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_INTERNAL_ERROR: CEREBRO_DBG(("control internal system error")); return CEREBRO_ERR_INTERNAL; default: CEREBRO_DBG(("invalid protocol error code: %d", err_code)); return CEREBRO_ERR_INTERNAL; } }
int _cerebro_namelist_append(cerebro_namelist_t namelist, const char *metric_name) { char *str = NULL; if (_cerebro_namelist_check(namelist) < 0) return -1; if (!metric_name || strlen(metric_name) > CEREBRO_MAX_METRIC_NAME_LEN) { CEREBRO_DBG(("metric_name invalid")); namelist->errnum = CEREBRO_ERR_INTERNAL; goto cleanup; } if (!(str = strdup(metric_name))) { namelist->errnum = CEREBRO_ERR_OUTMEM; goto cleanup; } if (!list_append(namelist->metric_names, str)) { CEREBRO_DBG(("list_append: %s", strerror(errno))); namelist->errnum = CEREBRO_ERR_INTERNAL; goto cleanup; } return 0; cleanup: free(str); return -1; }
/* * _readline * * read a line from the hostsfile. Buffer guaranteed to be null * terminated. * * - fd - file descriptor to read from * - buf - buffer pointer * - buflen - buffer length * * Return amount of data read into the buffer, -1 on error */ static int _readline(int fd, char *buf, unsigned int buflen) { int len; if (fd <= 0 || !buf || !buflen) { CEREBRO_DBG(("invalid parameters")); return -1; } if ((len = fd_read_line(fd, buf, buflen)) < 0) { CEREBRO_ERR(("fd_read_line: %s", strerror(errno))); return -1; } /* buflen - 1 b/c fd_read_line guarantees null termination */ if (len >= (buflen-1)) { CEREBRO_DBG(("fd_read_line: line truncation")); return -1; } return len; }
/* * _setup_metric_control_fd * * Setup the metric control file descriptor * * Returns fd on success, -1 on error */ static int _setup_metric_control_fd(cerebro_t handle) { struct sockaddr_un addr; int fd = -1; if ((fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) { CEREBRO_DBG(("socket: %s", strerror(errno))); handle->errnum = CEREBRO_ERR_INTERNAL; goto cleanup; } memset(&addr, '\0', sizeof(struct sockaddr_un)); addr.sun_family = AF_LOCAL; strncpy(addr.sun_path, CEREBRO_METRIC_CONTROL_PATH, sizeof(addr.sun_path)); if (connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) { CEREBRO_DBG(("connect: %s", strerror(errno))); handle->errnum = CEREBRO_ERR_CONNECT; goto cleanup; } return fd; cleanup: /* ignore potential error, we're in the error path already */ close(fd); return -1; }
/* * _event_server_response_unmarshall * * Unmarshall contents of a event server response * * Returns 0 on success, -1 on error */ static int _event_server_response_unmarshall(cerebro_t handle, struct cerebro_event_server_response *res, const char *buf, unsigned int buflen) { int n, bufPtrlen, c = 0; char *bufPtr; if (!res || !buf || buflen < CEREBRO_EVENT_SERVER_RESPONSE_LEN) { CEREBRO_DBG(("invalid pointers")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if ((n = unmarshall_int32(&(res->version), buf + c, buflen - c)) < 0) { CEREBRO_DBG(("unmarshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; if ((n = unmarshall_u_int32(&(res->err_code), buf + c, buflen - c)) < 0) { CEREBRO_DBG(("unmarshall_u_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; if ((n = unmarshall_u_int8(&(res->end), buf + c, buflen - c)) < 0) { CEREBRO_DBG(("unmarshall_u_int8")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; bufPtr = res->event_name; bufPtrlen = sizeof(res->event_name); if ((n = unmarshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c)) < 0) { CEREBRO_DBG(("unmarshall_buffer")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; if (c != CEREBRO_EVENT_SERVER_RESPONSE_LEN) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } return 0; }
/* * _event_server_err_check * * Check that the version and error code are good prior to * unmarshalling * * Returns 0 on success, -1 on error */ static int _event_server_err_check(cerebro_t handle, const char *buf, unsigned int buflen) { int n, len = 0; int32_t version; u_int32_t err_code; if ((n = unmarshall_int32(&version, buf + len, buflen - len)) < 0) { CEREBRO_DBG(("unmarshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!n) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } len += n; if ((n = unmarshall_u_int32(&err_code, buf + len, buflen - len)) < 0) { CEREBRO_DBG(("unmarshall_u_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!n) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } len += n; if (version != CEREBRO_EVENT_SERVER_PROTOCOL_VERSION) { handle->errnum = CEREBRO_ERR_VERSION_INCOMPATIBLE; return -1; } if (err_code != CEREBRO_EVENT_SERVER_PROTOCOL_ERR_SUCCESS) { handle->errnum = _event_server_protocol_err_code_conversion(err_code); return -1; } /* Note: We don't care about the 'end' or the 'event_name' portions * of the response when we're just looking for an error code. */ return 0; }
/* * _metric_control_response_check * * Check the version and error code * * Returns 0 on success, -1 on error */ static int _metric_control_response_check(cerebro_t handle, const char *buf, unsigned int buflen) { int n, len = 0; int32_t version; u_int32_t err_code; if ((n = unmarshall_int32(&version, buf + len, buflen - len)) < 0) { CEREBRO_DBG(("unmarshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!n) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } len += n; if ((n = unmarshall_u_int32(&err_code, buf + len, buflen - len)) < 0) { CEREBRO_DBG(("unmarshall_u_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!n) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } len += n; if (version != CEREBRO_METRIC_CONTROL_PROTOCOL_VERSION) { handle->errnum = CEREBRO_ERR_VERSION_INCOMPATIBLE; return -1; } if (err_code != CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_SUCCESS) { handle->errnum = _metric_control_protocol_err_code_conversion(err_code); return -1; } return 0; }
/* * cerebro_get_loadavgs * * Read load averages */ int cerebro_metric_get_loadavgs(float *loadavg1, float *loadavg5, float *loadavg15) { int len, fd = -1; char buf[LOADAVG_BUFLEN]; struct timeval now; int rv = -1; if (gettimeofday(&now, NULL) < 0) { CEREBRO_ERR(("gettimeofday: %s", strerror(errno))); goto cleanup; } if ((now.tv_sec - last_read) > LOADVAG_CACHETIMEOUT) { if ((fd = open(LOADAVG_FILE, O_RDONLY, 0)) < 0) { CEREBRO_ERR(("open: %s", strerror(errno))); goto cleanup; } memset(buf, '\0', LOADAVG_BUFLEN); if ((len = read(fd, buf, LOADAVG_BUFLEN)) < 0) { CEREBRO_ERR(("read: %s", strerror(errno))); goto cleanup; } if (sscanf(buf, "%f %f %f", &cache_loadavg1, &cache_loadavg5, &cache_loadavg15) != 3) { CEREBRO_DBG(("loadavg file parse error")); goto cleanup; } last_read = now.tv_sec; } if (loadavg1) *loadavg1 = cache_loadavg1; if (loadavg5) *loadavg5 = cache_loadavg5; if (loadavg15) *loadavg15 = cache_loadavg15; rv = 0; cleanup: /* ignore potential error, just return result */ if (fd >= 0) close(fd); return rv; }
/* * _merge_cerebro_configs * * Merge contents of module_conf and config_file_conf into conf. The * config file conf takes precedence. */ static int _merge_cerebro_configs(struct cerebro_config *conf, struct cerebro_config *module_conf, struct cerebro_config *config_file_conf, unsigned int *errnum) { if (!conf || !module_conf || !config_file_conf) { CEREBRO_DBG(("invalid parameters")); if (errnum) *errnum = CEREBRO_ERR_INTERNAL; return -1; } /* * Config file configuration takes precedence over config module * configuration */ memset(conf, '\0', sizeof(struct cerebro_config)); if (_set_cerebro_config(conf, config_file_conf, errnum) < 0) return -1; if (_set_cerebro_config(conf, module_conf, errnum) < 0) return -1; return 0; }
int load_config(struct cerebro_config *conf, unsigned int *errnum) { struct cerebro_config module_conf; struct cerebro_config config_file_conf; if (!conf) { CEREBRO_DBG(("conf null")); if (errnum) *errnum = CEREBRO_ERR_INTERNAL; return -1; } memset(conf, '\0', sizeof(struct cerebro_config)); memset(&module_conf, '\0', sizeof(struct cerebro_config)); memset(&config_file_conf, '\0', sizeof(struct cerebro_config)); if (_load_config_module(&module_conf, errnum) < 0) return -1; if (_load_config_file(&config_file_conf, errnum) < 0) return -1; if (_merge_cerebro_configs(conf, &module_conf, &config_file_conf, errnum) < 0) return -1; return 0; }
int cerebro_handle_destroy(cerebro_t handle) { if (_cerebro_handle_check(handle) < 0) return -1; if (handle->loaded_state & CEREBRO_CONFIG_LOADED) { if (_cerebro_unload_config(handle) < 0) return -1; if (handle->loaded_state & CEREBRO_CONFIG_LOADED) { CEREBRO_DBG(("loaded_state invalid")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } } list_destroy(handle->namelists); handle->namelists = NULL; list_destroy(handle->nodelists); handle->nodelists = NULL; list_destroy(handle->event_fds); handle->event_fds = NULL; handle->errnum = CEREBRO_ERR_SUCCESS; handle->magic = ~CEREBRO_MAGIC_NUMBER; free(handle); return 0; }
/* * _event_server_request_marshall * * Marshall contents of a event server request * * Returns length written to buffer on success, -1 on error */ static int _event_server_request_marshall(cerebro_t handle, struct cerebro_event_server_request *req, char *buf, unsigned int buflen) { int n, bufPtrlen, c = 0; char *bufPtr; if (!buf || buflen < CEREBRO_EVENT_SERVER_REQUEST_PACKET_LEN) { CEREBRO_DBG(("invalid parameters")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } memset(buf, '\0', buflen); if ((n = marshall_int32(req->version, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; bufPtr = req->event_name; bufPtrlen = sizeof(req->event_name); if ((n = marshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_buffer")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; if ((n = marshall_u_int32(req->flags, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_u_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; return c; }
/* * genders_clusterlist_get_all_nodes * * genders clusterlist module get_all_nodes function */ static int genders_clusterlist_get_all_nodes(char ***nodes) { if (!gh) { CEREBRO_DBG(("gh null")); return -1; } if (!nodes) { CEREBRO_DBG(("invalid parameters")); return -1; } return cerebro_clusterlist_genders_get_all_nodes(gh, nodes); }
/* * _event_value_unmarshall * * Unmarshall contents of an event * * Returns 0 on success, -1 on error */ static int _event_value_unmarshall(cerebro_t handle, struct cerebro_event *event, void **event_value, const char *buf, unsigned int buflen) { int errnum = 0, evalue_len = 0; void *evalue = NULL; u_int32_t etype, elen; #if CEREBRO_DEBUG if (!event || event->event_value_type == CEREBRO_DATA_VALUE_TYPE_NONE || !event_value || !buf) { CEREBRO_DBG(("invalid parameters")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } #endif /* CEREBRO_DEBUG */ etype = event->event_value_type; elen = event->event_value_len; /* Special case for ending null character */ if (etype == CEREBRO_DATA_VALUE_TYPE_STRING) evalue_len = buflen + 1; else evalue_len = buflen; if (!(evalue = malloc(evalue_len))) { handle->errnum = CEREBRO_ERR_OUTMEM; return -1; } memset(evalue, '\0', evalue_len); if (unmarshall_data_value(etype, elen, evalue, evalue_len, buf, buflen, &errnum) < 0) { handle->errnum = errnum; goto cleanup; } *event_value = evalue; return 0; cleanup: free(evalue); return -1; }
/* * _metric_value_unmarshall * * Unmarshall contents of a metric server response * * Returns 0 on success, -1 on error */ static int _metric_value_unmarshall(cerebro_t handle, struct cerebro_metric_server_response *res, void **metric_value, const char *buf, unsigned int buflen) { int errnum = 0, mvalue_len = 0; void *mvalue = NULL; u_int32_t mtype, mlen; #if CEREBRO_DEBUG if (!res || res->metric_value_type == CEREBRO_DATA_VALUE_TYPE_NONE || !metric_value || !buf) { CEREBRO_DBG(("invalid parameters")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } #endif /* CEREBRO_DEBUG */ mtype = res->metric_value_type; mlen = res->metric_value_len; /* Special case for ending null character */ if (mtype == CEREBRO_DATA_VALUE_TYPE_STRING) mvalue_len = buflen + 1; else mvalue_len = buflen; if (!(mvalue = malloc(mvalue_len))) { handle->errnum = CEREBRO_ERR_OUTMEM; return -1; } memset(mvalue, '\0', mvalue_len); if (unmarshall_data_value(mtype, mlen, mvalue, mvalue_len, buf, buflen, &errnum) < 0) { handle->errnum = errnum; goto cleanup; } *metric_value = mvalue; return 0; cleanup: free(mvalue); return -1; }
/* * genders_clusterlist_setup * * genders clusterlist module setup function */ static int genders_clusterlist_setup(void) { if (gh) { CEREBRO_DBG(("gh non-null")); return 0; } return cerebro_clusterlist_genders_setup(&gh, NULL); }
/* * genders_clusterlist_numnodes * * genders clusterlist module numnodes function */ static int genders_clusterlist_numnodes(void) { if (!gh) { CEREBRO_DBG(("gh null")); return -1; } return cerebro_clusterlist_genders_numnodes(gh); }
/* * hostsfile_clusterlist_numnodes * * hostsfile clusterlist module numnodes function */ static int hostsfile_clusterlist_numnodes(void) { if (!hosts) { CEREBRO_DBG(("hosts null")); return -1; } return list_count(hosts); }
/* * _receive_metric_value * * Receive the metric value * * Returns 0 on success, -1 on error */ static int _receive_metric_value(cerebro_t handle, struct cerebro_metric_server_response *res, int fd) { char *vbuf = NULL; int vbytes_read, rv = -1; void *metric_value = NULL; unsigned int errnum; if (!res->metric_value_len) { CEREBRO_DBG(("invalid parameters")); handle->errnum = CEREBRO_ERR_INTERNAL; goto cleanup; } if (!(vbuf = malloc(res->metric_value_len))) { handle->errnum = CEREBRO_ERR_OUTMEM; goto cleanup; } if ((vbytes_read = receive_data(fd, res->metric_value_len, vbuf, res->metric_value_len, CEREBRO_METRIC_SERVER_PROTOCOL_CLIENT_TIMEOUT_LEN, &errnum)) < 0) { handle->errnum = errnum; goto cleanup; } if (vbytes_read != res->metric_value_len) { handle->errnum = CEREBRO_ERR_PROTOCOL; goto cleanup; } if (_metric_value_unmarshall(handle, res, &metric_value, vbuf, vbytes_read) < 0) goto cleanup; res->metric_value = metric_value; rv = 0; cleanup: free(vbuf); return rv; }
/* * genders_clusterlist_node_in_cluster * * genders clusterlist module node_in_cluster function */ static int genders_clusterlist_node_in_cluster(const char *node) { char nodebuf[CEREBRO_MAX_NODENAME_LEN+1]; char *nodePtr = NULL; int flag; if (!gh) { CEREBRO_DBG(("gh null")); return -1; } if (!node) { CEREBRO_DBG(("invalid parameters")); return -1; } /* Shorten hostname if necessary */ if (strchr(node, '.')) { char *p; memset(nodebuf, '\0', CEREBRO_MAX_NODENAME_LEN+1); strncpy(nodebuf, node, CEREBRO_MAX_NODENAME_LEN); p = strchr(nodebuf, '.'); *p = '\0'; nodePtr = nodebuf; } else nodePtr = (char *)node; if ((flag = genders_isnode(gh, nodePtr)) < 0) { CEREBRO_ERR(("genders_isnode: %s", genders_errormsg(gh))); return -1; } return flag; }
/* * updown_event_destroy * * updown event module destroy function */ static void updown_event_destroy(struct cerebro_event *event) { if (!event) { CEREBRO_DBG(("invalid parameters")); return; } free(event->event_value); free(event); }
/* * _create_entry * * Create an entry in the node_states hash */ static int * _create_entry(const char *nodename) { char *nodePtr = NULL; int *state = NULL; if (!(state = (int *)malloc(sizeof(int)))) { CEREBRO_ERR(("malloc: %s", strerror(errno))); goto cleanup; } if (!(nodePtr = (char *)malloc(CEREBRO_MAX_NODENAME_LEN + 1))) { CEREBRO_ERR(("malloc: %s", strerror(errno))); goto cleanup; } strncpy(nodePtr, nodename, CEREBRO_MAX_NODENAME_LEN); if (!list_append(node_states_nodenames, nodePtr)) { CEREBRO_DBG(("list_append: %s", strerror(errno))); goto cleanup; } if (!hash_insert(node_states, nodePtr, state)) { CEREBRO_DBG(("hash_insert: %s", strerror(errno))); goto cleanup; } *state = UPDOWN_EVENT_STATE_INIT; return state; cleanup: free(nodePtr); free(state); return NULL; }
cerebro_nodelist_t _cerebro_nodelist_create(cerebro_t handle, const char *metric_name) { cerebro_nodelist_t nodelist = NULL; if (!(nodelist = (cerebro_nodelist_t)malloc(sizeof(struct cerebro_nodelist)))) { handle->errnum = CEREBRO_ERR_OUTMEM; goto cleanup; } memset(nodelist, '\0', sizeof(struct cerebro_nodelist)); nodelist->magic = CEREBRO_NODELIST_MAGIC_NUMBER; strcpy(nodelist->metric_name, metric_name); if (!(nodelist->nodes = list_create((ListDelF)_cerebro_nodelist_data_destroy))) { handle->errnum = CEREBRO_ERR_OUTMEM; goto cleanup; } /* No delete function, list_destroy() on 'nodes' will take care of * deleting iterators. */ if (!(nodelist->iterators = list_create(NULL))) { handle->errnum = CEREBRO_ERR_OUTMEM; goto cleanup; } if (!list_append(handle->nodelists, nodelist)) { CEREBRO_DBG(("list_append: %s", strerror(errno))); handle->errnum = CEREBRO_ERR_INTERNAL; goto cleanup; } nodelist->handle = handle; return nodelist; cleanup: if (nodelist) { if (nodelist->nodes) list_destroy(nodelist->nodes); if (nodelist->iterators) list_destroy(nodelist->iterators); free(nodelist); } return NULL; }
/* * list_strcmp * * strcmp for list data structure */ static int list_strcmp(void *x, void *key) { if (!x || !key) { CEREBRO_DBG(("invalid parameters")); return -1; } if (!strcmp((char *)x, (char *)key)) return 1; return 0; }
int _cerebro_handle_check(cerebro_t handle) { if (!handle || handle->magic != CEREBRO_MAGIC_NUMBER) return -1; if (!handle->namelists) { CEREBRO_DBG(("namelists null")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!handle->nodelists) { CEREBRO_DBG(("nodelists null")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } return 0; }
/* * _get_userspace_metric_value * * Get the metric value data supplied by a userspace program * * Returns message metric data on success, NULL otherwise */ static struct cerebrod_message_metric * _get_userspace_metric_value(struct cerebrod_speaker_metric_info *metric_info) { struct cerebrod_message_metric *mm = NULL; u_int32_t mtype, mlen; void *mvalue; assert(metric_info); #if CEREBRO_DEBUG if (metric_info->next_call_time) CEREBRO_DBG(("Unexpected next_call_time")); #endif /* CEREBRO_DEBUG */ mtype = metric_info->metric_value_type; mlen = metric_info->metric_value_len; mvalue = metric_info->metric_value; if (check_data_type_len_value(mtype, mlen, mvalue) < 0) goto cleanup; mm = Malloc(sizeof(struct cerebrod_message_metric)); memset(mm, '\0', sizeof(struct cerebrod_message_metric)); /* need not overflow */ strncpy(mm->metric_name, metric_info->metric_name, CEREBRO_MAX_METRIC_NAME_LEN); mm->metric_value_type = metric_info->metric_value_type; mm->metric_value_len = metric_info->metric_value_len; if (mm->metric_value_len) { mm->metric_value = Malloc(metric_info->metric_value_len); memcpy(mm->metric_value, metric_info->metric_value, metric_info->metric_value_len); } else mm->metric_value = NULL; return mm; cleanup: if (mm) { if (mm->metric_value) Free(mm->metric_value); Free(mm); } return NULL; }
/* * _event_server_protocol_err_code_conversion * * Convert event server protocol err codes to API err codes * * Returns proper err code */ static int _event_server_protocol_err_code_conversion(u_int32_t err_code) { switch(err_code) { case CEREBRO_EVENT_SERVER_PROTOCOL_ERR_SUCCESS: return CEREBRO_ERR_SUCCESS; case CEREBRO_EVENT_SERVER_PROTOCOL_ERR_VERSION_INVALID: return CEREBRO_ERR_VERSION_INCOMPATIBLE; case CEREBRO_EVENT_SERVER_PROTOCOL_ERR_PACKET_INVALID: return CEREBRO_ERR_PROTOCOL; case CEREBRO_EVENT_SERVER_PROTOCOL_ERR_EVENT_INVALID: return CEREBRO_ERR_EVENT_INVALID; case CEREBRO_EVENT_SERVER_PROTOCOL_ERR_PARAMETER_INVALID: return CEREBRO_ERR_PROTOCOL; case CEREBRO_EVENT_SERVER_PROTOCOL_ERR_INTERNAL_ERROR: CEREBRO_DBG(("server internal system error")); return CEREBRO_ERR_INTERNAL; default: CEREBRO_DBG(("invalid protocol error code: %d", err_code)); return CEREBRO_ERR_INTERNAL; } }
/* * _move_past_whitespace * * move past whitespace at the beginning of the buffer * * - buf - buffer pointer * * Return pointer to beginning of first non-whitespace char, NULL on * error */ static char * _move_past_whitespace(char *buf) { if (!buf) { CEREBRO_DBG(("invalid parameters")); return NULL; } while (*buf != '\0' && isspace(*buf)) buf++; return buf; }
/* * _cerebro_namelist_iterator_check * * Checks for a proper cerebro namelist * * Returns 0 on success, -1 on error */ int _cerebro_namelist_iterator_check(cerebro_namelist_iterator_t namelistItr) { if (!namelistItr || namelistItr->magic != CEREBRO_NAMELIST_ITERATOR_MAGIC_NUMBER) return -1; if (!namelistItr->itr || !namelistItr->namelist) { CEREBRO_DBG(("invalid namelist iterator data")); namelistItr->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (namelistItr->namelist->magic != CEREBRO_NAMELIST_MAGIC_NUMBER) { CEREBRO_DBG(("namelist destroyed")); namelistItr->errnum = CEREBRO_ERR_MAGIC_NUMBER; return -1; } return 0; }
/* * hostsfile_clusterlist_node_in_cluster * * hostsfile clusterlist module node_in_cluster function */ static int hostsfile_clusterlist_node_in_cluster(const char *node) { char nodebuf[CEREBRO_MAX_NODENAME_LEN+1]; char *nodePtr = NULL; void *ptr; if (!hosts) { CEREBRO_DBG(("hosts null")); return -1; } if (!node) { CEREBRO_DBG(("invalid parameters")); return -1; } /* Shorten hostname if necessary */ if (strchr(node, '.')) { char *p; memset(nodebuf, '\0', CEREBRO_MAX_NODENAME_LEN+1); strncpy(nodebuf, node, CEREBRO_MAX_NODENAME_LEN); p = strchr(nodebuf, '.'); *p = '\0'; nodePtr = nodebuf; } else nodePtr = (char *)node; ptr = list_find_first(hosts, list_strcmp, nodePtr); return ((ptr) ? 1: 0); }