- char logfile[PATH_MAX]; /* mcelog logfile */
- pthread_t tid; /* poll thread id */
- llist_t *dimms_list; /* DIMMs list */
- /* lock for dimms cache */
+ char logfile[PATH_MAX]; /* mcelog logfile */
+ pthread_t tid; /* poll thread id */
+ llist_t *dimms_list; /* DIMMs list */
+ pthread_mutex_t dimms_lock; /* lock for dimms cache */
typedef struct mcelog_memory_rec_s {
int corrected_err_total; /* x total*/
int corrected_err_timed; /* x in 24h*/
typedef struct mcelog_memory_rec_s {
int corrected_err_total; /* x total*/
int corrected_err_timed; /* x in 24h*/
- char uncorrected_err_timed_period[DATA_MAX_NAME_LEN];
- char location[DATA_MAX_NAME_LEN]; /* SOCKET x CHANNEL x DIMM x*/
- char dimm_name[DATA_MAX_NAME_LEN]; /* DMI_NAME "DIMM_F1" */
+ char uncorrected_err_timed_period[DATA_MAX_NAME_LEN / 2];
+ char location[DATA_MAX_NAME_LEN / 2]; /* SOCKET x CHANNEL x DIMM x*/
+ char dimm_name[DATA_MAX_NAME_LEN / 2]; /* DMI_NAME "DIMM_F1" */
- ssnprintf(dimm_name, sizeof(dimm_name), "%s_%s", rec->location,
- rec->dimm_name);
+ snprintf(dimm_name, sizeof(dimm_name), "%s_%s", rec->location,
+ rec->dimm_name);
} else
sstrncpy(dimm_name, rec->location, sizeof(dimm_name));
llentry_t *dimm_le = llist_search(g_mcelog_config.dimms_list, dimm_name);
} else
sstrncpy(dimm_name, rec->location, sizeof(dimm_name));
llentry_t *dimm_le = llist_search(g_mcelog_config.dimms_list, dimm_name);
- if (dimm_le == NULL) {
- mcelog_memory_rec_t *dimm_mr = calloc(1, sizeof(*dimm_mr));
- if (dimm_mr == NULL) {
- ERROR(MCELOG_PLUGIN ": Error allocating dimm memory item");
- return NULL;
- }
- char *p_name = strdup(dimm_name);
- if (p_name == NULL) {
- ERROR(MCELOG_PLUGIN ": strdup: error");
- free(dimm_mr);
- return NULL;
- }
+ if (dimm_le != NULL)
+ return dimm_le;
- /* add new dimm */
- dimm_le = llentry_create(p_name, dimm_mr);
- if (dimm_le == NULL) {
- ERROR(MCELOG_PLUGIN ": llentry_create(): error");
- free(dimm_mr);
- free(p_name);
- return NULL;
- }
- pthread_mutex_lock(&g_mcelog_config.dimms_lock);
- llist_append(g_mcelog_config.dimms_list, dimm_le);
- pthread_mutex_unlock(&g_mcelog_config.dimms_lock);
+ /* allocate new linked list entry */
+ mcelog_memory_rec_t *dimm_mr = calloc(1, sizeof(*dimm_mr));
+ if (dimm_mr == NULL) {
+ ERROR(MCELOG_PLUGIN ": Error allocating dimm memory item");
+ return NULL;
+ }
+ char *p_name = strdup(dimm_name);
+ if (p_name == NULL) {
+ ERROR(MCELOG_PLUGIN ": strdup: error");
+ free(dimm_mr);
+ return NULL;
+ /* add new dimm */
+ dimm_le = llentry_create(p_name, dimm_mr);
+ if (dimm_le == NULL) {
+ ERROR(MCELOG_PLUGIN ": llentry_create(): error");
+ free(dimm_mr);
+ free(p_name);
+ return NULL;
+ }
+ pthread_mutex_lock(&g_mcelog_config.dimms_lock);
+ llist_append(g_mcelog_config.dimms_list, dimm_le);
+ pthread_mutex_unlock(&g_mcelog_config.dimms_lock);
+
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Memory "
"option is already configured.",
child->key);
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Memory "
"option is already configured.",
child->key);
}
if (cf_util_get_string_buffer(child, g_mcelog_config.logfile,
sizeof(g_mcelog_config.logfile)) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
if (cf_util_get_string_buffer(child, g_mcelog_config.logfile,
sizeof(g_mcelog_config.logfile)) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
memset(socket_adapter.unix_sock.sun_path, 0,
sizeof(socket_adapter.unix_sock.sun_path));
}
memset(socket_adapter.unix_sock.sun_path, 0,
sizeof(socket_adapter.unix_sock.sun_path));
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Logfile "
"option is already configured.",
child->key);
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Logfile "
"option is already configured.",
child->key);
if (strcasecmp("McelogClientSocket", mem_child->key) == 0) {
if (cf_util_get_string_buffer(
mem_child, socket_adapter.unix_sock.sun_path,
sizeof(socket_adapter.unix_sock.sun_path)) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
mem_child->key);
if (strcasecmp("McelogClientSocket", mem_child->key) == 0) {
if (cf_util_get_string_buffer(
mem_child, socket_adapter.unix_sock.sun_path,
sizeof(socket_adapter.unix_sock.sun_path)) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
mem_child->key);
}
} else if (strcasecmp("PersistentNotification", mem_child->key) == 0) {
if (cf_util_get_boolean(mem_child, &g_mcelog_config.persist) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
mem_child->key);
}
} else if (strcasecmp("PersistentNotification", mem_child->key) == 0) {
if (cf_util_get_boolean(mem_child, &g_mcelog_config.persist) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
mem_child->key);
}
}
memset(g_mcelog_config.logfile, 0, sizeof(g_mcelog_config.logfile));
} else {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
}
memset(g_mcelog_config.logfile, 0, sizeof(g_mcelog_config.logfile));
} else {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
static int socket_write(socket_adapter_t *self, const char *msg,
const size_t len) {
int ret = 0;
pthread_rwlock_rdlock(&self->lock);
}
static int socket_write(socket_adapter_t *self, const char *msg,
const size_t len) {
int ret = 0;
pthread_rwlock_rdlock(&self->lock);
ERROR(MCELOG_PLUGIN ": Could not create a socket. %s",
sstrerror(errno, errbuff, sizeof(errbuff)));
pthread_rwlock_unlock(&self->lock);
ERROR(MCELOG_PLUGIN ": Could not create a socket. %s",
sstrerror(errno, errbuff, sizeof(errbuff)));
pthread_rwlock_unlock(&self->lock);
llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list);
if (dimm == NULL) {
ERROR(MCELOG_PLUGIN
": Error adding/getting dimm memory item to/from cache");
llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list);
if (dimm == NULL) {
ERROR(MCELOG_PLUGIN
": Error adding/getting dimm memory item to/from cache");
if (!dispatch_corrected_notifs && !dispatch_uncorrected_notifs) {
DEBUG("%s: No new notifications to dispatch", MCELOG_PLUGIN);
if (!dispatch_corrected_notifs && !dispatch_uncorrected_notifs) {
DEBUG("%s: No new notifications to dispatch", MCELOG_PLUGIN);
sstrncpy(n.host, hostname_g, sizeof(n.host));
if (mr->dimm_name[0] != '\0')
sstrncpy(n.host, hostname_g, sizeof(n.host));
if (mr->dimm_name[0] != '\0')
- ssnprintf(n.plugin_instance, sizeof(n.plugin_instance), "%s_%s",
- mr->location, mr->dimm_name);
+ snprintf(n.plugin_instance, sizeof(n.plugin_instance), "%s_%s",
+ mr->location, mr->dimm_name);
mr->corrected_err_total);
plugin_notification_meta_add_signed_int(&n, MCELOG_CORRECTED_ERR_TIMED,
mr->corrected_err_timed);
mr->corrected_err_total);
plugin_notification_meta_add_signed_int(&n, MCELOG_CORRECTED_ERR_TIMED,
mr->corrected_err_timed);
sstrncpy(n.type_instance, MCELOG_CORRECTED_ERR_TYPE_INS,
sizeof(n.type_instance));
plugin_dispatch_notification(&n);
sstrncpy(n.type_instance, MCELOG_CORRECTED_ERR_TYPE_INS,
sizeof(n.type_instance));
plugin_dispatch_notification(&n);
mr->uncorrected_err_total);
plugin_notification_meta_add_signed_int(&n, MCELOG_UNCORRECTED_ERR_TIMED,
mr->uncorrected_err_timed);
mr->uncorrected_err_total);
plugin_notification_meta_add_signed_int(&n, MCELOG_UNCORRECTED_ERR_TIMED,
mr->uncorrected_err_timed);
sstrncpy(n.type_instance, MCELOG_UNCORRECTED_ERR_TYPE_INS,
sizeof(n.type_instance));
n.severity = NOTIF_FAILURE;
sstrncpy(n.type_instance, MCELOG_UNCORRECTED_ERR_TYPE_INS,
sizeof(n.type_instance));
n.severity = NOTIF_FAILURE;
}
static int mcelog_submit(const mcelog_memory_rec_t *mr) {
if (!mr) {
ERROR(MCELOG_PLUGIN ": %s: NULL pointer", __FUNCTION__);
}
static int mcelog_submit(const mcelog_memory_rec_t *mr) {
if (!mr) {
ERROR(MCELOG_PLUGIN ": %s: NULL pointer", __FUNCTION__);
}
llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list);
if (dimm == NULL) {
ERROR(MCELOG_PLUGIN
": Error adding/getting dimm memory item to/from cache");
}
llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list);
if (dimm == NULL) {
ERROR(MCELOG_PLUGIN
": Error adding/getting dimm memory item to/from cache");
mcelog_update_dimm_stats(dimm, mr);
if (mr->dimm_name[0] != '\0')
mcelog_update_dimm_stats(dimm, mr);
if (mr->dimm_name[0] != '\0')
- ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
- mr->location, mr->dimm_name);
+ snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
+ mr->location, mr->dimm_name);
else
sstrncpy(vl.plugin_instance, mr->location, sizeof(vl.plugin_instance));
plugin_dispatch_values(&vl);
else
sstrncpy(vl.plugin_instance, mr->location, sizeof(vl.plugin_instance));
plugin_dispatch_values(&vl);
- ssnprintf(vl.type_instance, sizeof(vl.type_instance),
- "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
+ snprintf(vl.type_instance, sizeof(vl.type_instance),
+ "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
- ssnprintf(vl.type_instance, sizeof(vl.type_instance),
- "uncorrected_memory_errors_in_%s",
- mr->uncorrected_err_timed_period);
+ snprintf(vl.type_instance, sizeof(vl.type_instance),
+ "uncorrected_memory_errors_in_%s", mr->uncorrected_err_timed_period);
/* Got empty line or "done" */
if ((!strncmp("\n", buf, strlen(buf))) ||
(!strncmp(buf, "done\n", strlen(buf))))
/* Got empty line or "done" */
if ((!strncmp("\n", buf, strlen(buf))) ||
(!strncmp(buf, "done\n", strlen(buf))))
memset(buf, 0, sizeof(buf));
}
/* parsing definitely finished */
memset(buf, 0, sizeof(buf));
}
/* parsing definitely finished */
sstrerror(errno, errbuf, sizeof(errbuf)));
}
pthread_rwlock_unlock(&self->lock);
sstrerror(errno, errbuf, sizeof(errbuf)));
}
pthread_rwlock_unlock(&self->lock);
}
if (!(poll_fd.revents & (POLLIN | POLLPRI))) {
INFO(MCELOG_PLUGIN ": No data to read");
pthread_rwlock_unlock(&self->lock);
}
if (!(poll_fd.revents & (POLLIN | POLLPRI))) {
INFO(MCELOG_PLUGIN ": No data to read");
pthread_rwlock_unlock(&self->lock);
}
if ((*pp_file = fdopen(dup(self->sock_fd), "r")) == NULL)
res = -1;
pthread_rwlock_unlock(&self->lock);
}
if ((*pp_file = fdopen(dup(self->sock_fd), "r")) == NULL)
res = -1;
pthread_rwlock_unlock(&self->lock);
int err = pthread_mutex_init(&g_mcelog_config.dimms_lock, NULL);
if (err < 0) {
ERROR(MCELOG_PLUGIN ": plugin: failed to initialize cache lock");
int err = pthread_mutex_init(&g_mcelog_config.dimms_lock, NULL);
if (err < 0) {
ERROR(MCELOG_PLUGIN ": plugin: failed to initialize cache lock");
}
if (socket_adapter.reinit(&socket_adapter) != 0) {
ERROR(MCELOG_PLUGIN ": Cannot connect to client socket");
}
if (socket_adapter.reinit(&socket_adapter) != 0) {
ERROR(MCELOG_PLUGIN ": Cannot connect to client socket");
}
if (strlen(socket_adapter.unix_sock.sun_path)) {
if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL,
NULL) != 0) {
ERROR(MCELOG_PLUGIN ": Error creating poll thread.");
}
if (strlen(socket_adapter.unix_sock.sun_path)) {
if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL,
NULL) != 0) {
ERROR(MCELOG_PLUGIN ": Error creating poll thread.");
pthread_mutex_destroy(&g_mcelog_config.dimms_lock);
ret = socket_adapter.close(&socket_adapter) || ret;
pthread_rwlock_destroy(&(socket_adapter.lock));
pthread_mutex_destroy(&g_mcelog_config.dimms_lock);
ret = socket_adapter.close(&socket_adapter) || ret;
pthread_rwlock_destroy(&(socket_adapter.lock));