status = amqp_socket_open(socket, CONF(conf, host), conf->port);
if (status < 0) {
- char errbuf[1024];
status *= -1;
- ERROR("amqp plugin: amqp_socket_open failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: amqp_socket_open failed: %s", STRERROR(status));
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
return status;
/* this interface is deprecated as of rabbitmq-c 0.4 */
sockfd = amqp_open_socket(CONF(conf, host), conf->port);
if (sockfd < 0) {
- char errbuf[1024];
status = (-1) * sockfd;
- ERROR("amqp plugin: amqp_open_socket failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: amqp_open_socket failed: %s", STRERROR(status));
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
return status;
static int camqp_shutdown(void) /* {{{ */
{
- DEBUG("amqp plugin: Shutting down %zu subscriber threads.",
+ DEBUG("amqp plugin: Shutting down %" PRIsz " subscriber threads.",
subscriber_threads_num);
subscriber_threads_running = 0;
while (received < body_size) {
status = amqp_simple_wait_frame(conf->connection, &frame);
if (status < 0) {
- char errbuf[1024];
status = (-1) * status;
- ERROR("amqp plugin: amqp_simple_wait_frame failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: amqp_simple_wait_frame failed: %s", STRERROR(status));
camqp_close_connection(conf);
return status;
}
status = amqp_simple_wait_frame(conf->connection, &frame);
if (status < 0) {
- char errbuf[1024];
status = (-1) * status;
- ERROR("amqp plugin: amqp_simple_wait_frame failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: amqp_simple_wait_frame failed: %s", STRERROR(status));
camqp_close_connection(conf);
return status;
}
status = plugin_thread_create(tmp, /* attr = */ NULL, camqp_subscribe_thread,
conf, "amqp subscribe");
if (status != 0) {
- char errbuf[1024];
- ERROR("amqp plugin: pthread_create failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: pthread_create failed: %s", STRERROR(status));
return status;
}
continue;
}
- DEBUG(
- "barometer: get_reference_temperature - initialize \"%s\", %zu vals",
- list->sensor_name, values_num);
+ DEBUG("barometer: get_reference_temperature - initialize \"%s\", %" PRIsz
+ " vals",
+ list->sensor_name, values_num);
list->initialized = 1;
list->num_values = values_num;
for (size_t i = 0; i < values_num; ++i) {
- DEBUG("barometer: get_reference_temperature - rate %zu: %lf **", i,
- values[i]);
+ DEBUG("barometer: get_reference_temperature - rate %" PRIsz ": %lf **",
+ i, values[i]);
if (!isnan(values[i])) {
avg_sum += values[i];
++avg_num;
}
for (size_t i = 0; i < REF_TEMP_AVG_NUM * list->num_values; ++i) {
- DEBUG("barometer: get_reference_temperature - history %zu: %lf", i,
+ DEBUG("barometer: get_reference_temperature - history %" PRIsz ": %lf", i,
values_history[i]);
if (!isnan(values_history[i])) {
avg_sum += values_history[i];
}
for (size_t i = 0; i < values_num; ++i) {
- DEBUG("barometer: get_reference_temperature - rate last %zu: %lf **", i,
- values[i]);
+ DEBUG("barometer: get_reference_temperature - rate last %" PRIsz
+ ": %lf **",
+ i, values[i]);
if (!isnan(values[i])) {
avg_sum += values[i];
++avg_num;
*/
static int MPL115_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL115_I2C_ADDRESS) < 0) {
ERROR("barometer: MPL115_detect problem setting i2c slave address to "
"0x%02X: %s",
- MPL115_I2C_ADDRESS, sstrerror(errno, errbuf, sizeof(errbuf)));
+ MPL115_I2C_ADDRESS, STRERRNO);
return 0;
}
int8_t sic12MSB, sic12LSB, sic11MSB, sic11LSB, sic22MSB, sic22LSB;
int16_t sia0, sib1, sib2, sic12, sic11, sic22;
- char errbuf[1024];
-
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, MPL115_ADDR_COEFFS,
STATIC_ARRAY_SIZE(mpl115_coeffs),
mpl115_coeffs);
if (res < 0) {
- ERROR("barometer: MPL115_read_coeffs - problem reading data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL115_read_coeffs - problem reading data: %s", STRERRNO);
return -1;
}
int conv_temperature;
double adc_pressure;
double adc_temperature;
- char errbuf[1024];
*pressure = 0.0;
*temperature = 0.0;
if (retries > 0) {
ERROR("barometer: MPL115_read_averaged - requesting conversion: %s, "
"will retry at most %d more times",
- sstrerror(errno, errbuf, sizeof(errbuf)), retries);
+ STRERRNO, retries);
} else {
ERROR("barometer: MPL115_read_averaged - requesting conversion: %s, "
"too many failed retries",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
}
if (retries > 0) {
ERROR("barometer: MPL115_read_averaged - reading conversion: %s, "
"will retry at most %d more times",
- sstrerror(errno, errbuf, sizeof(errbuf)), retries);
+ STRERRNO, retries);
} else {
ERROR("barometer: MPL115_read_averaged - reading conversion: %s, "
"too many failed retries",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
}
*/
static int MPL3115_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL3115_I2C_ADDRESS) < 0) {
ERROR("barometer: MPL3115_detect problem setting i2c slave address to "
"0x%02X: %s",
- MPL3115_I2C_ADDRESS, sstrerror(errno, errbuf, sizeof(errbuf)));
+ MPL3115_I2C_ADDRESS, STRERRNO);
return 0;
}
__s32 ctrl;
__u8 data[MPL3115_NUM_CONV_VALS];
long int tmp_value = 0;
- char errbuf[1024];
/* Set Active - activate the device from standby */
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1);
if (res < 0) {
- ERROR("barometer: MPL3115_read - cannot read CTRL_REG1: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - cannot read CTRL_REG1: %s", STRERRNO);
return 1;
}
ctrl = res;
res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1,
ctrl | MPL3115_CTRL_REG1_SBYB);
if (res < 0) {
- ERROR("barometer: MPL3115_read - problem activating: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - problem activating: %s", STRERRNO);
return 1;
}
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
if (res < 0) {
ERROR("barometer: MPL3115_read - cannot read status register: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
if (res < 0) {
ERROR("barometer: MPL3115_read - cannot read status register: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
}
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, MPL3115_REG_OUT_P_MSB,
MPL3115_NUM_CONV_VALS, data);
if (res < 0) {
- ERROR("barometer: MPL3115_read - cannot read data registers: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - cannot read data registers: %s", STRERRNO);
return 1;
}
static int MPL3115_init_sensor(void) {
__s32 res;
__s8 offset;
- char errbuf[1024];
/* Reset the sensor. It will reset immediately without ACKing */
/* the transaction, so no error handling here. */
res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_OFF_T, offset);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem setting temp offset: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
if (res < 0) {
ERROR(
"barometer: MPL3115_init_sensor - problem setting pressure offset: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
MPL3115_PT_DATA_TDEF);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem setting PT_DATA_CFG: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
mpl3115_oversample);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem configuring CTRL_REG1: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
*/
static int BMP085_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, BMP085_I2C_ADDRESS) < 0) {
ERROR("barometer: BMP085_detect - problem setting i2c slave address to "
"0x%02X: %s",
- BMP085_I2C_ADDRESS, sstrerror(errno, errbuf, sizeof(errbuf)));
+ BMP085_I2C_ADDRESS, STRERRNO);
return 0;
}
res = i2c_smbus_read_byte_data(i2c_bus_fd, BMP085_ADDR_VERSION);
if (res < 0) {
ERROR("barometer: BMP085_detect - problem checking chip version: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 0;
}
DEBUG("barometer: BMP085_detect - chip version ML:0x%02X AL:0x%02X",
static int BMP085_read_coeffs(void) {
__s32 res;
__u8 coeffs[BMP085_NUM_COEFFS];
- char errbuf[1024];
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_COEFFS,
BMP085_NUM_COEFFS, coeffs);
if (res < 0) {
- ERROR("barometer: BMP085_read_coeffs - problem reading data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: BMP085_read_coeffs - problem reading data: %s", STRERRNO);
return -1;
}
long adc_pressure;
long adc_temperature;
- char errbuf[1024];
-
/* start conversion of temperature */
res = i2c_smbus_write_byte_data(i2c_bus_fd, BMP085_ADDR_CTRL_REG,
BMP085_CMD_CONVERT_TEMP);
if (res < 0) {
ERROR("barometer: BMP085_read - problem requesting temperature conversion: "
"%s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_CONV, 2, measBuff);
if (res < 0) {
ERROR("barometer: BMP085_read - problem reading temperature data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
bmp085_cmdCnvPress);
if (res < 0) {
ERROR("barometer: BMP085_read - problem requesting pressure conversion: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_CONV, 3, measBuff);
if (res < 0) {
ERROR("barometer: BMP085_read - problem reading pressure data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
* @return Zero when successful.
*/
static int collectd_barometer_init(void) {
- char errbuf[1024];
DEBUG("barometer: collectd_barometer_init");
if (i2c_bus_fd < 0) {
ERROR("barometer: collectd_barometer_init problem opening I2C bus device "
"\"%s\": %s (is loaded mod i2c-dev?)",
- config_device, sstrerror(errno, errbuf, sizeof(errbuf)));
+ config_device, STRERRNO);
return -1;
}
* the same type of other "Bytes". Instead of keeping an "average" or
* "rate", use the "sum" in the pair and assign that to the derive
* value. */
- if (convert_special_metrics && (state->depth >= 2) &&
+ if (convert_special_metrics && (state->depth > 2) &&
(strcmp("filestore", state->stack[state->depth - 2]) == 0) &&
(strcmp("journal_wr_bytes", state->stack[state->depth - 1]) == 0) &&
(strcmp("avgcount", state->key) == 0)) {
struct cconn *io = io_array + i;
ret = cconn_prepare(io, fds + nfds);
if (ret < 0) {
- WARNING("ceph plugin: cconn_prepare(name=%s,i=%zu,st=%d)=%d",
+ WARNING("ceph plugin: cconn_prepare(name=%s,i=%" PRIsz ",st=%d)=%d",
io->d->name, i, io->state, ret);
cconn_close(io);
io->request_type = ASOK_REQ_NONE;
}
status = snprintf(buffer + offset, buffer_len - offset, ",%lf", rates[i]);
} else if (ds->ds[i].type == DS_TYPE_COUNTER) {
- status = snprintf(buffer + offset, buffer_len - offset, ",%llu",
- vl->values[i].counter);
+ status = snprintf(buffer + offset, buffer_len - offset, ",%" PRIu64,
+ (uint64_t)vl->values[i].counter);
} else if (ds->ds[i].type == DS_TYPE_DERIVE) {
status = snprintf(buffer + offset, buffer_len - offset, ",%" PRIi64,
vl->values[i].derive);
csv = fopen(filename, "w");
if (csv == NULL) {
- char errbuf[1024];
- ERROR("csv plugin: fopen (%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("csv plugin: fopen (%s) failed: %s", filename, STRERRNO);
return -1;
}
if (csv_create_file(filename, ds))
return -1;
} else {
- char errbuf[1024];
- ERROR("stat(%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("stat(%s) failed: %s", filename, STRERRNO);
return -1;
}
} else if (!S_ISREG(statbuf.st_mode)) {
csv = fopen(filename, "a");
if (csv == NULL) {
- char errbuf[1024];
- ERROR("csv plugin: fopen (%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("csv plugin: fopen (%s) failed: %s", filename, STRERRNO);
return -1;
}
csv_fd = fileno(csv);
status = fcntl(csv_fd, F_SETLK, &fl);
if (status != 0) {
- char errbuf[1024];
- ERROR("csv plugin: flock (%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("csv plugin: flock (%s) failed: %s", filename, STRERRNO);
fclose(csv);
return -1;
}
if (EEXIST == errno)
continue;
- char errbuf[1024];
- ERROR("check_create_dir: mkdir (%s): %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("check_create_dir: mkdir (%s): %s", dir, STRERRNO);
return -1;
} else {
- char errbuf[1024];
- ERROR("check_create_dir: stat (%s): %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("check_create_dir: stat (%s): %s", dir, STRERRNO);
return -1;
}
} else if (!S_ISDIR(statbuf.st_mode)) {
}
BUFFER_ADD(":" GAUGE_FORMAT, rates[i]);
} else if (ds->ds[i].type == DS_TYPE_COUNTER)
- BUFFER_ADD(":%llu", vl->values[i].counter);
+ BUFFER_ADD(":%" PRIu64, (uint64_t)vl->values[i].counter);
else if (ds->ds[i].type == DS_TYPE_DERIVE)
BUFFER_ADD(":%" PRIi64, vl->values[i].derive);
else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
failure = 0;
if ((dh = opendir(dir)) == NULL) {
- char errbuf[1024];
- ERROR("walk_directory: Cannot open '%s': %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("walk_directory: Cannot open '%s': %s", dir, STRERRNO);
return -1;
}
return 0;
} /* }}} int plugin_unregister */
- /*
- * (Try to) load the shared object `file'. Won't complain if it isn't a shared
- * object, but it will bitch about a shared object not having a
- * ``module_register'' symbol..
- */
- static int plugin_load_file(const char *file, _Bool global) {
- void (*reg_handle)(void);
-
+ /* plugin_load_file loads the shared object "file" and calls its
+ * "module_register" function. Returns zero on success, non-zero otherwise. */
+ static int plugin_load_file(char const *file, _Bool global) {
int flags = RTLD_NOW;
if (global)
flags |= RTLD_GLOBAL;
void *dlh = dlopen(file, flags);
-
if (dlh == NULL) {
char errbuf[1024] = "";
snprintf(errbuf, sizeof(errbuf),
- "dlopen (\"%s\") failed: %s. "
- "The most common cause for this problem is "
- "missing dependencies. Use ldd(1) to check "
- "the dependencies of the plugin "
- "/ shared object.",
+ "dlopen(\"%s\") failed: %s. "
+ "The most common cause for this problem is missing dependencies. "
+ "Use ldd(1) to check the dependencies of the plugin / shared "
+ "object.",
file, dlerror());
- ERROR("%s", errbuf);
- /* Make sure this is printed to STDERR in any case, but also
- * make sure it's printed only once. */
- if (list_log != NULL)
- fprintf(stderr, "ERROR: %s\n", errbuf);
+ /* This error is printed to STDERR unconditionally. If list_log is NULL,
+ * plugin_log() will also print to STDERR. We avoid duplicate output by
+ * checking that the list of log handlers, list_log, is not NULL. */
+ fprintf(stderr, "ERROR: %s\n", errbuf);
+ if (list_log != NULL) {
+ ERROR("%s", errbuf);
+ }
- return 1;
+ return ENOENT;
}
- reg_handle = (void (*)(void))dlsym(dlh, "module_register");
+ void (*reg_handle)(void) = dlsym(dlh, "module_register");
if (reg_handle == NULL) {
- WARNING("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file,
- dlerror());
+ ERROR("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file,
+ dlerror());
dlclose(dlh);
- return -1;
+ return ENOENT;
}
(*reg_handle)();
-
return 0;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
int status = pthread_setname_np(tid, n);
if (status != 0) {
- char errbuf[1024];
- ERROR("set_thread_name(\"%s\"): %s", n,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("set_thread_name(\"%s\"): %s", n, STRERROR(status));
}
#else /* if defined(HAVE_PTHREAD_SET_NAME_NP) */
pthread_set_name_np(tid, n);
/* attr = */ NULL, plugin_read_thread,
/* arg = */ NULL);
if (status != 0) {
- char errbuf[1024];
- ERROR("plugin: start_read_threads: pthread_create failed "
- "with status %i (%s).",
- status, sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("plugin: start_read_threads: pthread_create failed with status %i "
+ "(%s).",
+ status, STRERROR(status));
return;
}
char name[THREAD_NAME_MAX];
- snprintf(name, sizeof(name), "reader#%zu", read_threads_num);
+ snprintf(name, sizeof(name), "reader#%" PRIsz, read_threads_num);
set_thread_name(read_threads[read_threads_num], name);
read_threads_num++;
if (read_threads == NULL)
return;
- INFO("collectd: Stopping %zu read threads.", read_threads_num);
+ INFO("collectd: Stopping %" PRIsz " read threads.", read_threads_num);
pthread_mutex_lock(&read_lock);
read_loop = 0;
/* attr = */ NULL, plugin_write_thread,
/* arg = */ NULL);
if (status != 0) {
- char errbuf[1024];
- ERROR("plugin: start_write_threads: pthread_create failed "
- "with status %i (%s).",
- status, sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("plugin: start_write_threads: pthread_create failed with status %i "
+ "(%s).",
+ status, STRERROR(status));
return;
}
char name[THREAD_NAME_MAX];
- snprintf(name, sizeof(name), "writer#%zu", write_threads_num);
+ snprintf(name, sizeof(name), "writer#%" PRIsz, write_threads_num);
set_thread_name(write_threads[write_threads_num], name);
write_threads_num++;
if (write_threads == NULL)
return;
- INFO("collectd: Stopping %zu write threads.", write_threads_num);
+ INFO("collectd: Stopping %" PRIsz " write threads.", write_threads_num);
pthread_mutex_lock(&write_lock);
write_loop = 0;
pthread_mutex_unlock(&write_lock);
if (i > 0) {
- WARNING("plugin: %zu value list%s left after shutting down "
+ WARNING("plugin: %" PRIsz " value list%s left after shutting down "
"the write threads.",
i, (i == 1) ? " was" : "s were");
}
}
if ((dh = opendir(dir)) == NULL) {
- char errbuf[1024];
- ERROR("plugin_load: opendir (%s) failed: %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("plugin_load: opendir (%s) failed: %s", dir, STRERRNO);
return -1;
}
}
if (lstat(filename, &statbuf) == -1) {
- char errbuf[1024];
- WARNING("plugin_load: stat (\"%s\") failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("plugin_load: stat (\"%s\") failed: %s", filename, STRERRNO);
continue;
} else if (!S_ISREG(statbuf.st_mode)) {
/* don't follow symlinks */
#else
if (ds->ds_num != vl->values_len) {
ERROR("plugin_dispatch_values: ds->type = %s: "
- "(ds->ds_num = %zu) != "
- "(vl->values_len = %zu)",
+ "(ds->ds_num = %" PRIsz ") != "
+ "(vl->values_len = %" PRIsz ")",
ds->type, ds->ds_num, vl->values_len);
return -1;
}
status = plugin_write_enqueue(vl);
if (status != 0) {
- char errbuf[1024];
- ERROR("plugin_dispatch_values: plugin_write_enqueue failed "
- "with status %i (%s).",
- status, sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("plugin_dispatch_values: plugin_write_enqueue failed with status %i "
+ "(%s).",
+ status, STRERROR(status));
return status;
}
ctx = malloc(sizeof(*ctx));
if (ctx == NULL) {
- char errbuf[1024];
- ERROR("Failed to allocate plugin context: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("Failed to allocate plugin context: %s", STRERRNO);
return NULL;
}
int fields_num;
if (buf_len < 11) {
- ERROR("parse_ds: (buf_len = %zu) < 11", buf_len);
+ ERROR("parse_ds: (buf_len = %" PRIsz ") < 11", buf_len);
return -1;
}
for (size_t i = 0; i < ds->ds_num; i++)
if (parse_ds(ds->ds + i, fields[i + 1], strlen(fields[i + 1])) != 0) {
- ERROR("types_list: parse_line: Cannot parse data source #%zu "
- "of data set %s",
+ ERROR("types_list: parse_line: Cannot parse data source #%" PRIsz
+ " of data set %s",
i, ds->type);
sfree(ds->ds);
sfree(ds);
fh = fopen(file, "r");
if (fh == NULL) {
- char errbuf[1024];
fprintf(stderr, "Failed to open types database `%s': %s.\n", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
- ERROR("Failed to open types database `%s': %s", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
+ ERROR("Failed to open types database `%s': %s", file, STRERRNO);
return -1;
}
int ret = dpdk_helper_init(g_shm_name, sizeof(dpdk_stats_ctx_t), &g_hc);
if (ret != 0) {
- char errbuf[ERR_BUF_SIZE];
ERROR("%s: failed to initialize %s helper(error: %s)", DPDK_STATS_PLUGIN,
- g_shm_name, sstrerror(errno, errbuf, sizeof(errbuf)));
+ g_shm_name, STRERRNO);
return ret;
}
size_t data_size = sizeof(dpdk_stats_ctx_t) +
(ctx->stats_count * DPDK_STATS_CTX_GET_XSTAT_SIZE);
- DEBUG("%s:%d helper reinit (new_size=%zu)", __FUNCTION__, __LINE__,
+ DEBUG("%s:%d helper reinit (new_size=%" PRIsz ")", __FUNCTION__, __LINE__,
data_size);
dpdk_stats_ctx_t tmp_ctx;
int ret;
ret = dpdk_helper_init(g_shm_name, data_size, &g_hc);
if (ret != 0) {
- char errbuf[ERR_BUF_SIZE];
ERROR("%s: failed to initialize %s helper(error: %s)", DPDK_STATS_PLUGIN,
- g_shm_name, sstrerror(errno, errbuf, sizeof(errbuf)));
+ g_shm_name, STRERRNO);
return ret;
}
errno = 0;
if (fgets(line, sizeof(line), this->socket) == NULL) {
if (errno != 0) {
- char errbuf[1024];
log_err("collect: reading from socket (fd #%i) "
"failed: %s",
- fileno(this->socket),
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ fileno(this->socket), STRERRNO);
}
break;
}
len = strlen(line);
if ((line[len - 1] != '\n') && (line[len - 1] != '\r')) {
- log_warn("collect: line too long (> %zu characters): "
+ log_warn("collect: line too long (> %" PRIsz " characters): "
"'%s' (truncated)",
sizeof(line) - 1, line);
/* create UNIX socket */
errno = 0;
if ((connector_socket = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
- char errbuf[1024];
disabled = 1;
- log_err("socket() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("socket() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
if (bind(connector_socket, (struct sockaddr *)&addr,
offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) ==
-1) {
- char errbuf[1024];
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("bind() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("bind() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
errno = 0;
if (listen(connector_socket, 5) == -1) {
- char errbuf[1024];
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("listen() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("listen() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
grp = NULL;
status = getgrnam_r(group, &sg, grbuf, sizeof(grbuf), &grp);
if (status != 0) {
- char errbuf[1024];
- log_warn("getgrnam_r (%s) failed: %s", group,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ log_warn("getgrnam_r (%s) failed: %s", group, STRERROR(status));
} else if (grp == NULL) {
log_warn("No such group: `%s'", group);
} else {
status = chown(path, (uid_t)-1, grp->gr_gid);
if (status != 0) {
- char errbuf[1024];
log_warn("chown (%s, -1, %i) failed: %s", path, (int)grp->gr_gid,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
}
}
}
errno = 0;
if (chmod(path, sock_perms) != 0) {
- char errbuf[1024];
- log_warn("chmod() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_warn("chmod() failed: %s", STRERRNO);
}
{ /* initialize collector threads */
if (plugin_thread_create(&collectors[i]->thread, &ptattr, collect,
collectors[i], "email collector") != 0) {
- char errbuf[1024];
- log_err("plugin_thread_create() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("plugin_thread_create() failed: %s", STRERRNO);
collectors[i]->thread = (pthread_t)0;
}
}
remote = accept(connector_socket, NULL, NULL);
if (remote == -1) {
- char errbuf[1024];
-
if (errno == EINTR)
continue;
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("accept() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("accept() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
static int email_init(void) {
if (plugin_thread_create(&connector, NULL, open_connection, NULL,
"email listener") != 0) {
- char errbuf[1024];
disabled = 1;
- log_err("plugin_thread_create() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("plugin_thread_create() failed: %s", STRERRNO);
return -1;
}
ai_return = getaddrinfo(node, service, &ai_hints, &ai_list);
if (ai_return != 0) {
- char errbuf[1024];
ERROR("gmond plugin: getaddrinfo (%s, %s) failed: %s",
(node == NULL) ? "(null)" : node,
(service == NULL) ? "(null)" : service,
- (ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(ai_return));
+ (ai_return == EAI_SYSTEM) ? STRERRNO : gai_strerror(ai_return));
return -1;
}
sockets[sockets_num].fd =
socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (sockets[sockets_num].fd < 0) {
- char errbuf[1024];
- ERROR("gmond plugin: socket failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: socket failed: %s", STRERRNO);
continue;
}
status = setsockopt(sockets[sockets_num].fd, SOL_SOCKET, SO_REUSEADDR,
(void *)&yes, sizeof(yes));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
}
status = bind(sockets[sockets_num].fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- ERROR("gmond plugin: bind failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: bind failed: %s", STRERRNO);
close(sockets[sockets_num].fd);
continue;
}
status = setsockopt(sockets[sockets_num].fd, IPPROTO_IP,
IP_MULTICAST_LOOP, (void *)&loop, sizeof(loop));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
struct ip_mreq mreq = {.imr_multiaddr.s_addr = addr->sin_addr.s_addr,
status = setsockopt(sockets[sockets_num].fd, IPPROTO_IP,
IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
} /* if (ai_ptr->ai_family == AF_INET) */
else if (ai_ptr->ai_family == AF_INET6) {
status = setsockopt(sockets[sockets_num].fd, IPPROTO_IPV6,
IPV6_MULTICAST_LOOP, (void *)&loop, sizeof(loop));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
struct ipv6_mreq mreq = {
status = setsockopt(sockets[sockets_num].fd, IPPROTO_IPV6,
IPV6_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
} /* if (ai_ptr->ai_family == AF_INET6) */
/* flags = */ 0, (struct sockaddr *)&mc_send_sockets[i].addr,
mc_send_sockets[i].addrlen);
if (status == -1) {
- char errbuf[1024];
- ERROR("gmond plugin: sendto(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: sendto(2) failed: %s", STRERRNO);
continue;
}
}
}
if (ds->ds_num <= ds_index) {
- ERROR("gmond plugin: Invalid index %zu: %s has only %zu data source(s).",
+ ERROR("gmond plugin: Invalid index %" PRIsz ": %s has only %" PRIsz
+ " data source(s).",
ds_index, ds->type, ds->ds_num);
return -1;
}
buffer_size = recv(p->fd, buffer, sizeof(buffer), /* flags = */ 0);
if (buffer_size <= 0) {
- char errbuf[1024];
- ERROR("gmond plugin: recv failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: recv failed: %s", STRERRNO);
p->revents = 0;
return -1;
}
while (mc_receive_thread_loop != 0) {
status = poll(mc_receive_sockets, mc_receive_sockets_num, -1);
if (status <= 0) {
- char errbuf[1024];
if (errno == EINTR)
continue;
- ERROR("gmond plugin: poll failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: poll failed: %s", STRERRNO);
break;
}
#include "collectd/lcc_features.h"
#include "collectd/network_parse.h"
+#include "globals.h"
#include <errno.h>
#include <math.h>
#include <endian.h>
#elif HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
+ #else /* fallback */
+ __attribute__((const)) static uint16_t be16toh(uint16_t n) {
+ uint8_t tmp[2];
+ memmove(tmp, &n, sizeof(tmp));
+
+ return ((uint16_t)tmp[0] << 8) | ((uint16_t)tmp[1] << 0);
+ }
+
+ __attribute__((const)) static uint64_t be64toh(uint64_t n) {
+ uint8_t tmp[8];
+ memmove(tmp, &n, sizeof(tmp));
+
+ return ((uint64_t)tmp[0] << 56) | ((uint64_t)tmp[1] << 48) |
+ ((uint64_t)tmp[2] << 40) | ((uint64_t)tmp[3] << 32) |
+ ((uint64_t)tmp[4] << 24) | ((uint64_t)tmp[5] << 16) |
+ ((uint64_t)tmp[6] << 8) | ((uint64_t)tmp[7] << 0);
+ }
#endif
#if HAVE_GCRYPT_H
uint8_t pwhash[32] = {0};
gcry_md_hash_buffer(GCRY_MD_SHA256, pwhash, password, strlen(password));
- fprintf(stderr, "sizeof(iv) = %zu\n", sizeof(iv));
+ fprintf(stderr, "sizeof(iv) = %" PRIsz "\n", sizeof(iv));
if (gcry_cipher_setkey(cipher, pwhash, sizeof(pwhash)) ||
gcry_cipher_setiv(cipher, iv, iv_size) ||
gcry_cipher_decrypt(cipher, b->data, b->len, /* in = */ NULL,
if ((sz < 5) || (((size_t)sz - 4) > b->len)) {
DEBUG("lcc_network_parse(): invalid 'sz' field: sz = %" PRIu16
- ", b->len = %zu\n",
+ ", b->len = %" PRIsz "\n",
sz, b->len);
return EINVAL;
}
uint8_t buffer[LCC_NETWORK_BUFFER_SIZE_DEFAULT];
size_t buffer_size = sizeof(buffer);
if (decode_string(raw_packet_data[i], buffer, &buffer_size)) {
- fprintf(
- stderr,
- "lcc_network_parse(raw_packet_data[%zu]): decoding string failed\n",
- i);
+ fprintf(stderr, "lcc_network_parse(raw_packet_data[%" PRIsz "]):"
+ " decoding string failed\n",
+ i);
return -1;
}
.writer = nop_writer,
});
if (status != 0) {
- fprintf(stderr, "lcc_network_parse(raw_packet_data[%zu]) = %d, want 0\n",
+ fprintf(stderr,
+ "lcc_network_parse(raw_packet_data[%" PRIsz "]) = %d, want 0\n",
i, status);
ret = status;
}
- printf("ok - lcc_network_parse(raw_packet_data[%zu])\n", i);
+ printf("ok - lcc_network_parse(raw_packet_data[%" PRIsz "])\n", i);
}
return ret;
}
if (vl.values_len != 3) {
- fprintf(stderr, "parse_values(): vl.values_len = %zu, want 3\n",
+ fprintf(stderr, "parse_values(): vl.values_len = %" PRIsz ", want 3\n",
vl.values_len);
return -1;
}
int want_types[] = {LCC_TYPE_GAUGE, LCC_TYPE_DERIVE, LCC_TYPE_GAUGE};
for (size_t i = 0; i < sizeof(want_types) / sizeof(want_types[0]); i++) {
if (vl.values_types[i] != want_types[i]) {
- fprintf(stderr, "parse_values(): vl.values_types[%zu] = %d, want %d\n", i,
+ fprintf(stderr,
+ "parse_values(): vl.values_types[%" PRIsz "] = %d, want %d\n", i,
vl.values_types[i], want_types[i]);
ret = -1;
}
return ret;
}
+ #if HAVE_GCRYPT_H
static int test_verify_sha256() {
int ret = 0;
return ret;
}
+ #endif
+ #if HAVE_GCRYPT_H
static int test_decrypt_aes256() {
char const *iv_str = "4cbe2a747c9f9dcfa0e66f0c2fa74875";
uint8_t iv[16] = {0};
return 0;
}
+ #endif
int main(void) {
int ret = 0;
- printf("libcollectdclient/server_test.c\n");
-
int status;
if ((status = test_network_parse())) {
ret = status;
ret = status;
}
+ #if HAVE_GCRYPT_H
if ((status = test_verify_sha256())) {
ret = status;
}
if ((status = test_decrypt_aes256())) {
ret = status;
}
+ #endif
return ret;
}
}
if (ds->ds_num != 1) {
- ERROR("Modbus plugin: The type \"%s\" has %zu data sources. "
+ ERROR("Modbus plugin: The type \"%s\" has %" PRIsz " data sources. "
"I can only handle data sets with only one data source.",
data->type, ds->ds_num);
return -1;
status = getaddrinfo(address, /* service = */ NULL, &ai_hints, &ai_list);
if (status != 0) {
- char errbuf[1024];
ERROR("Modbus plugin: getaddrinfo failed: %s",
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return status;
}
continue;
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*stats.stats64)) < 0) {
+ char errbuf[1024];
ERROR("netlink plugin: link_filter_cb: IFLA_STATS64 mnl_attr_validate2 "
- "failed.");
+ "failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
return MNL_CB_ERROR;
}
stats.stats64 = mnl_attr_get_payload(attr);
continue;
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*stats.stats32)) < 0) {
+ char errbuf[1024];
ERROR("netlink plugin: link_filter_cb: IFLA_STATS mnl_attr_validate2 "
- "failed.");
+ "failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
return MNL_CB_ERROR;
}
stats.stats32 = mnl_attr_get_payload(attr);
if (mnl_attr_get_type(attr) == TCA_STATS_BASIC) {
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*q_stats->bs)) < 0) {
+ char errbuf[1024];
ERROR("netlink plugin: qos_attr_cb: TCA_STATS_BASIC mnl_attr_validate2 "
- "failed.");
+ "failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
return MNL_CB_ERROR;
}
q_stats->bs = mnl_attr_get_payload(attr);
if ((tm->tcm_ifindex >= 0) && ((size_t)tm->tcm_ifindex >= iflist_len)) {
ERROR("netlink plugin: qos_filter_cb: tm->tcm_ifindex = %i "
- ">= iflist_len = %zu",
+ ">= iflist_len = %" PRIsz,
tm->tcm_ifindex, iflist_len);
return MNL_CB_ERROR;
}
continue;
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*ts)) < 0) {
+ char errbuf[1024];
ERROR("netlink plugin: qos_filter_cb: TCA_STATS mnl_attr_validate2 "
- "failed.");
+ "failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
return MNL_CB_ERROR;
}
ts = mnl_attr_get_payload(attr);
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
}
if (ret < 0) {
- ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed.");
- return -1;
+ char errbuf[1024];
+ ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
+ return (-1);
}
/* `link_filter_cb' will update `iflist' which is used here to iterate
continue;
}
- DEBUG("netlink plugin: ir_read: querying %s from %s (%zu).",
+ DEBUG("netlink plugin: ir_read: querying %s from %s (%" PRIsz ").",
type_name[type_index], iflist[ifindex], ifindex);
nlh = mnl_nlmsg_put_header(buf);
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
}
if (ret < 0) {
- ERROR("netlink plugin: ir_read:mnl_socket_recvfrom failed.");
+ char errbuf[1024];
+ ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
continue;
}
-
} /* for (type_index) */
} /* for (if_index) */
if (buffer_len < 15) {
NOTICE("network plugin: packet is too short: "
- "buffer_len = %zu",
+ "buffer_len = %" PRIsz,
buffer_len);
return -1;
}
if (buffer_len < exp_size) {
WARNING("network plugin: parse_part_values: "
"Packet too short: "
- "Chunk of size %zu expected, "
- "but buffer has only %zu bytes left.",
+ "Chunk of size %" PRIsz " expected, "
+ "but buffer has only %" PRIsz " bytes left.",
exp_size, buffer_len);
return -1;
}
if (buffer_len < exp_size) {
WARNING("network plugin: parse_part_number: "
"Packet too short: "
- "Chunk of size %zu expected, "
- "but buffer has only %zu bytes left.",
+ "Chunk of size %" PRIsz " expected, "
+ "but buffer has only %" PRIsz " bytes left.",
exp_size, buffer_len);
return -1;
}
if (buffer_len < header_size) {
WARNING("network plugin: parse_part_string: "
"Packet too short: "
- "Chunk of at least size %zu expected, "
- "but buffer has only %zu bytes left.",
+ "Chunk of at least size %" PRIsz " expected, "
+ "but buffer has only %" PRIsz " bytes left.",
header_size, buffer_len);
return -1;
}
WARNING("network plugin: parse_part_string: "
"Packet too big: "
"Chunk of size %" PRIu16 " received, "
- "but buffer has only %zu bytes left.",
+ "but buffer has only %" PRIsz " bytes left.",
pkg_length, buffer_len);
return -1;
}
if (output_len < payload_size) {
WARNING("network plugin: parse_part_string: "
"Buffer too small: "
- "Output buffer holds %zu bytes, "
+ "Output buffer holds %" PRIsz " bytes, "
"which is too small to hold the received "
- "%zu byte string.",
+ "%" PRIsz " byte string.",
output_len, payload_size);
return -1;
}
if (setsockopt(se->data.client.fd, IPPROTO_IP, optname, &network_config_ttl,
sizeof(network_config_ttl)) != 0) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv4-ttl): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv4-ttl): %s", STRERRNO);
return -1;
}
} else if (ai->ai_family == AF_INET6) {
if (setsockopt(se->data.client.fd, IPPROTO_IPV6, optname,
&network_config_ttl, sizeof(network_config_ttl)) != 0) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt(ipv6-ttl): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt(ipv6-ttl): %s", STRERRNO);
return -1;
}
}
if (setsockopt(se->data.client.fd, IPPROTO_IP, IP_MULTICAST_IF, &mreq,
sizeof(mreq)) != 0) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv4-multicast-if): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv4-multicast-if): %s", STRERRNO);
return -1;
}
if (IN6_IS_ADDR_MULTICAST(&addr->sin6_addr)) {
if (setsockopt(se->data.client.fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
&se->interface, sizeof(se->interface)) != 0) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv6-multicast-if): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv6-multicast-if): %s", STRERRNO);
return -1;
}
if (setsockopt(se->data.client.fd, SOL_SOCKET, SO_BINDTODEVICE,
interface_name, sizeof(interface_name)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (bind-if): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (bind-if): %s", STRERRNO);
return -1;
}
/* #endif HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */
/* allow multiple sockets to use the same PORT number */
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (reuseaddr): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (reuseaddr): %s", STRERRNO);
return -1;
}
DEBUG("fd = %i; calling `bind'", fd);
if (bind(fd, ai->ai_addr, ai->ai_addrlen) == -1) {
- char errbuf[1024];
- ERROR("bind: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("bind: %s", STRERRNO);
return -1;
}
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) ==
-1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (multicast-loop): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (multicast-loop): %s", STRERRNO);
return -1;
}
if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) ==
-1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (add-membership): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (add-membership): %s", STRERRNO);
return -1;
}
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop,
sizeof(loop)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv6-multicast-loop): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv6-multicast-loop): %s", STRERRNO);
return -1;
}
if (setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq,
sizeof(mreq)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv6-add-membership): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv6-add-membership): %s", STRERRNO);
return -1;
}
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, interface_name,
sizeof(interface_name)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (bind-if): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (bind-if): %s", STRERRNO);
return -1;
}
}
client->fd =
socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (client->fd < 0) {
- char errbuf[1024];
- ERROR("network plugin: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: socket(2) failed: %s", STRERRNO);
continue;
}
*tmp = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (*tmp < 0) {
- char errbuf[1024];
- ERROR("network plugin: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: socket(2) failed: %s", STRERRNO);
continue;
}
while (listen_loop == 0) {
status = poll(listen_sockets_pollfd, listen_sockets_num, -1);
if (status <= 0) {
- char errbuf[1024];
if (errno == EINTR)
continue;
- ERROR("network plugin: poll(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: poll(2) failed: %s", STRERRNO);
break;
}
buffer_len = recv(listen_sockets_pollfd[i].fd, buffer, sizeof(buffer),
0 /* no flags */);
if (buffer_len < 0) {
- char errbuf[1024];
status = (errno != 0) ? errno : -1;
- ERROR("network plugin: recv(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: recv(2) failed: %s", STRERRNO);
break;
}
/* flags = */ 0, (struct sockaddr *)se->data.client.addr,
se->data.client.addrlen);
if (status < 0) {
- char errbuf[1024];
-
if ((errno == EINTR) || (errno == EAGAIN))
continue;
ERROR("network plugin: sendto failed: %s. Closing sending socket.",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
sockent_client_disconnect(se);
return;
}
assert(buffer_size <= sizeof(buffer));
DEBUG("network plugin: network_send_buffer_encrypted: "
- "buffer_size = %zu;",
+ "buffer_size = %" PRIsz ";",
buffer_size);
pea.head.length = htons(
static void network_send_buffer(char *buffer, size_t buffer_len) /* {{{ */
{
- DEBUG("network plugin: network_send_buffer: buffer_len = %zu", buffer_len);
+ DEBUG("network plugin: network_send_buffer: buffer_len = %" PRIsz,
+ buffer_len);
for (sockent_t *se = sending_sockets; se != NULL; se = se->next) {
#if HAVE_GCRYPT_H
dispatch_thread, NULL /* no argument */,
"network disp");
if (status != 0) {
- char errbuf[1024];
- ERROR("network: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network: pthread_create failed: %s", STRERRNO);
} else {
dispatch_thread_running = 1;
}
receive_thread, NULL /* no argument */,
"network recv");
if (status != 0) {
- char errbuf[1024];
- ERROR("network: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network: pthread_create failed: %s", STRERRNO);
} else {
receive_thread_running = 1;
}
.ai_socktype = SOCK_DGRAM};
if ((status = getaddrinfo(host, port, &ai_hints, &ai_list)) != 0) {
- char errbuf[1024];
ERROR("ntpd plugin: getaddrinfo (%s, %s): %s", host, port,
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return -1;
}
*res_data = NULL;
if (gettimeofday(&time_end, NULL) < 0) {
- char errbuf[1024];
- ERROR("ntpd plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ntpd plugin: gettimeofday failed: %s", STRERRNO);
return -1;
}
time_end.tv_sec++; /* wait for a most one second */
struct timeval time_left;
if (gettimeofday(&time_now, NULL) < 0) {
- char errbuf[1024];
- ERROR("ntpd plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ntpd plugin: gettimeofday failed: %s", STRERRNO);
return -1;
}
continue;
if (status < 0) {
- char errbuf[1024];
- ERROR("ntpd plugin: poll failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ntpd plugin: poll failed: %s", STRERRNO);
return -1;
}
continue;
if (status < 0) {
- char errbuf[1024];
- INFO("recv(2) failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ INFO("recv(2) failed: %s", STRERRNO);
DEBUG("Closing socket #%i", sd);
close(sd);
sock_descr = sd = -1;
* Enough with the checks. Copy the data now.
* We start by allocating some more memory.
*/
- DEBUG("realloc (%p, %zu)", (void *)*res_data,
+ DEBUG("realloc (%p, %" PRIsz ")", (void *)*res_data,
(items_num + pkt_item_num) * res_item_size);
items = realloc(*res_data, (items_num + pkt_item_num) * res_item_size);
if (items == NULL) {
buffer_size, NULL, 0, /* No port name */
flags);
if (status != 0) {
- char errbuf[1024];
ERROR("ntpd plugin: getnameinfo failed: %s",
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return -1;
}
if (array_len < ds->ds_num) {
log_warn("av2value: array does not contain enough elements for type "
- "\"%s\": got %zu, want %zu",
+ "\"%s\": got %" PRIsz ", want %" PRIsz,
name, array_len, ds->ds_num);
return 0;
} else if (array_len > ds->ds_num) {
log_warn("av2value: array contains excess elements for type \"%s\": got "
- "%zu, want %zu",
+ "%" PRIsz ", want %" PRIsz,
name, array_len, ds->ds_num);
}
static int notification_meta2av(pTHX_ notification_meta_t *meta, AV *array) {
int meta_num = 0;
-
- while (meta) {
+ for (notification_meta_t *m = meta; m != NULL; m = m->next) {
++meta_num;
- meta = meta->next;
}
av_extend(array, meta_num);
static double ping_timeout = 0.9;
static int ping_max_missed = -1;
+ static pthread_mutex_t ping_lock = PTHREAD_MUTEX_INITIALIZER;
+ static pthread_cond_t ping_cond = PTHREAD_COND_INITIALIZER;
static int ping_thread_loop = 0;
static int ping_thread_error = 0;
static pthread_t ping_thread_id;
- static pthread_mutex_t ping_lock = PTHREAD_MUTEX_INITIALIZER;
- static pthread_cond_t ping_cond = PTHREAD_COND_INITIALIZER;
static const char *config_keys[] = {"Host", "SourceAddress",
#ifdef HAVE_OPING_1_3
static void *ping_thread(void *arg) /* {{{ */
{
- pingobj_t *pingobj = NULL;
-
struct timeval tv_begin;
struct timeval tv_end;
struct timespec ts_wait;
c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
- pthread_mutex_lock(&ping_lock);
-
- pingobj = ping_construct();
+ pingobj_t *pingobj = ping_construct();
if (pingobj == NULL) {
ERROR("ping plugin: ping_construct failed.");
+ pthread_mutex_lock(&ping_lock);
ping_thread_error = 1;
pthread_mutex_unlock(&ping_lock);
return (void *)-1;
if (count == 0) {
ERROR("ping plugin: No host could be added to ping object. Giving up.");
+ pthread_mutex_lock(&ping_lock);
ping_thread_error = 1;
pthread_mutex_unlock(&ping_lock);
return (void *)-1;
ts_int.tv_nsec = (long)(temp_nsec * 1000000000L);
}
+ pthread_mutex_lock(&ping_lock);
while (ping_thread_loop > 0) {
- int status;
_Bool send_successful = 0;
if (gettimeofday(&tv_begin, NULL) < 0) {
- char errbuf[1024];
- ERROR("ping plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ping plugin: gettimeofday failed: %s", STRERRNO);
ping_thread_error = 1;
break;
}
pthread_mutex_unlock(&ping_lock);
- status = ping_send(pingobj);
+ int status = ping_send(pingobj);
if (status < 0) {
c_complain(LOG_ERR, &complaint, "ping plugin: ping_send failed: %s",
ping_get_error(pingobj));
(void)ping_dispatch_all(pingobj);
if (gettimeofday(&tv_end, NULL) < 0) {
- char errbuf[1024];
- ERROR("ping plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ping plugin: gettimeofday failed: %s", STRERRNO);
ping_thread_error = 1;
break;
}
tmp = strdup(value);
if (tmp == NULL) {
- char errbuf[1024];
ERROR("ping plugin: Setting `%s' to `%s' failed: strdup failed: %s", name,
- value, sstrerror(errno, errbuf, sizeof(errbuf)));
+ value, STRERRNO);
return 1;
}
hl = malloc(sizeof(*hl));
if (hl == NULL) {
- char errbuf[1024];
- ERROR("ping plugin: malloc failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ping plugin: malloc failed: %s", STRERRNO);
return 1;
}
host = strdup(value);
if (host == NULL) {
- char errbuf[1024];
sfree(hl);
- ERROR("ping plugin: strdup failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ping plugin: strdup failed: %s", STRERRNO);
return 1;
}
} /* }}} for (i = 0; i < size; i++) */
ping_data[size] = 0;
} else
- WARNING("ping plugin: Ignoring invalid Size %zu.", size);
+ WARNING("ping plugin: Ignoring invalid Size %" PRIsz ".", size);
} else if (strcasecmp(key, "Timeout") == 0) {
double tmp;
#endif
#define FUNC_ERROR(func) \
do { \
- char errbuf[1024]; \
- ERROR("powerdns plugin: %s failed: %s", func, \
- sstrerror(errno, errbuf, sizeof(errbuf))); \
+ ERROR("powerdns plugin: %s failed: %s", func, STRERRNO); \
} while (0)
#define SOCK_ERROR(func, sockpath) \
do { \
- char errbuf[1024]; \
ERROR("powerdns plugin: Socket `%s` %s failed: %s", sockpath, func, \
- sstrerror(errno, errbuf, sizeof(errbuf))); \
+ STRERRNO); \
} while (0)
#define SERVER_SOCKET LOCALSTATEDIR "/run/pdns.controlsocket"
}
if (ds->ds_num != 1) {
- ERROR("powerdns plugin: type `%s' has %zu data sources, "
+ ERROR("powerdns plugin: type `%s' has %" PRIsz " data sources, "
"but I can only handle one.",
type, ds->ds_num);
return;
plugin_dispatch_values(&vl);
} /* }}} static void submit */
- static int powerdns_get_data_dgram(list_item_t *item, /* {{{ */
- char **ret_buffer, size_t *ret_buffer_size) {
+ static int powerdns_get_data_dgram(list_item_t *item, char **ret_buffer) {
+ /* {{{ */
int sd;
int status;
buffer[buffer_size - 1] = 0;
*ret_buffer = buffer;
- *ret_buffer_size = buffer_size;
-
return 0;
} /* }}} int powerdns_get_data_dgram */
- static int powerdns_get_data_stream(list_item_t *item, /* {{{ */
- char **ret_buffer,
- size_t *ret_buffer_size) {
+ static int powerdns_get_data_stream(list_item_t *item, char **ret_buffer) {
+ /* {{{ */
int sd;
int status;
if (status < 0) {
SOCK_ERROR("recv", item->sockaddr.sun_path);
break;
- } else if (status == 0)
+ } else if (status == 0) {
break;
+ }
buffer_new = realloc(buffer, buffer_size + status + 1);
if (buffer_new == NULL) {
FUNC_ERROR("realloc");
- status = -1;
+ status = ENOMEM;
break;
}
buffer = buffer_new;
} /* while (42) */
close(sd);
- if (status < 0) {
+ if (status != 0) {
sfree(buffer);
- } else {
- assert(status == 0);
- *ret_buffer = buffer;
- *ret_buffer_size = buffer_size;
+ return status;
}
- return status;
+ *ret_buffer = buffer;
+ return 0;
} /* }}} int powerdns_get_data_stream */
- static int powerdns_get_data(list_item_t *item, char **ret_buffer,
- size_t *ret_buffer_size) {
+ static int powerdns_get_data(list_item_t *item, char **ret_buffer) {
if (item->socktype == SOCK_DGRAM)
- return powerdns_get_data_dgram(item, ret_buffer, ret_buffer_size);
+ return powerdns_get_data_dgram(item, ret_buffer);
else if (item->socktype == SOCK_STREAM)
- return powerdns_get_data_stream(item, ret_buffer, ret_buffer_size);
+ return powerdns_get_data_stream(item, ret_buffer);
else {
ERROR("powerdns plugin: Unknown socket type: %i", (int)item->socktype);
return -1;
static int powerdns_read_server(list_item_t *item) /* {{{ */
{
- char *buffer = NULL;
- size_t buffer_size = 0;
- int status;
-
- char *dummy;
- char *saveptr;
-
- char *key;
- char *value;
-
- const char *const *fields;
- int fields_num;
-
if (item->command == NULL)
item->command = strdup(SERVER_COMMAND);
if (item->command == NULL) {
return -1;
}
- status = powerdns_get_data(item, &buffer, &buffer_size);
- if (status != 0)
- return -1;
+ char *buffer = NULL;
+ int status = powerdns_get_data(item, &buffer);
+ if (status != 0) {
+ ERROR("powerdns plugin: powerdns_get_data failed.");
+ return status;
+ }
+ if (buffer == NULL) {
+ return EINVAL;
+ }
+ const char *const *fields = default_server_fields;
+ int fields_num = default_server_fields_num;
if (item->fields_num != 0) {
fields = (const char *const *)item->fields;
fields_num = item->fields_num;
- } else {
- fields = default_server_fields;
- fields_num = default_server_fields_num;
}
assert(fields != NULL);
/* corrupt-packets=0,deferred-cache-inserts=0,deferred-cache-lookup=0,latency=0,packetcache-hit=0,packetcache-miss=0,packetcache-size=0,qsize-q=0,query-cache-hit=0,query-cache-miss=0,recursing-answers=0,recursing-questions=0,servfail-packets=0,tcp-answers=0,tcp-queries=0,timedout-packets=0,udp-answers=0,udp-queries=0,udp4-answers=0,udp4-queries=0,udp6-answers=0,udp6-queries=0,
*/
- dummy = buffer;
- saveptr = NULL;
+ char *dummy = buffer;
+ char *saveptr = NULL;
+ char *key;
while ((key = strtok_r(dummy, ",", &saveptr)) != NULL) {
dummy = NULL;
- value = strchr(key, '=');
+ char *value = strchr(key, '=');
if (value == NULL)
break;
static int powerdns_read_recursor(list_item_t *item) /* {{{ */
{
char *buffer = NULL;
- size_t buffer_size = 0;
int status;
char *dummy;
}
assert(item->command != NULL);
- status = powerdns_get_data(item, &buffer, &buffer_size);
+ status = powerdns_get_data(item, &buffer);
if (status != 0) {
ERROR("powerdns plugin: powerdns_get_data failed.");
return -1;
ps_update_counter(&ps->io_diskw, &pse->io_diskw, entry->io_diskw);
}
- if ((entry->cswitch_vol != -1) && (entry->cswitch_vol != -1)) {
+ if ((entry->cswitch_vol != -1) && (entry->cswitch_invol != -1)) {
ps_update_counter(&ps->cswitch_vol, &pse->cswitch_vol,
entry->cswitch_vol);
ps_update_counter(&ps->cswitch_invol, &pse->cswitch_invol,
#if KERNEL_LINUX || KERNEL_SOLARIS || KERNEL_FREEBSD
if (strlen(c->values[0].value.string) > max_procname_len) {
- WARNING("processes plugin: this platform has a %zu character limit "
+ WARNING("processes plugin: this platform has a %" PRIsz
+ " character limit "
"to process names. The `Process \"%s\"' option will "
"not work as expected.",
max_procname_len, c->values[0].value.string);
} /* while (fgets) */
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("processes: fclose: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes: fclose: %s", STRERRNO);
}
}
closedir(dh);
} /* while (fgets) */
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes: fclose: %s", STRERRNO);
}
ps->vmem_data = data * 1024;
} /* while (fgets) */
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes: fclose: %s", STRERRNO);
}
return 0;
} /* int ps_read_io (...) */
} /* while (fgets) */
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes: fclose: %s", STRERRNO);
}
return count;
} /* int ps_count_maps (...) */
/* Either '(' or ')' is not found or they are in the wrong order.
* Anyway, something weird that shouldn't happen ever. */
if (name_start_pos >= name_end_pos) {
- ERROR("processes plugin: name_start_pos = %zu >= name_end_pos = %zu",
+ ERROR("processes plugin: name_start_pos = %" PRIsz
+ " >= name_end_pos = %" PRIsz,
name_start_pos, name_end_pos);
return -1;
}
errno = 0;
fd = open(file, O_RDONLY);
if (fd < 0) {
- char errbuf[4096];
/* ENOENT means the process exited while we were handling it.
* Don't complain about this, it only fills the logs. */
if (errno != ENOENT)
- WARNING("processes plugin: Failed to open `%s': %s.", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes plugin: Failed to open `%s': %s.", file, STRERRNO);
return NULL;
}
status = read(fd, (void *)buf_ptr, len);
if (status < 0) {
- char errbuf[1024];
if ((EAGAIN == errno) || (EINTR == errno))
continue;
WARNING("processes plugin: Failed to read from `%s': %s.", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
close(fd);
return NULL;
}
proc_stat = fopen("/proc/stat", "r");
if (proc_stat == NULL) {
- char errbuf[1024];
- ERROR("processes plugin: fopen (/proc/stat) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("processes plugin: fopen (/proc/stat) failed: %s", STRERRNO);
return -1;
}
if ((status < 0) || (((size_t)status) != sizeof(info))) {
ERROR("processes plugin: Unexpected return value "
"while reading \"%s\": "
- "Returned %zd but expected %zu.",
+ "Returned %zd but expected %" PRIsz ".",
path, status, buffer_size);
return NULL;
}
ps_list_reset();
if ((proc = opendir("/proc")) == NULL) {
- char errbuf[1024];
- ERROR("Cannot open `/proc': %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("Cannot open `/proc': %s", STRERRNO);
return -1;
}
return -1;
if (ds->ds[i].type == DS_TYPE_COUNTER) {
- status = snprintf(buffer + offset, buffer_len - offset, ":%llu",
- vl->values[i].counter);
+ status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIu64,
+ (uint64_t)vl->values[i].counter);
} else if (ds->ds[i].type == DS_TYPE_GAUGE) {
status = snprintf(buffer + offset, buffer_len - offset, ":%f",
vl->values[i].gauge);
status = stat(filename, &statbuf);
if (status != 0) {
if (errno != ENOENT) {
- char errbuf[1024];
- ERROR("rrdcached plugin: stat (%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("rrdcached plugin: stat (%s) failed: %s", filename, STRERRNO);
return -1;
}
return -1;
if (ds->ds[i].type == DS_TYPE_COUNTER)
- status = snprintf(buffer + offset, buffer_len - offset, ":%llu",
- vl->values[i].counter);
+ status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIu64,
+ (uint64_t)vl->values[i].counter);
else if (ds->ds[i].type == DS_TYPE_GAUGE)
status = snprintf(buffer + offset, buffer_len - offset, ":" GAUGE_FORMAT,
vl->values[i].gauge);
vl->values[0].gauge);
break;
case DS_TYPE_COUNTER:
- status = snprintf(buffer, buffer_len, "%u:%llu", (unsigned)tt,
- vl->values[0].counter);
+ status = snprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt,
+ (uint64_t)vl->values[0].counter);
break;
case DS_TYPE_ABSOLUTE:
status = snprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt,
{
char **tmp = realloc(keys, (keys_num + 1) * sizeof(char *));
if (tmp == NULL) {
- char errbuf[1024];
- ERROR("rrdtool plugin: "
- "realloc failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("rrdtool plugin: realloc failed: %s", STRERRNO);
c_avl_iterator_destroy(iter);
sfree(keys);
return;
return -1;
}
- c_avl_get(cache, filename, (void *)&rc);
-
- if (rc == NULL) {
+ int status = c_avl_get(cache, filename, (void *)&rc);
+ if ((status != 0) || (rc == NULL)) {
rc = malloc(sizeof(*rc));
if (rc == NULL) {
pthread_mutex_unlock(&cache_lock);
values_new =
realloc((void *)rc->values, (rc->values_num + 1) * sizeof(char *));
if (values_new == NULL) {
- char errbuf[1024];
void *cache_key = NULL;
- sstrerror(errno, errbuf, sizeof(errbuf));
-
c_avl_remove(cache, filename, &cache_key, NULL);
pthread_mutex_unlock(&cache_lock);
- ERROR("rrdtool plugin: realloc failed: %s", errbuf);
+ ERROR("rrdtool plugin: realloc failed: %s", STRERRNO);
sfree(cache_key);
sfree(rc->values);
void *cache_key = strdup(filename);
if (cache_key == NULL) {
- char errbuf[1024];
- sstrerror(errno, errbuf, sizeof(errbuf));
-
pthread_mutex_unlock(&cache_lock);
- ERROR("rrdtool plugin: strdup failed: %s", errbuf);
+ ERROR("rrdtool plugin: strdup failed: %s", STRERRNO);
sfree(rc->values[0]);
sfree(rc->values);
if (value_list_to_filename(filename, sizeof(filename), vl) != 0)
return -1;
- char values[32 * ds->ds_num];
+ char values[32 * (ds->ds_num + 1)];
if (value_list_to_string(values, sizeof(values), ds, vl) != 0)
return -1;
return 0;
}
} else {
- char errbuf[1024];
- ERROR("rrdtool plugin: stat(%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("rrdtool plugin: stat(%s) failed: %s", filename, STRERRNO);
return -1;
}
} else if (!S_ISREG(statbuf.st_mode)) {
cache_flush_timeout = 0;
} else if (cache_flush_timeout < cache_timeout) {
INFO("rrdtool plugin: \"CacheFlush %.3f\" is less than \"CacheTimeout "
- "%.3f\". "
- "Ajusting \"CacheFlush\" to %.3f seconds.",
+ "%.3f\". Adjusting \"CacheFlush\" to %.3f seconds.",
CDTIME_T_TO_DOUBLE(cache_flush_timeout),
CDTIME_T_TO_DOUBLE(cache_timeout),
CDTIME_T_TO_DOUBLE(cache_timeout * 10));
}
DEBUG("snmp plugin: dd = { name = %s, type = %s, is_table = %s, values_len = "
- "%zu }",
+ "%" PRIsz " }",
dd->name, dd->type, (dd->is_table != 0) ? "true" : "false",
dd->values_len);
value_t val = csnmp_value_list_to_value(
vb, DS_TYPE_COUNTER,
/* scale = */ 1.0, /* shift = */ 0.0, hd->name, dd->name);
- snprintf(il->instance, sizeof(il->instance), "%llu", val.counter);
+ snprintf(il->instance, sizeof(il->instance), "%" PRIu64,
+ (uint64_t)val.counter);
}
/* TODO: Debugging output */
}
if (ds->ds_num != data->values_len) {
- ERROR("snmp plugin: DataSet `%s' requires %zu values, but config talks "
- "about %zu",
+ ERROR("snmp plugin: DataSet `%s' requires %" PRIsz
+ " values, but config talks "
+ "about %" PRIsz,
data->type, ds->ds_num, data->values_len);
return -1;
}
for (vb = res->variables, i = 0; (vb != NULL);
vb = vb->next_variable, i++) {
/* Calculate value index from todo list */
- while ((i < oid_list_len) && !oid_list_todo[i])
+ while ((i < oid_list_len) && !oid_list_todo[i]) {
i++;
+ }
+ if (i >= oid_list_len) {
+ break;
+ }
/* An instance is configured and the res variable we process is the
* instance value (last index) */
* suffix is increasing. This also checks if we left the subtree */
ret = csnmp_oid_suffix(&suffix, &vb_name, data->values + i);
if (ret != 0) {
- DEBUG("snmp plugin: host = %s; data = %s; i = %zu; "
+ DEBUG("snmp plugin: host = %s; data = %s; i = %" PRIsz "; "
"Value probably left its subtree.",
host->name, data->name, i);
oid_list_todo[i] = 0;
* table matching algorithm will get confused. */
if ((value_list_tail[i] != NULL) &&
(csnmp_oid_compare(&suffix, &value_list_tail[i]->suffix) <= 0)) {
- DEBUG("snmp plugin: host = %s; data = %s; i = %zu; "
+ DEBUG("snmp plugin: host = %s; data = %s; i = %" PRIsz "; "
"Suffix is not increasing.",
host->name, data->name, i);
oid_list_todo[i] = 0;
}
if (ds->ds_num != data->values_len) {
- ERROR("snmp plugin: DataSet `%s' requires %zu values, but config talks "
- "about %zu",
+ ERROR("snmp plugin: DataSet `%s' requires %" PRIsz
+ " values, but config talks "
+ "about %" PRIsz,
data->type, ds->ds_num, data->values_len);
return -1;
}
DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance);
for (size_t i = 0; i < dd->oids_len; i++) {
snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]);
- DEBUG(PLUGIN_NAME ": OID[%zu]: %s", i, oid_str);
+ DEBUG(PLUGIN_NAME ": OID[%" PRIsz "]: %s", i, oid_str);
}
DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale);
DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift);
DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance);
for (size_t i = 0; i < dd->oids_len; i++) {
snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]);
- DEBUG(PLUGIN_NAME ": OID[%zu]: %s", i, oid_str);
+ DEBUG(PLUGIN_NAME ": OID[%" PRIsz "]: %s", i, oid_str);
}
DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale);
DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift);
}
}
- llentry_t *entry = llentry_create(td->name, td);
- if (entry == NULL) {
- snmp_agent_free_table(&td);
- return -ENOMEM;
- }
-
td->instance_index =
c_avl_create((int (*)(const void *, const void *))strcmp);
if (td->instance_index == NULL) {
return -ENOMEM;
}
+ llentry_t *entry = llentry_create(td->name, td);
+ if (entry == NULL) {
+ snmp_agent_free_table(&td);
+ return -ENOMEM;
+ }
llist_append(g_agent->tables, entry);
return 0;
} /* tbl_result_setup */
static void tbl_result_clear(tbl_result_t *res) {
+ if (res == NULL) {
+ return;
+ }
+
sfree(res->type);
sfree(res->instance_prefix);
} /* tbl_setup */
static void tbl_clear(tbl_t *tbl) {
+ if (tbl == NULL) {
+ return;
+ }
+
sfree(tbl->file);
sfree(tbl->sep);
sfree(tbl->plugin_name);
sfree(tbl->instance);
+ /* (tbl->results == NULL) -> (tbl->results_num == 0) */
+ assert((tbl->results != NULL) || (tbl->results_num == 0));
for (size_t i = 0; i < tbl->results_num; ++i)
tbl_result_clear(tbl->results + i);
sfree(tbl->results);
tmp = realloc(*var, ((*len) + num) * sizeof(**var));
if (NULL == tmp) {
- char errbuf[1024];
- log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("realloc failed: %s.", STRERRNO);
return -1;
}
*var = tmp;
} /* tbl_config_append_array_s */
static int tbl_config_result(tbl_t *tbl, oconfig_item_t *ci) {
- tbl_result_t *res;
-
- int status = 0;
-
if (0 != ci->values_num) {
log_err("<Result> does not expect any arguments.");
return 1;
}
- res = realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results));
+ tbl_result_t *res =
+ realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results));
if (res == NULL) {
- char errbuf[1024];
- log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("realloc failed: %s.", STRERRNO);
return -1;
}
tbl->results = res;
- ++tbl->results_num;
- res = tbl->results + tbl->results_num - 1;
+ res = tbl->results + tbl->results_num;
tbl_result_setup(res);
for (int i = 0; i < ci->children_num; ++i) {
c->key);
}
+ int status = 0;
if (NULL == res->type) {
- log_err("No \"Type\" option specified for <Result> "
- "in table \"%s\".",
+ log_err("No \"Type\" option specified for <Result> in table \"%s\".",
tbl->file);
status = 1;
}
if (NULL == res->values) {
- log_err("No \"ValuesFrom\" option specified for <Result> "
- "in table \"%s\".",
+ log_err("No \"ValuesFrom\" option specified for <Result> in table \"%s\".",
tbl->file);
status = 1;
}
if (0 != status) {
tbl_result_clear(res);
- --tbl->results_num;
return status;
}
+
+ tbl->results_num++;
return 0;
} /* tbl_config_result */
static int tbl_config_table(oconfig_item_t *ci) {
- tbl_t *tbl;
-
- int status = 0;
-
if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
log_err("<Table> expects a single string argument.");
return 1;
}
- tbl = realloc(tables, (tables_num + 1) * sizeof(*tables));
+ tbl_t *tbl = realloc(tables, (tables_num + 1) * sizeof(*tables));
if (NULL == tbl) {
- char errbuf[1024];
- log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("realloc failed: %s.", STRERRNO);
return -1;
}
tables = tbl;
- ++tables_num;
- tbl = tables + tables_num - 1;
+ tbl = tables + tables_num;
tbl_setup(tbl, ci->values[0].value.string);
for (size_t i = 0; i < ((size_t)ci->children_num); ++i) {
c->key, tbl->file);
}
+ int status = 0;
if (NULL == tbl->sep) {
log_err("Table \"%s\" does not specify any separator.", tbl->file);
status = 1;
}
if (NULL == tbl->results) {
+ assert(tbl->results_num == 0);
log_err("Table \"%s\" does not specify any (valid) results.", tbl->file);
status = 1;
}
if (0 != status) {
tbl_clear(tbl);
- --tables_num;
return status;
}
if (res->values[j] > tbl->max_colnum)
tbl->max_colnum = res->values[j];
}
+
+ tables_num++;
return 0;
} /* tbl_config_table */
}
if (res->values_num != res->ds->ds_num) {
- log_err("Invalid type \"%s\". Expected %zu data source%s, "
- "got %zu.",
+ log_err("Invalid type \"%s\". Expected %" PRIsz " data source%s, "
+ "got %" PRIsz ".",
res->type, res->values_num, (1 == res->values_num) ? "" : "s",
res->ds->ds_num);
return -1;
if (i <= tbl->max_colnum) {
log_warn("Not enough columns in line "
- "(expected at least %zu, got %zu).",
+ "(expected at least %" PRIsz ", got %" PRIsz ").",
tbl->max_colnum + 1, i);
return -1;
}
fh = fopen(tbl->file, "r");
if (NULL == fh) {
- char errbuf[1024];
- log_err("Failed to open file \"%s\": %s.", tbl->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("Failed to open file \"%s\": %s.", tbl->file, STRERRNO);
return -1;
}
}
if (0 != ferror(fh)) {
- char errbuf[1024];
- log_err("Failed to read from file \"%s\": %s.", tbl->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("Failed to read from file \"%s\": %s.", tbl->file, STRERRNO);
fclose(fh);
return -1;
}
#define print_to_socket(fh, ...) \
if (fprintf(fh, __VA_ARGS__) < 0) { \
- char errbuf[1024]; \
WARNING("handle_getthreshold: failed to write to socket #%i: %s", \
- fileno(fh), sstrerror(errno, errbuf, sizeof(errbuf))); \
+ fileno(fh), STRERRNO); \
return -1; \
}
i++;
/* Print the response */
- print_to_socket(fh, "%zu Threshold found\n", i);
+ print_to_socket(fh, "%" PRIsz " Threshold found\n", i);
if (threshold.host[0] != 0)
print_to_socket(fh, "Host: %s\n", threshold.host);
#define print_to_socket(fh, ...) \
do { \
if (fprintf(fh, __VA_ARGS__) < 0) { \
- char errbuf[1024]; \
WARNING("cmd_handle_getval: failed to write to socket #%i: %s", \
- fileno(fh), sstrerror(errno, errbuf, sizeof(errbuf))); \
+ fileno(fh), STRERRNO); \
return -1; \
} \
fflush(fh); \
}
if (ds->ds_num != values_num) {
- ERROR("ds[%s]->ds_num = %zu, "
- "but uc_get_rate_by_name returned %zu values.",
+ ERROR("ds[%s]->ds_num = %" PRIsz ", "
+ "but uc_get_rate_by_name returned %" PRIsz " values.",
ds->type, ds->ds_num, values_num);
cmd_error(CMD_ERROR, &err, "Error reading value from cache.");
sfree(values);
return CMD_ERROR;
}
- print_to_socket(fh, "%zu Value%s found\n", values_num,
+ print_to_socket(fh, "%" PRIsz " Value%s found\n", values_num,
(values_num == 1) ? "" : "s");
for (size_t i = 0; i < values_num; i++) {
print_to_socket(fh, "%s=", ds->ds[i].name);
else
BUFFER_ADD("null");
} else if (ds->ds[i].type == DS_TYPE_COUNTER)
- BUFFER_ADD("%llu", vl->values[i].counter);
+ BUFFER_ADD("%" PRIu64, (uint64_t)vl->values[i].counter);
else if (ds->ds[i].type == DS_TYPE_DERIVE)
BUFFER_ADD("%" PRIi64, vl->values[i].derive);
else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
} \
} while (0)
+ #define CHECK_SUCCESS(cmd) \
+ do { \
+ yajl_gen_status s = (cmd); \
+ if (s != yajl_gen_status_ok) { \
+ return (int)s; \
+ } \
+ } while (0)
+
static int format_json_meta(yajl_gen g, notification_meta_t *meta) /* {{{ */
{
if (meta == NULL)
default:
ERROR("format_json_meta: unknown meta data type %d (name \"%s\")",
meta->type, meta->name);
- yajl_gen_null(g);
+ CHECK_SUCCESS(yajl_gen_null(g));
}
return format_json_meta(g, meta->next);
static int format_alert(yajl_gen g, notification_t const *n) /* {{{ */
{
- yajl_gen_array_open(g);
- yajl_gen_map_open(g); /* BEGIN alert */
+ CHECK_SUCCESS(yajl_gen_array_open(g)); /* BEGIN array */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN alert */
/*
* labels
*/
JSON_ADD(g, "labels");
- yajl_gen_map_open(g); /* BEGIN labels */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN labels */
JSON_ADD(g, "alertname");
if (strncmp(n->plugin, n->type, strlen(n->plugin)) == 0)
JSON_ADD(g, "service");
JSON_ADD(g, "collectd");
- yajl_gen_map_close(g); /* END labels */
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END labels */
/*
* annotations
*/
JSON_ADD(g, "annotations");
- yajl_gen_map_open(g); /* BEGIN annotations */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN annotations */
JSON_ADD(g, "summary");
JSON_ADD(g, n->message);
- if (format_json_meta(g, n->meta) != 0)
+ if (format_json_meta(g, n->meta) != 0) {
return -1;
+ }
- yajl_gen_map_close(g); /* END annotations */
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END annotations */
JSON_ADD(g, "startsAt");
- format_time(g, n->time);
+ if (format_time(g, n->time) != 0) {
+ return -1;
+ }
- yajl_gen_map_close(g); /* END alert */
- yajl_gen_array_close(g);
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END alert */
+ CHECK_SUCCESS(yajl_gen_array_close(g)); /* END array */
return 0;
} /* }}} format_alert */
}
/* copy to output buffer */
- yajl_gen_get_buf(g, &out, &unused_out_len);
+ if (yajl_gen_get_buf(g, &out, &unused_out_len) != yajl_gen_status_ok) {
+ yajl_gen_clear(g);
+ yajl_gen_free(g);
+ return -1;
+ }
sstrncpy(buffer, (void *)out, buffer_size);
yajl_gen_clear(g);
#define OVS_DB_POLL_READ_BLOCK_SIZE 512 /* read block size (bytes) */
#define OVS_DB_DEFAULT_DB_NAME "Open_vSwitch"
+ #define OVS_DB_EVENT_NONE 0
#define OVS_DB_EVENT_TIMEOUT 5 /* event thread timeout (sec) */
#define OVS_DB_EVENT_TERMINATE 1
#define OVS_DB_EVENT_CONN_ESTABLISHED 2
/* Remove all callbacks form OVS DB object */
static void ovs_db_callback_remove_all(ovs_db_t *pdb) {
pthread_mutex_lock(&pdb->mutex);
- for (ovs_callback_t *del_cb = pdb->remote_cb; pdb->remote_cb;
- del_cb = pdb->remote_cb) {
+ while (pdb->remote_cb != NULL) {
+ ovs_callback_t *del_cb = pdb->remote_cb;
pdb->remote_cb = del_cb->next;
- free(del_cb);
+ sfree(del_cb);
}
- pdb->remote_cb = NULL;
pthread_mutex_unlock(&pdb->mutex);
}
return -1;
sstrncpy(sjson, data, len + 1);
- OVS_DEBUG("[len=%zu] %s", len, sjson);
+ OVS_DEBUG("[len=%" PRIsz "] %s", len, sjson);
/* parse json data */
jnode = yajl_tree_parse(sjson, yajl_errbuf, sizeof(yajl_errbuf));
}
/* try to connect to the server */
for (struct addrinfo *rp = result; rp != NULL; rp = rp->ai_next) {
- char errbuff[OVS_ERROR_BUFF_SIZE];
int sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sock < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_DEBUG("socket(): %s", errbuff);
+ OVS_DEBUG("socket(): %s", STRERRNO);
continue;
}
if (connect(sock, rp->ai_addr, rp->ai_addrlen) < 0) {
close(sock);
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_DEBUG("connect(): %s [family=%d]", errbuff, rp->ai_family);
+ OVS_DEBUG("connect(): %s [family=%d]", STRERRNO, rp->ai_family);
} else {
/* send notification to event thread */
- ovs_db_event_post(pdb, OVS_DB_EVENT_CONN_ESTABLISHED);
pdb->sock = sock;
+ ovs_db_event_post(pdb, OVS_DB_EVENT_CONN_ESTABLISHED);
break;
}
}
/* poll data */
while (ovs_db_poll_is_running(pdb)) {
- char errbuff[OVS_ERROR_BUFF_SIZE];
poll_fd.fd = pdb->sock;
int poll_ret = poll(&poll_fd, 1, /* ms */ OVS_DB_POLL_TIMEOUT * 1000);
if (poll_ret < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_ERROR("poll(): %s", errbuff);
+ OVS_ERROR("poll(): %s", STRERRNO);
break;
} else if (poll_ret == 0) {
OVS_DEBUG("poll(): timeout");
char buff[OVS_DB_POLL_READ_BLOCK_SIZE];
ssize_t nbytes = recv(poll_fd.fd, buff, sizeof(buff), 0);
if (nbytes < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_ERROR("recv(): %s", errbuff);
+ OVS_ERROR("recv(): %s", STRERRNO);
/* read error? Try to reconnect */
close(poll_fd.fd);
continue;
ts.tv_sec += (OVS_DB_EVENT_TIMEOUT);
int ret = pthread_cond_timedwait(&pdb->event_thread.cond,
&pdb->event_thread.mutex, &ts);
- if (!ret) {
+ if (!ret || ret == ETIMEDOUT) {
/* handle the event */
OVS_DEBUG("handle event %d", pdb->event_thread.value);
switch (pdb->event_thread.value) {
case OVS_DB_EVENT_CONN_ESTABLISHED:
if (pdb->cb.post_conn_init)
pdb->cb.post_conn_init(pdb);
+ /* reset event */
+ pdb->event_thread.value = OVS_DB_EVENT_NONE;
break;
case OVS_DB_EVENT_CONN_TERMINATED:
if (pdb->cb.post_conn_terminate)
pdb->cb.post_conn_terminate();
+ /* reset event */
+ pdb->event_thread.value = OVS_DB_EVENT_NONE;
+ break;
+ case OVS_DB_EVENT_NONE:
+ /* wait timeout */
+ OVS_DEBUG("no event received (timeout)");
break;
default:
OVS_DEBUG("unknown event received");
break;
}
- } else if (ret == ETIMEDOUT) {
- /* wait timeout */
- OVS_DEBUG("no event received (timeout)");
- continue;
} else {
/* unexpected error */
OVS_ERROR("pthread_cond_timedwait() failed");
/* Initialize EVENT thread */
static int ovs_db_event_thread_init(ovs_db_t *pdb) {
- pdb->event_thread.tid = (pthread_t)-1;
+ pdb->event_thread.tid = (pthread_t){0};
/* init event thread condition variable */
if (pthread_cond_init(&pdb->event_thread.cond, NULL)) {
return -1;
return 0;
}
- /* Destroy EVENT thread */
- static int ovs_db_event_thread_destroy(ovs_db_t *pdb) {
- if (pdb->event_thread.tid == (pthread_t)-1)
- /* already destroyed */
+ /* Terminate EVENT thread */
+ static int ovs_db_event_thread_terminate(ovs_db_t *pdb) {
+ if (pthread_equal(pdb->event_thread.tid, (pthread_t){0})) {
+ /* already terminated */
return 0;
+ }
ovs_db_event_post(pdb, OVS_DB_EVENT_TERMINATE);
if (pthread_join(pdb->event_thread.tid, NULL) != 0)
return -1;
* performs some task (handles event) and releases it when
* while sleeping. Thus, if event thread exits, the mutex
* remains locked */
+ pdb->event_thread.tid = (pthread_t){0};
pthread_mutex_unlock(&pdb->event_thread.mutex);
+ return 0;
+ }
+
+ /* Destroy EVENT thread private data */
+ static void ovs_db_event_thread_data_destroy(ovs_db_t *pdb) {
+ /* destroy mutex */
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
- pdb->event_thread.tid = (pthread_t)-1;
- return 0;
}
/* Initialize POLL thread */
static int ovs_db_poll_thread_init(ovs_db_t *pdb) {
- pdb->poll_thread.tid = (pthread_t)-1;
+ pdb->poll_thread.tid = (pthread_t){0};
/* init event thread mutex */
if (pthread_mutex_init(&pdb->poll_thread.mutex, NULL)) {
return -1;
}
/* Destroy POLL thread */
+ /* XXX: Must hold pdb->mutex when calling! */
static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
- if (pdb->poll_thread.tid == (pthread_t)-1)
+ if (pthread_equal(pdb->poll_thread.tid, (pthread_t){0})) {
/* already destroyed */
return 0;
+ }
/* change thread state */
pthread_mutex_lock(&pdb->poll_thread.mutex);
pdb->poll_thread.state = OVS_DB_POLL_STATE_EXITING;
if (pthread_join(pdb->poll_thread.tid, NULL) != 0)
return -1;
pthread_mutex_destroy(&pdb->poll_thread.mutex);
- pdb->poll_thread.tid = (pthread_t)-1;
+ pdb->poll_thread.tid = (pthread_t){0};
return 0;
}
return NULL;
/* allocate db data & fill it */
- ovs_db_t *pdb = pdb = calloc(1, sizeof(*pdb));
+ ovs_db_t *pdb = calloc(1, sizeof(*pdb));
if (pdb == NULL)
return NULL;
+ pdb->sock = -1;
/* store the OVS DB address */
sstrncpy(pdb->node, node, sizeof(pdb->node));
}
/* init polling thread */
- pdb->sock = -1;
if (ovs_db_poll_thread_init(pdb) < 0) {
ovs_db_destroy(pdb);
return NULL;
if (pdb == NULL)
return -1;
+ /* stop event thread */
+ if (ovs_db_event_thread_terminate(pdb) < 0) {
+ OVS_ERROR("stop event thread failed");
+ ovs_db_ret = -1;
+ }
+
/* try to lock the structure before releasing */
if ((ret = pthread_mutex_lock(&pdb->mutex))) {
OVS_ERROR("pthread_mutex_lock() DB mutex lock failed (%d)", ret);
return -1;
}
- /* stop poll thread */
- if (ovs_db_event_thread_destroy(pdb) < 0) {
+ /* stop poll thread and destroy thread's private data */
+ if (ovs_db_poll_thread_destroy(pdb) < 0) {
OVS_ERROR("destroy poll thread failed");
- ovs_db_ret = (-1);
+ ovs_db_ret = -1;
}
- /* stop event thread */
- if (ovs_db_poll_thread_destroy(pdb) < 0) {
- OVS_ERROR("stop event thread failed");
- ovs_db_ret = (-1);
- }
+ /* destroy event thread private data */
+ ovs_db_event_thread_data_destroy(pdb);
+
+ pthread_mutex_unlock(&pdb->mutex);
/* unsubscribe callbacks */
ovs_db_callback_remove_all(pdb);
close(pdb->sock);
/* release DB handler */
- pthread_mutex_unlock(&pdb->mutex);
pthread_mutex_destroy(&pdb->mutex);
sfree(pdb);
return ovs_db_ret;
#ifdef HAVE_BLOCK_STATS_FLAGS
#define GET_BLOCK_INFO_VALUE(NAME, FIELD) \
- do { \
- if (!strcmp(param[i].field, NAME)) { \
- binfo->FIELD = param[i].value.l; \
- continue; \
- } \
- } while (0)
+ if (!strcmp(param[i].field, NAME)) { \
+ binfo->FIELD = param[i].value.l; \
+ continue; \
+ }
static int get_block_info(struct lv_block_info *binfo,
virTypedParameterPtr param, int nparams) {
(time_diff_sec * node_cpus * NANOSEC_IN_SEC);
}
- DEBUG(PLUGIN_NAME ": node_cpus=%u cpu_time_old=%llu cpu_time_new=%llu"
- "cpu_time_diff=%llu time_diff_sec=%f percent=%f",
- node_cpus, cpu_time_old, cpu_time_new, cpu_time_diff, time_diff_sec,
- percent);
+ DEBUG(PLUGIN_NAME ": node_cpus=%u cpu_time_old=%" PRIu64
+ " cpu_time_new=%" PRIu64 "cpu_time_diff=%" PRIu64
+ " time_diff_sec=%f percent=%f",
+ node_cpus, (uint64_t)cpu_time_old, (uint64_t)cpu_time_new,
+ (uint64_t)cpu_time_diff, time_diff_sec, percent);
return percent;
}
memset(lv_ud, 0, sizeof(*lv_ud));
- snprintf(inst->tag, sizeof(inst->tag), "%s-%zu", PLUGIN_NAME, i);
+ snprintf(inst->tag, sizeof(inst->tag), "%s-%" PRIsz, PLUGIN_NAME, i);
inst->id = i;
user_data_t *ud = &(lv_ud->ud);
status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf));
if (status != 0) {
if (cb->log_send_errors) {
- char errbuf[1024];
ERROR("write_graphite plugin: send to %s:%s (%s) failed with status %zi "
"(%s)",
- cb->node, cb->service, cb->protocol, status,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ cb->node, cb->service, cb->protocol, status, STRERRNO);
}
close(cb->sock_fd);
int status;
DEBUG("write_graphite plugin: wg_flush_nolock: timeout = %.3f; "
- "send_buf_fill = %zu;",
+ "send_buf_fill = %" PRIsz ";",
(double)timeout, cb->send_buf_fill);
/* timeout == 0 => flush unconditionally */
cb->sock_fd =
socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (cb->sock_fd < 0) {
- char errbuf[1024];
- snprintf(connerr, sizeof(connerr), "failed to open socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ snprintf(connerr, sizeof(connerr), "failed to open socket: %s", STRERRNO);
continue;
}
status = connect(cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- snprintf(connerr, sizeof(connerr), "failed to connect to remote "
- "host: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ snprintf(connerr, sizeof(connerr), "failed to connect to remote host: %s",
+ STRERRNO);
close(cb->sock_fd);
cb->sock_fd = -1;
continue;
freeaddrinfo(ai_list);
if (cb->sock_fd < 0) {
- if (connerr[0] == '\0')
- /* this should not happen but try to get a message anyway */
- sstrerror(errno, connerr, sizeof(connerr));
c_complain(LOG_ERR, &cb->init_complaint,
"write_graphite plugin: Connecting to %s:%s via %s failed. "
"The last error was: %s",
sfree(cb->prefix);
sfree(cb->postfix);
+ pthread_mutex_unlock(&cb->send_lock);
pthread_mutex_destroy(&cb->send_lock);
sfree(cb);
cb->send_buf_fill += message_len;
cb->send_buf_free -= message_len;
- DEBUG("write_graphite plugin: [%s]:%s (%s) buf %zu/%zu (%.1f %%) \"%s\"",
+ DEBUG("write_graphite plugin: [%s]:%s (%s) buf %" PRIsz "/%" PRIsz
+ " (%.1f %%) \"%s\"",
cb->node, cb->service, cb->protocol, cb->send_buf_fill,
sizeof(cb->send_buf),
100.0 * ((double)cb->send_buf_fill) / ((double)sizeof(cb->send_buf)),
{
char ds_index[DATA_MAX_NAME_LEN];
- snprintf(ds_index, sizeof(ds_index), "%zu", index);
+ snprintf(ds_index, sizeof(ds_index), "%" PRIsz, index);
riemann_event_string_attribute_add(event, "ds_index", ds_index);
}
wrr_disconnect(host);
+ pthread_mutex_lock(&host->lock);
pthread_mutex_destroy(&host->lock);
sfree(host);
} /* }}} void wrr_free */
#include "common.h"
#include "plugin.h"
#include "utils_cache.h"
-
#include <arpa/inet.h>
#include <errno.h>
#include <inttypes.h>
// incorporate the data source index
{
char ds_index[DATA_MAX_NAME_LEN];
- snprintf(ds_index, sizeof(ds_index), "%zu", index);
+ snprintf(ds_index, sizeof(ds_index), "%" PRIsz, index);
res = my_asprintf(&temp_str, "%s, \"collectd_data_source_index\": %s",
ret_str, ds_index);
free(ret_str);
return NULL;
}
} else {
- res = my_asprintf(&value_str, "%llu", vl->values[index].counter);
+ res = my_asprintf(&value_str, "%" PRIu64,
+ (uint64_t)vl->values[index].counter);
if (res == -1) {
free(ret_str);
ERROR("write_sensu plugin: Unable to alloc memory");
sensu_close_socket(host);
if (status != 0) {
- char errbuf[1024];
ERROR("write_sensu plugin: Sending to Sensu at %s:%s failed: %s",
(host->node != NULL) ? host->node : SENSU_HOST,
- (host->service != NULL) ? host->service : SENSU_PORT,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ (host->service != NULL) ? host->service : SENSU_PORT, STRERRNO);
return -1;
}
sfree(host->separator);
free_str_list(&(host->metric_handlers));
free_str_list(&(host->notification_handlers));
+
+ pthread_mutex_unlock(&host->lock);
pthread_mutex_destroy(&host->lock);
+
sfree(host);
} /* }}} void sensu_free */
status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf));
if (status != 0) {
- char errbuf[1024];
ERROR("write_tsdb plugin: send failed with status %zi (%s)", status,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
close(cb->sock_fd);
cb->sock_fd = -1;
int status;
DEBUG("write_tsdb plugin: wt_flush_nolock: timeout = %.3f; "
- "send_buf_fill = %zu;",
+ "send_buf_fill = %" PRIsz ";",
(double)timeout, cb->send_buf_fill);
/* timeout == 0 => flush unconditionally */
}
if (cb->sock_fd < 0) {
- char errbuf[1024];
ERROR("write_tsdb plugin: Connecting to %s:%s failed. "
"The last error was: %s",
- node, service, sstrerror(errno, errbuf, sizeof(errbuf)));
+ node, service, STRERRNO);
return -1;
}
sfree(cb->service);
sfree(cb->host_tags);
+ pthread_mutex_unlock(&cb->send_lock);
pthread_mutex_destroy(&cb->send_lock);
sfree(cb);
}
BUFFER_ADD(GAUGE_FORMAT, rates[ds_num]);
} else if (ds->ds[ds_num].type == DS_TYPE_COUNTER)
- BUFFER_ADD("%llu", vl->values[ds_num].counter);
+ BUFFER_ADD("%" PRIu64, (uint64_t)vl->values[ds_num].counter);
else if (ds->ds[ds_num].type == DS_TYPE_DERIVE)
BUFFER_ADD("%" PRIi64, vl->values[ds_num].derive);
else if (ds->ds[ds_num].type == DS_TYPE_ABSOLUTE)
if (message_len >= sizeof(message)) {
ERROR("write_tsdb plugin: message buffer too small: "
- "Need %zu bytes.",
+ "Need %" PRIsz " bytes.",
message_len + 1);
return -1;
}
cb->send_buf_fill += message_len;
cb->send_buf_free -= message_len;
- DEBUG("write_tsdb plugin: [%s]:%s buf %zu/%zu (%.1f %%) \"%s\"", cb->node,
- cb->service, cb->send_buf_fill, sizeof(cb->send_buf),
+ DEBUG("write_tsdb plugin: [%s]:%s buf %" PRIsz "/%" PRIsz " (%.1f %%) \"%s\"",
+ cb->node, cb->service, cb->send_buf_fill, sizeof(cb->send_buf),
100.0 * ((double)cb->send_buf_fill) / ((double)sizeof(cb->send_buf)),
message);