2 * collectd - src/mcelog.c
5 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Maryam Tahhan <maryam.tahhan@intel.com>
27 * Volodymyr Mytnyk <volodymyrx.mytnyk@intel.com>
28 * Taras Chornyi <tarasx.chornyi@intel.com>
29 * Krzysztof Matczak <krzysztofx.matczak@intel.com>
35 #include "utils_llist.h"
38 #include <sys/socket.h>
42 #define MCELOG_PLUGIN "mcelog"
43 #define MCELOG_BUFF_SIZE 1024
44 #define MCELOG_POLL_TIMEOUT 1000 /* ms */
45 #define MCELOG_SOCKET_STR "SOCKET"
46 #define MCELOG_DIMM_NAME "DMI_NAME"
47 #define MCELOG_CORRECTED_ERR "corrected memory errors"
48 #define MCELOG_UNCORRECTED_ERR "uncorrected memory errors"
49 #define MCELOG_CORRECTED_ERR_TIMED "corrected memory timed errors"
50 #define MCELOG_UNCORRECTED_ERR_TIMED "uncorrected memory timed errors"
51 #define MCELOG_CORRECTED_ERR_TYPE_INS "corrected_memory_errors"
52 #define MCELOG_UNCORRECTED_ERR_TYPE_INS "uncorrected_memory_errors"
54 typedef struct mcelog_config_s {
55 char logfile[PATH_MAX]; /* mcelog logfile */
56 pthread_t tid; /* poll thread id */
57 llist_t *dimms_list; /* DIMMs list */
58 /* lock for dimms cache */
60 pthread_mutex_t dimms_lock;
63 typedef struct socket_adapter_s socket_adapter_t;
65 struct socket_adapter_s {
66 int sock_fd; /* mcelog server socket fd */
67 struct sockaddr_un unix_sock; /* mcelog client socket */
68 pthread_rwlock_t lock;
69 /* function pointers for socket operations */
70 int (*write)(socket_adapter_t *self, const char *msg, const size_t len);
71 int (*reinit)(socket_adapter_t *self);
72 int (*receive)(socket_adapter_t *self, FILE **p_file);
73 int (*close)(socket_adapter_t *self);
76 typedef struct mcelog_memory_rec_s {
77 int corrected_err_total; /* x total*/
78 int corrected_err_timed; /* x in 24h*/
79 char corrected_err_timed_period[DATA_MAX_NAME_LEN];
80 int uncorrected_err_total; /* x total*/
81 int uncorrected_err_timed; /* x in 24h*/
82 char uncorrected_err_timed_period[DATA_MAX_NAME_LEN];
83 char location[DATA_MAX_NAME_LEN]; /* SOCKET x CHANNEL x DIMM x*/
84 char dimm_name[DATA_MAX_NAME_LEN]; /* DMI_NAME "DIMM_F1" */
85 } mcelog_memory_rec_t;
87 static int socket_close(socket_adapter_t *self);
88 static int socket_write(socket_adapter_t *self, const char *msg,
90 static int socket_reinit(socket_adapter_t *self);
91 static int socket_receive(socket_adapter_t *self, FILE **p_file);
93 static mcelog_config_t g_mcelog_config = {
94 .logfile = "/var/log/mcelog", .persist = 0,
97 static socket_adapter_t socket_adapter = {
101 .sun_family = AF_UNIX, .sun_path = "/var/run/mcelog-client",
103 .lock = PTHREAD_RWLOCK_INITIALIZER,
104 .close = socket_close,
105 .write = socket_write,
106 .reinit = socket_reinit,
107 .receive = socket_receive,
110 static _Bool mcelog_thread_running;
111 static _Bool mcelog_apply_defaults;
113 static void mcelog_free_dimms_list_records(llist_t *dimms_list) {
115 for (llentry_t *e = llist_head(dimms_list); e != NULL; e = e->next) {
121 /* Create or get dimm by dimm name/location */
122 static llentry_t *mcelog_dimm(const mcelog_memory_rec_t *rec,
123 llist_t *dimms_list) {
125 char dimm_name[DATA_MAX_NAME_LEN];
127 if (strlen(rec->dimm_name) > 0) {
128 ssnprintf(dimm_name, sizeof(dimm_name), "%s_%s", rec->location,
131 sstrncpy(dimm_name, rec->location, sizeof(dimm_name));
133 llentry_t *dimm_le = llist_search(g_mcelog_config.dimms_list, dimm_name);
135 if (dimm_le == NULL) {
136 mcelog_memory_rec_t *dimm_mr = calloc(1, sizeof(*dimm_mr));
137 if (dimm_mr == NULL) {
138 ERROR(MCELOG_PLUGIN ": Error allocating dimm memory item");
141 char *p_name = strdup(dimm_name);
142 if (p_name == NULL) {
143 ERROR(MCELOG_PLUGIN ": strdup: error");
149 dimm_le = llentry_create(p_name, dimm_mr);
150 if (dimm_le == NULL) {
151 ERROR(MCELOG_PLUGIN ": llentry_create(): error");
156 pthread_mutex_lock(&g_mcelog_config.dimms_lock);
157 llist_append(g_mcelog_config.dimms_list, dimm_le);
158 pthread_mutex_unlock(&g_mcelog_config.dimms_lock);
164 static void mcelog_update_dimm_stats(llentry_t *dimm,
165 const mcelog_memory_rec_t *rec) {
166 pthread_mutex_lock(&g_mcelog_config.dimms_lock);
167 memcpy(dimm->value, rec, sizeof(mcelog_memory_rec_t));
168 pthread_mutex_unlock(&g_mcelog_config.dimms_lock);
171 static int mcelog_config(oconfig_item_t *ci) {
172 int use_logfile = 0, use_memory = 0;
173 for (int i = 0; i < ci->children_num; i++) {
174 oconfig_item_t *child = ci->children + i;
175 if (strcasecmp("McelogLogfile", child->key) == 0) {
178 ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Memory "
179 "option is already configured.",
183 if (cf_util_get_string_buffer(child, g_mcelog_config.logfile,
184 sizeof(g_mcelog_config.logfile)) < 0) {
185 ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
189 memset(socket_adapter.unix_sock.sun_path, 0,
190 sizeof(socket_adapter.unix_sock.sun_path));
191 } else if (strcasecmp("Memory", child->key) == 0) {
193 ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Logfile "
194 "option is already configured.",
199 oconfig_item_t *mem_child = child->children;
200 for (int j = 0; j < child->children_num; j++) {
202 if (strcasecmp("McelogClientSocket", mem_child->key) == 0) {
203 if (cf_util_get_string_buffer(
204 mem_child, socket_adapter.unix_sock.sun_path,
205 sizeof(socket_adapter.unix_sock.sun_path)) < 0) {
206 ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
210 } else if (strcasecmp("PersistentNotification", mem_child->key) == 0) {
211 if (cf_util_get_boolean(mem_child, &g_mcelog_config.persist) < 0) {
212 ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
217 ERROR(MCELOG_PLUGIN ": Invalid Memory configuration option: \"%s\".",
222 memset(g_mcelog_config.logfile, 0, sizeof(g_mcelog_config.logfile));
224 ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
230 if (!use_logfile && !use_memory)
231 mcelog_apply_defaults = 1;
236 static int socket_close(socket_adapter_t *self) {
238 pthread_rwlock_rdlock(&self->lock);
239 if (fcntl(self->sock_fd, F_GETFL) != -1) {
240 char errbuf[MCELOG_BUFF_SIZE];
241 if (shutdown(self->sock_fd, SHUT_RDWR) != 0) {
242 ERROR(MCELOG_PLUGIN ": Socket shutdown failed: %s",
243 sstrerror(errno, errbuf, sizeof(errbuf)));
246 if (close(self->sock_fd) != 0) {
247 ERROR(MCELOG_PLUGIN ": Socket close failed: %s",
248 sstrerror(errno, errbuf, sizeof(errbuf)));
252 pthread_rwlock_unlock(&self->lock);
256 static int socket_write(socket_adapter_t *self, const char *msg,
259 pthread_rwlock_rdlock(&self->lock);
260 if (swrite(self->sock_fd, msg, len) < 0)
262 pthread_rwlock_unlock(&self->lock);
266 static void mcelog_dispatch_notification(notification_t *n) {
268 ERROR(MCELOG_PLUGIN ": %s: NULL pointer", __FUNCTION__);
272 sstrncpy(n->host, hostname_g, sizeof(n->host));
273 sstrncpy(n->type, "gauge", sizeof(n->type));
274 plugin_dispatch_notification(n);
276 plugin_notification_meta_free(n->meta);
279 static int socket_reinit(socket_adapter_t *self) {
280 char errbuff[MCELOG_BUFF_SIZE];
282 cdtime_t interval = plugin_get_interval();
283 struct timeval socket_timeout = CDTIME_T_TO_TIMEVAL(interval);
285 /* synchronization via write lock since sock_fd may be changed here */
286 pthread_rwlock_wrlock(&self->lock);
288 socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
289 if (self->sock_fd < 0) {
290 ERROR(MCELOG_PLUGIN ": Could not create a socket. %s",
291 sstrerror(errno, errbuff, sizeof(errbuff)));
292 pthread_rwlock_unlock(&self->lock);
296 /* Set socket timeout option */
297 if (setsockopt(self->sock_fd, SOL_SOCKET, SO_SNDTIMEO, &socket_timeout,
298 sizeof(socket_timeout)) < 0)
299 ERROR(MCELOG_PLUGIN ": Failed to set the socket timeout option.");
301 /* downgrading to read lock due to possible recursive read locks
302 * in self->close(self) call */
303 pthread_rwlock_unlock(&self->lock);
304 pthread_rwlock_rdlock(&self->lock);
305 if (connect(self->sock_fd, (struct sockaddr *)&(self->unix_sock),
306 sizeof(self->unix_sock)) < 0) {
307 ERROR(MCELOG_PLUGIN ": Failed to connect to mcelog server. %s",
308 sstrerror(errno, errbuff, sizeof(errbuff)));
313 mcelog_dispatch_notification(
314 &(notification_t){.severity = NOTIF_OKAY,
316 .message = "Connected to mcelog server",
317 .plugin = MCELOG_PLUGIN,
318 .type_instance = "mcelog_status"});
320 pthread_rwlock_unlock(&self->lock);
324 static int mcelog_dispatch_mem_notifications(const mcelog_memory_rec_t *mr) {
325 notification_t n = {.severity = NOTIF_WARNING,
327 .plugin = MCELOG_PLUGIN,
330 int dispatch_corrected_notifs = 0, dispatch_uncorrected_notifs = 0;
335 llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list);
338 ": Error adding/getting dimm memory item to/from cache");
341 mcelog_memory_rec_t *mr_old = dimm->value;
342 if (!g_mcelog_config.persist) {
344 if (mr_old->corrected_err_total != mr->corrected_err_total ||
345 mr_old->corrected_err_timed != mr->corrected_err_timed)
346 dispatch_corrected_notifs = 1;
348 if (mr_old->uncorrected_err_total != mr->uncorrected_err_total ||
349 mr_old->uncorrected_err_timed != mr->uncorrected_err_timed)
350 dispatch_uncorrected_notifs = 1;
352 if (!dispatch_corrected_notifs && !dispatch_uncorrected_notifs) {
353 DEBUG("%s: No new notifications to dispatch", MCELOG_PLUGIN);
357 dispatch_corrected_notifs = 1;
358 dispatch_uncorrected_notifs = 1;
361 sstrncpy(n.host, hostname_g, sizeof(n.host));
363 if (mr->dimm_name[0] != '\0')
364 ssnprintf(n.plugin_instance, sizeof(n.plugin_instance), "%s_%s",
365 mr->location, mr->dimm_name);
367 sstrncpy(n.plugin_instance, mr->location, sizeof(n.plugin_instance));
369 if (dispatch_corrected_notifs &&
370 (mr->corrected_err_total > 0 || mr->corrected_err_timed > 0)) {
371 /* Corrected Error Notifications */
372 plugin_notification_meta_add_signed_int(&n, MCELOG_CORRECTED_ERR,
373 mr->corrected_err_total);
374 plugin_notification_meta_add_signed_int(&n, MCELOG_CORRECTED_ERR_TIMED,
375 mr->corrected_err_timed);
376 ssnprintf(n.message, sizeof(n.message), MCELOG_CORRECTED_ERR);
377 sstrncpy(n.type_instance, MCELOG_CORRECTED_ERR_TYPE_INS,
378 sizeof(n.type_instance));
379 plugin_dispatch_notification(&n);
381 plugin_notification_meta_free(n.meta);
385 if (dispatch_uncorrected_notifs &&
386 (mr->uncorrected_err_total > 0 || mr->uncorrected_err_timed > 0)) {
387 /* Uncorrected Error Notifications */
388 plugin_notification_meta_add_signed_int(&n, MCELOG_UNCORRECTED_ERR,
389 mr->uncorrected_err_total);
390 plugin_notification_meta_add_signed_int(&n, MCELOG_UNCORRECTED_ERR_TIMED,
391 mr->uncorrected_err_timed);
392 ssnprintf(n.message, sizeof(n.message), MCELOG_UNCORRECTED_ERR);
393 sstrncpy(n.type_instance, MCELOG_UNCORRECTED_ERR_TYPE_INS,
394 sizeof(n.type_instance));
395 n.severity = NOTIF_FAILURE;
396 plugin_dispatch_notification(&n);
398 plugin_notification_meta_free(n.meta);
405 static int mcelog_submit(const mcelog_memory_rec_t *mr) {
408 ERROR(MCELOG_PLUGIN ": %s: NULL pointer", __FUNCTION__);
412 llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list);
415 ": Error adding/getting dimm memory item to/from cache");
421 .values = &(value_t){.derive = (derive_t)mr->corrected_err_total},
423 .plugin = MCELOG_PLUGIN,
425 .type_instance = MCELOG_CORRECTED_ERR_TYPE_INS};
427 mcelog_update_dimm_stats(dimm, mr);
429 if (mr->dimm_name[0] != '\0')
430 ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
431 mr->location, mr->dimm_name);
433 sstrncpy(vl.plugin_instance, mr->location, sizeof(vl.plugin_instance));
435 plugin_dispatch_values(&vl);
437 ssnprintf(vl.type_instance, sizeof(vl.type_instance),
438 "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
439 vl.values = &(value_t){.derive = (derive_t)mr->corrected_err_timed};
440 plugin_dispatch_values(&vl);
442 sstrncpy(vl.type_instance, MCELOG_UNCORRECTED_ERR_TYPE_INS,
443 sizeof(vl.type_instance));
444 vl.values = &(value_t){.derive = (derive_t)mr->uncorrected_err_total};
445 plugin_dispatch_values(&vl);
447 ssnprintf(vl.type_instance, sizeof(vl.type_instance),
448 "uncorrected_memory_errors_in_%s",
449 mr->uncorrected_err_timed_period);
450 vl.values = &(value_t){.derive = (derive_t)mr->uncorrected_err_timed};
451 plugin_dispatch_values(&vl);
456 static int parse_memory_info(FILE *p_file, mcelog_memory_rec_t *memory_record) {
457 char buf[DATA_MAX_NAME_LEN] = {0};
458 while (fgets(buf, sizeof(buf), p_file)) {
459 /* Got empty line or "done" */
460 if ((!strncmp("\n", buf, strlen(buf))) ||
461 (!strncmp(buf, "done\n", strlen(buf))))
465 if (!strncmp(buf, MCELOG_SOCKET_STR, strlen(MCELOG_SOCKET_STR))) {
466 sstrncpy(memory_record->location, buf, strlen(buf));
467 /* replace spaces with '_' */
468 for (size_t i = 0; i < strlen(memory_record->location); i++)
469 if (memory_record->location[i] == ' ')
470 memory_record->location[i] = '_';
471 DEBUG(MCELOG_PLUGIN ": Got SOCKET INFO %s", memory_record->location);
473 if (!strncmp(buf, MCELOG_DIMM_NAME, strlen(MCELOG_DIMM_NAME))) {
475 char *saveptr = NULL;
476 name = strtok_r(buf, "\"", &saveptr);
477 if (name != NULL && saveptr != NULL) {
478 name = strtok_r(NULL, "\"", &saveptr);
480 sstrncpy(memory_record->dimm_name, name,
481 sizeof(memory_record->dimm_name));
482 DEBUG(MCELOG_PLUGIN ": Got DIMM NAME %s", memory_record->dimm_name);
486 if (!strncmp(buf, MCELOG_CORRECTED_ERR, strlen(MCELOG_CORRECTED_ERR))) {
488 if (fgets(buf, sizeof(buf), p_file) != NULL) {
489 sscanf(buf, "\t%d total", &(memory_record->corrected_err_total));
490 DEBUG(MCELOG_PLUGIN ": Got corrected error total %d",
491 memory_record->corrected_err_total);
493 if (fgets(buf, sizeof(buf), p_file) != NULL) {
494 sscanf(buf, "\t%d in %s", &(memory_record->corrected_err_timed),
495 memory_record->corrected_err_timed_period);
496 DEBUG(MCELOG_PLUGIN ": Got timed corrected errors %d in %s",
497 memory_record->corrected_err_total,
498 memory_record->corrected_err_timed_period);
501 if (!strncmp(buf, MCELOG_UNCORRECTED_ERR, strlen(MCELOG_UNCORRECTED_ERR))) {
502 if (fgets(buf, sizeof(buf), p_file) != NULL) {
503 sscanf(buf, "\t%d total", &(memory_record->uncorrected_err_total));
504 DEBUG(MCELOG_PLUGIN ": Got uncorrected error total %d",
505 memory_record->uncorrected_err_total);
507 if (fgets(buf, sizeof(buf), p_file) != NULL) {
508 sscanf(buf, "\t%d in %s", &(memory_record->uncorrected_err_timed),
509 memory_record->uncorrected_err_timed_period);
510 DEBUG(MCELOG_PLUGIN ": Got timed uncorrected errors %d in %s",
511 memory_record->uncorrected_err_total,
512 memory_record->uncorrected_err_timed_period);
515 memset(buf, 0, sizeof(buf));
517 /* parsing definitely finished */
521 static void poll_worker_cleanup(void *arg) {
522 mcelog_thread_running = 0;
523 FILE *p_file = *((FILE **)arg);
529 static int socket_receive(socket_adapter_t *self, FILE **pp_file) {
531 pthread_rwlock_rdlock(&self->lock);
532 struct pollfd poll_fd = {
533 .fd = self->sock_fd, .events = POLLIN | POLLPRI,
536 if ((res = poll(&poll_fd, 1, MCELOG_POLL_TIMEOUT)) <= 0) {
537 if (res != 0 && errno != EINTR) {
538 char errbuf[MCELOG_BUFF_SIZE];
539 ERROR("mcelog: poll failed: %s",
540 sstrerror(errno, errbuf, sizeof(errbuf)));
542 pthread_rwlock_unlock(&self->lock);
546 if (poll_fd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
547 /* connection is broken */
548 ERROR(MCELOG_PLUGIN ": Connection to socket is broken");
549 if (poll_fd.revents & (POLLERR | POLLHUP)) {
550 mcelog_dispatch_notification(
551 &(notification_t){.severity = NOTIF_FAILURE,
553 .message = "Connection to mcelog socket is broken.",
554 .plugin = MCELOG_PLUGIN,
555 .type_instance = "mcelog_status"});
557 pthread_rwlock_unlock(&self->lock);
561 if (!(poll_fd.revents & (POLLIN | POLLPRI))) {
562 INFO(MCELOG_PLUGIN ": No data to read");
563 pthread_rwlock_unlock(&self->lock);
567 if ((*pp_file = fdopen(dup(self->sock_fd), "r")) == NULL)
570 pthread_rwlock_unlock(&self->lock);
574 static void *poll_worker(__attribute__((unused)) void *arg) {
575 char errbuf[MCELOG_BUFF_SIZE];
576 mcelog_thread_running = 1;
577 FILE **pp_file = calloc(1, sizeof(*pp_file));
578 if (pp_file == NULL) {
579 ERROR("mcelog: memory allocation failed: %s",
580 sstrerror(errno, errbuf, sizeof(errbuf)));
581 pthread_exit((void *)1);
584 pthread_cleanup_push(poll_worker_cleanup, pp_file);
588 int res = socket_adapter.receive(&socket_adapter, pp_file);
590 socket_adapter.close(&socket_adapter);
591 while (socket_adapter.reinit(&socket_adapter) != 0) {
592 nanosleep(&CDTIME_T_TO_TIMESPEC(MS_TO_CDTIME_T(MCELOG_POLL_TIMEOUT)),
597 /* timeout or no data to read */
601 if (*pp_file == NULL)
604 mcelog_memory_rec_t memory_record = {0};
605 while (parse_memory_info(*pp_file, &memory_record)) {
606 /* Check if location was successfully parsed */
607 if (memory_record.location[0] == '\0') {
608 memset(&memory_record, 0, sizeof(memory_record));
612 if (mcelog_dispatch_mem_notifications(&memory_record) != 0)
613 ERROR(MCELOG_PLUGIN ": Failed to submit memory errors notification");
614 if (mcelog_submit(&memory_record) != 0)
615 ERROR(MCELOG_PLUGIN ": Failed to submit memory errors");
616 memset(&memory_record, 0, sizeof(memory_record));
623 mcelog_thread_running = 0;
624 pthread_cleanup_pop(1);
628 static int mcelog_init(void) {
629 if (mcelog_apply_defaults) {
631 ": No configuration selected defaulting to memory errors.");
632 memset(g_mcelog_config.logfile, 0, sizeof(g_mcelog_config.logfile));
634 g_mcelog_config.dimms_list = llist_create();
635 int err = pthread_mutex_init(&g_mcelog_config.dimms_lock, NULL);
637 ERROR(MCELOG_PLUGIN ": plugin: failed to initialize cache lock");
641 if (socket_adapter.reinit(&socket_adapter) != 0) {
642 ERROR(MCELOG_PLUGIN ": Cannot connect to client socket");
646 if (strlen(socket_adapter.unix_sock.sun_path)) {
647 if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL,
649 ERROR(MCELOG_PLUGIN ": Error creating poll thread.");
656 static int get_memory_machine_checks(void) {
657 static const char dump[] = "dump all bios\n";
658 int ret = socket_adapter.write(&socket_adapter, dump, sizeof(dump));
660 ERROR(MCELOG_PLUGIN ": SENT DUMP REQUEST FAILED");
662 DEBUG(MCELOG_PLUGIN ": SENT DUMP REQUEST OK");
666 static int mcelog_read(__attribute__((unused)) user_data_t *ud) {
667 DEBUG(MCELOG_PLUGIN ": %s", __FUNCTION__);
669 if (get_memory_machine_checks() != 0)
670 ERROR(MCELOG_PLUGIN ": MACHINE CHECK INFO NOT AVAILABLE");
675 static int mcelog_shutdown(void) {
677 if (mcelog_thread_running) {
678 pthread_cancel(g_mcelog_config.tid);
679 if (pthread_join(g_mcelog_config.tid, NULL) != 0) {
680 ERROR(MCELOG_PLUGIN ": Stopping thread failed.");
684 pthread_mutex_lock(&g_mcelog_config.dimms_lock);
685 mcelog_free_dimms_list_records(g_mcelog_config.dimms_list);
686 llist_destroy(g_mcelog_config.dimms_list);
687 g_mcelog_config.dimms_list = NULL;
688 pthread_mutex_unlock(&g_mcelog_config.dimms_lock);
689 pthread_mutex_destroy(&g_mcelog_config.dimms_lock);
690 ret = socket_adapter.close(&socket_adapter) || ret;
691 pthread_rwlock_destroy(&(socket_adapter.lock));
695 void module_register(void) {
696 plugin_register_complex_config(MCELOG_PLUGIN, mcelog_config);
697 plugin_register_init(MCELOG_PLUGIN, mcelog_init);
698 plugin_register_complex_read(NULL, MCELOG_PLUGIN, mcelog_read, 0, NULL);
699 plugin_register_shutdown(MCELOG_PLUGIN, mcelog_shutdown);