X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fipc.c;h=93eddaf86302423790bd6ab273db4228fde50a22;hb=d93c31e59d1bbb5ed8c2ef624ef8ffa800bc5961;hp=97d71429bffe02b3a886606546b6dffc77b6151d;hpb=336c5c5170b65c3983bf98e9b114759cce1de54c;p=collectd.git diff --git a/src/ipc.c b/src/ipc.c index 97d71429..93eddaf8 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -28,8 +28,8 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #if KERNEL_LINUX /* _GNU_SOURCE is needed for struct shm_info.used_ids on musl libc */ @@ -95,14 +95,10 @@ __attribute__((nonnull(1))) static void ipc_submit_g(const char *plugin_instance, const char *type, const char *type_instance, gauge_t value) /* {{{ */ { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t){.gauge = value}; vl.values_len = 1; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "ipc", sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, type, sizeof(vl.type)); @@ -123,17 +119,16 @@ static int ipc_read_sem(void) /* {{{ */ status = semctl(/* id = */ 0, /* num = */ 0, SEM_INFO, arg); if (status == -1) { - char errbuf[1024]; ERROR("ipc plugin: semctl(2) failed: %s. " "Maybe the kernel is not configured for semaphores?", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + STRERRNO); + return -1; } ipc_submit_g("sem", "count", "arrays", seminfo.semusz); ipc_submit_g("sem", "count", "total", seminfo.semaem); - return (0); + return 0; } /* }}} int ipc_read_sem */ static int ipc_read_shm(void) /* {{{ */ @@ -143,18 +138,17 @@ static int ipc_read_shm(void) /* {{{ */ status = shmctl(/* id = */ 0, SHM_INFO, (void *)&shm_info); if (status == -1) { - char errbuf[1024]; ERROR("ipc plugin: shmctl(2) failed: %s. " "Maybe the kernel is not configured for shared memory?", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + STRERRNO); + return -1; } ipc_submit_g("shm", "segments", NULL, shm_info.used_ids); ipc_submit_g("shm", "bytes", "total", shm_info.shm_tot * pagesize_g); ipc_submit_g("shm", "bytes", "rss", shm_info.shm_rss * pagesize_g); ipc_submit_g("shm", "bytes", "swapped", shm_info.shm_swp * pagesize_g); - return (0); + return 0; } /* }}} int ipc_read_shm */ @@ -164,23 +158,23 @@ static int ipc_read_msg(void) /* {{{ */ if (msgctl(0, MSG_INFO, (struct msqid_ds *)(void *)&msginfo) < 0) { ERROR("Kernel is not configured for message queues"); - return (-1); + return -1; } ipc_submit_g("msg", "count", "queues", msginfo.msgmni); ipc_submit_g("msg", "count", "headers", msginfo.msgmap); ipc_submit_g("msg", "count", "space", msginfo.msgtql); - return (0); + return 0; } /* }}} int ipc_read_msg */ static int ipc_init(void) /* {{{ */ { pagesize_g = sysconf(_SC_PAGESIZE); - return (0); + return 0; } -/* }}} */ -/* #endif KERNEL_LINUX */ + /* }}} */ + /* #endif KERNEL_LINUX */ #elif KERNEL_AIX static caddr_t ipc_get_info(cid_t cid, int cmd, int version, int stsize, @@ -191,10 +185,8 @@ static caddr_t ipc_get_info(cid_t cid, int cmd, int version, int stsize, if (get_ipc_info(cid, cmd, version, buff, &size) < 0) { if (errno != ENOSPC) { - char errbuf[1024]; - WARNING("ipc plugin: get_ipc_info: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (NULL); + WARNING("ipc plugin: get_ipc_info: %s", STRERRNO); + return NULL; } } @@ -203,7 +195,7 @@ static caddr_t ipc_get_info(cid_t cid, int cmd, int version, int stsize, if (size % stsize) { ERROR("ipc plugin: ipc_get_info: missmatch struct size and buffer size"); - return (NULL); + return NULL; } *nmemb = size / stsize; @@ -211,15 +203,13 @@ static caddr_t ipc_get_info(cid_t cid, int cmd, int version, int stsize, buff = malloc(size); if (buff == NULL) { ERROR("ipc plugin: ipc_get_info malloc failed."); - return (NULL); + return NULL; } if (get_ipc_info(cid, cmd, version, buff, &size) < 0) { - char errbuf[1024]; - WARNING("ipc plugin: get_ipc_info: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + WARNING("ipc plugin: get_ipc_info: %s", STRERRNO); free(buff); - return (NULL); + return NULL; } return buff; @@ -246,7 +236,7 @@ static int ipc_read_sem(void) /* {{{ */ ipc_submit_g("sem", "count", "arrays", sem_nsems); ipc_submit_g("sem", "count", "total", sems); - return (0); + return 0; } /* }}} int ipc_read_sem */ static int ipc_read_shm(void) /* {{{ */ @@ -271,7 +261,7 @@ static int ipc_read_shm(void) /* {{{ */ ipc_submit_g("shm", "segments", NULL, shm_segments); ipc_submit_g("shm", "bytes", "total", shm_bytes); - return (0); + return 0; } /* }}} int ipc_read_shm */ @@ -299,7 +289,7 @@ static int ipc_read_msg(void) /* {{{ */ ipc_submit_g("msg", "count", "headers", msg_qnum); ipc_submit_g("msg", "count", "space", msg_used_space); - return (0); + return 0; } /* }}} */ #endif /* KERNEL_AIX */ @@ -311,7 +301,7 @@ static int ipc_read(void) /* {{{ */ x |= ipc_read_sem(); x |= ipc_read_msg(); - return (x); + return x; } /* }}} */ @@ -323,5 +313,3 @@ void module_register(void) /* {{{ */ plugin_register_read("ipc", ipc_read); } /* }}} */ - -/* vim: set sw=2 sts=2 et fdm=marker : */