From: Sean Campbell Date: Wed, 6 Dec 2017 00:05:08 +0000 (-0500) Subject: Merge branch 'master' into pri X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=4c4988b1c5d33ed70b2d6d6e5a4eae13cab9255b;hp=-c Merge branch 'master' into pri --- 4c4988b1c5d33ed70b2d6d6e5a4eae13cab9255b diff --combined src/amqp.c index 423b251c,a8df8881..6c184488 --- a/src/amqp.c +++ b/src/amqp.c @@@ -441,10 -441,8 +441,8 @@@ static int camqp_connect(camqp_config_ 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; @@@ -454,10 -452,8 +452,8 @@@ /* 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; @@@ -507,7 -503,7 +503,7 @@@ 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; @@@ -545,10 -541,8 +541,8 @@@ static int camqp_read_body(camqp_config 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; } @@@ -597,10 -591,8 +591,8 @@@ static int camqp_read_header(camqp_conf 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; } @@@ -693,9 -685,7 +685,7 @@@ static int camqp_subscribe_init(camqp_c 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; } diff --combined src/barometer.c index 0fa62fb6,2db1ea41..6c6347c9 --- a/src/barometer.c +++ b/src/barometer.c @@@ -412,16 -412,16 +412,16 @@@ static int get_reference_temperature(do 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; @@@ -444,7 -444,7 +444,7 @@@ } 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]; @@@ -464,9 -464,8 +464,9 @@@ } 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; @@@ -515,12 -514,11 +515,11 @@@ */ 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; } @@@ -549,14 -547,11 +548,11 @@@ static int MPL115_read_coeffs(void) 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; } @@@ -658,7 -653,6 +654,6 @@@ static int MPL115_read_averaged(double int conv_temperature; double adc_pressure; double adc_temperature; - char errbuf[1024]; *pressure = 0.0; *temperature = 0.0; @@@ -675,11 -669,11 +670,11 @@@ 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; } } @@@ -698,11 -692,11 +693,11 @@@ 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; } } @@@ -739,12 -733,11 +734,11 @@@ */ 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; } @@@ -811,21 -804,18 +805,18 @@@ static int MPL3115_read(double *pressur __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; } @@@ -836,7 -826,7 +827,7 @@@ 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; } @@@ -849,7 -839,7 +840,7 @@@ 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; } } @@@ -858,8 -848,7 +849,7 @@@ 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; } @@@ -889,7 -878,6 +879,6 @@@ 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. */ @@@ -907,7 -895,7 +896,7 @@@ 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; } @@@ -918,7 -906,7 +907,7 @@@ if (res < 0) { ERROR( "barometer: MPL3115_init_sensor - problem setting pressure offset: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); return -1; } @@@ -928,7 -916,7 +917,7 @@@ 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; } @@@ -937,7 -925,7 +926,7 @@@ mpl3115_oversample); if (res < 0) { ERROR("barometer: MPL3115_init_sensor - problem configuring CTRL_REG1: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); return -1; } @@@ -955,12 -943,11 +944,11 @@@ */ 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; } @@@ -972,7 -959,7 +960,7 @@@ 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", @@@ -1034,13 -1021,11 +1022,11 @@@ static void BMP085_adjust_oversampling( 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; } @@@ -1141,15 -1126,13 +1127,13 @@@ static int BMP085_read(double *pressure 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; } @@@ -1159,7 -1142,7 +1143,7 @@@ 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; } @@@ -1170,7 -1153,7 +1154,7 @@@ bmp085_cmdCnvPress); if (res < 0) { ERROR("barometer: BMP085_read - problem requesting pressure conversion: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); return 1; } @@@ -1180,7 -1163,7 +1164,7 @@@ 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; } @@@ -1572,7 -1555,6 +1556,6 @@@ static int BMP085_collectd_barometer_re * @return Zero when successful. */ static int collectd_barometer_init(void) { - char errbuf[1024]; DEBUG("barometer: collectd_barometer_init"); @@@ -1597,7 -1579,7 +1580,7 @@@ 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; } diff --combined src/ceph.c index cc13a608,73140a54..df4a720e --- a/src/ceph.c +++ b/src/ceph.c @@@ -280,7 -280,7 +280,7 @@@ static int ceph_cb_number(void *ctx, co * 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)) { @@@ -1341,7 -1341,7 +1341,7 @@@ static int cconn_main_loop(uint32_t req 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; diff --combined src/csv.c index b9d9287e,59d1d2fe..f5126d26 --- a/src/csv.c +++ b/src/csv.c @@@ -74,8 -74,8 +74,8 @@@ static int value_list_to_string(char *b } 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); @@@ -161,9 -161,7 +161,7 @@@ static int csv_create_file(const char * 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; } @@@ -258,9 -256,7 +256,7 @@@ static int csv_write(const data_set_t * 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)) { @@@ -270,9 -266,7 +266,7 @@@ 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); @@@ -283,9 -277,7 +277,7 @@@ 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; } diff --combined src/daemon/common.c index 3ec56a12,60cebcf9..bf833ee8 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@@ -629,14 -629,10 +629,10 @@@ int check_create_dir(const char *file_o 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)) { @@@ -893,7 -889,7 +889,7 @@@ int format_values(char *ret, size_t ret } 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) @@@ -1210,9 -1206,7 +1206,7 @@@ int walk_directory(const char *dir, dir 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; } diff --combined src/daemon/plugin.c index 7c6cf829,4b7a58ec..438366c2 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@@ -389,50 -389,44 +389,44 @@@ static int plugin_unregister(llist_t *l 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; } @@@ -610,9 -604,7 +604,7 @@@ static void set_thread_name(pthread_t t #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); @@@ -638,15 -630,14 +630,14 @@@ static void start_read_threads(size_t 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++; @@@ -657,7 -648,7 +648,7 @@@ static void stop_read_threads(void) 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; @@@ -845,15 -836,14 +836,14 @@@ static void start_write_threads(size_t /* 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++; @@@ -868,7 -858,7 +858,7 @@@ static void stop_write_threads(void) / 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; @@@ -900,7 -890,7 +890,7 @@@ 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"); } @@@ -1009,9 -999,7 +999,7 @@@ int plugin_load(char const *plugin_name } 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; } @@@ -1026,9 -1014,7 +1014,7 @@@ } 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 */ @@@ -1970,8 -1956,8 +1956,8 @@@ static int plugin_dispatch_values_inter #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; } @@@ -2092,10 -2078,9 +2078,9 @@@ int plugin_dispatch_values(value_list_ 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; } @@@ -2462,9 -2447,7 +2447,7 @@@ static plugin_ctx_t *plugin_ctx_create( 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; } diff --combined src/daemon/types_list.c index 8cfddda5,3b3b8f45..1ccf10bc --- a/src/daemon/types_list.c +++ b/src/daemon/types_list.c @@@ -39,7 -39,7 +39,7 @@@ static int parse_ds(data_source_t *dsrc 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; } @@@ -121,8 -121,8 +121,8 @@@ static void parse_line(char *buf) 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); @@@ -174,11 -174,9 +174,9 @@@ int read_types_list(const char *file) 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; } diff --combined src/dpdkstat.c index 7ef11791,134801ba..59ab9760 --- a/src/dpdkstat.c +++ b/src/dpdkstat.c @@@ -125,9 -125,8 +125,8 @@@ static int dpdk_stats_preinit(void) 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; } @@@ -430,7 -429,7 +429,7 @@@ static int dpdk_stats_reinit_helper() 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; @@@ -446,9 -445,8 +445,8 @@@ 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; } diff --combined src/email.c index 82fdb9f1,c0f28d04..91764d22 --- a/src/email.c +++ b/src/email.c @@@ -265,18 -265,16 +265,16 @@@ static void *collect(void *arg) 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); @@@ -367,9 -365,8 +365,8 @@@ static void *open_connection(void __att /* 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); } @@@ -380,21 -377,19 +377,19 @@@ 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); } @@@ -413,25 -408,21 +408,21 @@@ 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 */ @@@ -453,9 -444,7 +444,7 @@@ 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; } } @@@ -483,16 -472,13 +472,13 @@@ 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); } @@@ -537,10 -523,8 +523,8 @@@ 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; } diff --combined src/gmond.c index 2162463b,09f94ae7..cb005fd9 --- a/src/gmond.c +++ b/src/gmond.c @@@ -217,12 -217,10 +217,10 @@@ static int create_sockets(socket_entry_ 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; } @@@ -241,9 -239,7 +239,7 @@@ 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; } @@@ -261,17 -257,13 +257,13 @@@ 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; } @@@ -291,9 -283,7 +283,7 @@@ 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, @@@ -302,9 -292,7 +292,7 @@@ 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) { @@@ -322,9 -310,7 +310,7 @@@ 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 = { @@@ -335,9 -321,7 +321,7 @@@ 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) */ @@@ -393,9 -377,7 +377,7 @@@ static int request_meta_data(const cha /* 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; } } @@@ -472,8 -454,7 +454,8 @@@ static int staging_entry_update(const c } 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; } @@@ -738,9 -719,7 +720,7 @@@ static int mc_handle_socket(struct poll 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; } @@@ -786,11 -765,9 +766,9 @@@ static void *mc_receive_thread(void *ar 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; } diff --combined src/libcollectdclient/network_parse.c index 04de8c04,2365ab0a..49b1a007 --- a/src/libcollectdclient/network_parse.c +++ b/src/libcollectdclient/network_parse.c @@@ -31,7 -31,6 +31,7 @@@ #include "collectd/lcc_features.h" #include "collectd/network_parse.h" +#include "globals.h" #include #include @@@ -44,6 -43,23 +44,23 @@@ #include #elif HAVE_SYS_ENDIAN_H #include + #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 @@@ -433,7 -449,7 +450,7 @@@ static int decrypt_aes256(buffer_t *b, 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, @@@ -518,7 -534,7 +535,7 @@@ static int network_parse(void *data, si 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; } diff --combined src/libcollectdclient/network_parse_test.c index 17b50ffb,07010fbd..a638642c --- a/src/libcollectdclient/network_parse_test.c +++ b/src/libcollectdclient/network_parse_test.c @@@ -245,9 -245,10 +245,9 @@@ static int test_network_parse() 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; } @@@ -256,13 -257,12 +256,13 @@@ .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; @@@ -376,7 -376,7 +376,7 @@@ static int test_parse_values() } 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; } @@@ -384,8 -384,7 +384,8 @@@ 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; } @@@ -413,6 -412,7 +413,7 @@@ return ret; } + #if HAVE_GCRYPT_H static int test_verify_sha256() { int ret = 0; @@@ -442,7 -442,9 +443,9 @@@ return ret; } + #endif + #if HAVE_GCRYPT_H static int test_decrypt_aes256() { char const *iv_str = "4cbe2a747c9f9dcfa0e66f0c2fa74875"; uint8_t iv[16] = {0}; @@@ -481,12 -483,11 +484,11 @@@ return 0; } + #endif int main(void) { int ret = 0; - printf("libcollectdclient/server_test.c\n"); - int status; if ((status = test_network_parse())) { ret = status; @@@ -501,12 -502,14 +503,14 @@@ ret = status; } + #if HAVE_GCRYPT_H if ((status = test_verify_sha256())) { ret = status; } if ((status = test_decrypt_aes256())) { ret = status; } + #endif return ret; } diff --combined src/modbus.c index 6689d24e,ad5e58e0..31f0c2da --- a/src/modbus.c +++ b/src/modbus.c @@@ -417,7 -417,7 +417,7 @@@ static int mb_read_data(mb_host_t *host } 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; @@@ -770,10 -770,8 +770,8 @@@ static int mb_config_set_host_address(m 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; } diff --combined src/netlink.c index 888b1645,b5ae3bd2..0f71ce7c --- a/src/netlink.c +++ b/src/netlink.c @@@ -358,8 -358,10 +358,10 @@@ static int link_filter_cb(const struct 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); @@@ -374,8 -376,10 +376,10 @@@ 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); @@@ -400,8 -404,10 +404,10 @@@ static int qos_attr_cb(const struct nla 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); @@@ -458,7 -464,7 +464,7 @@@ static int qos_filter_cb(const struct n 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; } @@@ -550,8 -556,10 +556,10 @@@ 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); @@@ -686,8 -694,10 +694,10 @@@ static int ir_read(void) 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 @@@ -707,7 -717,7 +717,7 @@@ 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); @@@ -731,10 -741,11 +741,11 @@@ 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) */ diff --combined src/network.c index 9b8ef535,e5b8b3a8..fcacd38a --- a/src/network.c +++ b/src/network.c @@@ -753,7 -753,7 +753,7 @@@ static int parse_part_values(void **ret if (buffer_len < 15) { NOTICE("network plugin: packet is too short: " - "buffer_len = %zu", + "buffer_len = %" PRIsz, buffer_len); return -1; } @@@ -777,8 -777,8 +777,8 @@@ 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; } @@@ -857,8 -857,8 +857,8 @@@ static int parse_part_number(void **ret 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; } @@@ -898,8 -898,8 +898,8 @@@ static int parse_part_string(void **ret 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; } @@@ -918,7 -918,7 +918,7 @@@ 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; } @@@ -939,9 -939,9 +939,9 @@@ 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; } @@@ -1578,9 -1578,7 +1578,7 @@@ static int network_set_ttl(const socken 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) { @@@ -1596,9 -1594,7 +1594,7 @@@ 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; } } @@@ -1634,9 -1630,7 +1630,7 @@@ static int network_set_interface(const 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; } @@@ -1648,9 -1642,7 +1642,7 @@@ 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; } @@@ -1671,9 -1663,7 +1663,7 @@@ 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 */ @@@ -1704,17 -1694,14 +1694,14 @@@ static int network_bind_socket(int fd, /* 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; } @@@ -1742,17 -1729,13 +1729,13 @@@ 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; } @@@ -1782,17 -1765,13 +1765,13 @@@ 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; } @@@ -1815,9 -1794,7 +1794,7 @@@ 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; } } @@@ -1994,9 -1971,7 +1971,7 @@@ static int sockent_client_connect(socke 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; } @@@ -2081,9 -2056,7 +2056,7 @@@ static int sockent_server_listen(socken *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; } @@@ -2231,11 -2204,9 +2204,9 @@@ static int network_receive(void) /* {{ 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; } @@@ -2249,10 -2220,8 +2220,8 @@@ 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; } @@@ -2362,13 -2331,11 +2331,11 @@@ static void network_send_buffer_plain(s /* 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; } @@@ -2480,7 -2447,7 +2447,7 @@@ static void network_send_buffer_encrypt assert(buffer_size <= sizeof(buffer)); DEBUG("network plugin: network_send_buffer_encrypted: " - "buffer_size = %zu;", + "buffer_size = %" PRIsz ";", buffer_size); pea.head.length = htons( @@@ -2531,8 -2498,7 +2498,8 @@@ 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 @@@ -3168,9 -3134,7 +3135,7 @@@ static int network_init(void) 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; } @@@ -3182,9 -3146,7 +3147,7 @@@ 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; } diff --combined src/ntpd.c index 35c95c0c,39bbeeb5..84512d2b --- a/src/ntpd.c +++ b/src/ntpd.c @@@ -337,10 -337,8 +337,8 @@@ static int ntpd_connect(void) .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; } @@@ -409,9 -407,7 +407,7 @@@ static int ntpd_receive_response(int *r *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 */ @@@ -421,9 -417,7 +417,7 @@@ 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; } @@@ -447,9 -441,7 +441,7 @@@ 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; } @@@ -466,8 -458,7 +458,7 @@@ 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; @@@ -593,7 -584,7 +584,7 @@@ * 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) { @@@ -763,10 -754,8 +754,8 @@@ static int ntpd_get_name_from_address(c 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; } diff --combined src/perl.c index cf300447,1bb0b333..5ad99ee4 --- a/src/perl.c +++ b/src/perl.c @@@ -331,12 -331,12 +331,12 @@@ static size_t av2value(pTHX_ char *name 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); } @@@ -706,10 -706,8 +706,8 @@@ static int value_list2hv(pTHX_ value_li 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); diff --combined src/ping.c index 23b724c9,89aee754..1ffd72b7 --- a/src/ping.c +++ b/src/ping.c @@@ -81,11 -81,11 +81,11 @@@ static double ping_interval = 1.0 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 @@@ -224,8 -224,6 +224,6 @@@ static int ping_dispatch_all(pingobj_t static void *ping_thread(void *arg) /* {{{ */ { - pingobj_t *pingobj = NULL; - struct timeval tv_begin; struct timeval tv_end; struct timespec ts_wait; @@@ -235,11 -233,10 +233,10 @@@ 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; @@@ -276,6 -273,7 +273,7 @@@ 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; @@@ -291,21 -289,19 +289,19 @@@ 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)); @@@ -323,9 -319,7 +319,7 @@@ (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; } @@@ -436,9 -430,8 +430,8 @@@ static int config_set_string(const cha 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; } @@@ -456,18 -449,14 +449,14 @@@ static int ping_config(const char *key 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; } @@@ -532,7 -521,7 +521,7 @@@ } /* }}} 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; diff --combined src/powerdns.c index 2d7dd2bb,efeeb313..729a15b4 --- a/src/powerdns.c +++ b/src/powerdns.c @@@ -44,15 -44,12 +44,12 @@@ #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" @@@ -355,7 -352,7 +352,7 @@@ static void submit(const char *plugin_i } 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; @@@ -379,8 -376,8 +376,8 @@@ 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; @@@ -478,14 -475,11 +475,11 @@@ 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; @@@ -533,13 -527,14 +527,14 @@@ 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; @@@ -550,23 -545,20 +545,20 @@@ } /* 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; @@@ -575,19 -567,6 +567,6 @@@ 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) { @@@ -595,16 -574,21 +574,21 @@@ 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); @@@ -612,12 -596,13 +596,13 @@@ /* 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; @@@ -691,7 -676,6 +676,6 @@@ static int powerdns_update_recursor_com static int powerdns_read_recursor(list_item_t *item) /* {{{ */ { char *buffer = NULL; - size_t buffer_size = 0; int status; char *dummy; @@@ -714,7 -698,7 +698,7 @@@ } 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; diff --combined src/processes.c index 32b48cf8,30c4954a..a3287305 --- a/src/processes.c +++ b/src/processes.c @@@ -502,7 -502,7 +502,7 @@@ static void ps_list_add(const char *nam 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, @@@ -602,8 -602,7 +602,8 @@@ static int ps_config(oconfig_item_t *ci #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); @@@ -905,9 -904,7 +905,7 @@@ static int ps_read_tasks_status(process } /* while (fgets) */ if (fclose(fh)) { - char errbuf[1024]; - WARNING("processes: fclose: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + WARNING("processes: fclose: %s", STRERRNO); } } closedir(dh); @@@ -963,8 -960,7 +961,7 @@@ static int ps_read_status(long pid, pro } /* 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; @@@ -1024,8 -1020,7 +1021,7 @@@ static int ps_read_io(process_entry_t * } /* 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 (...) */ @@@ -1049,8 -1044,7 +1045,7 @@@ static int ps_count_maps(pid_t pid) } /* 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 (...) */ @@@ -1154,8 -1148,7 +1149,8 @@@ static int ps_read_process(long pid, pr /* 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; } @@@ -1262,12 -1255,10 +1257,10 @@@ static char *ps_get_cmdline(long pid, c 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; } @@@ -1282,13 -1273,12 +1275,12 @@@ 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; } @@@ -1346,9 -1336,7 +1338,7 @@@ static int read_fork_rate(void) 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; } @@@ -1394,7 -1382,7 +1384,7 @@@ static char *ps_get_cmdline(long pid 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; } @@@ -1860,8 -1848,7 +1850,7 @@@ static int ps_read(void) 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; } diff --combined src/rrdcached.c index 0c22d29c,9f76f232..529d29c1 --- a/src/rrdcached.c +++ b/src/rrdcached.c @@@ -88,8 -88,8 +88,8 @@@ static int value_list_to_string(char *b 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); @@@ -424,9 -424,7 +424,7 @@@ static int rc_write(const data_set_t *d 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; } diff --combined src/rrdtool.c index fd6ed93b,1f354218..e3ad07e2 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@@ -186,8 -186,8 +186,8 @@@ static int value_list_to_string_multipl 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); @@@ -226,8 -226,8 +226,8 @@@ static int value_list_to_string(char *b 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, @@@ -520,10 -520,7 +520,7 @@@ static void rrd_cache_flush(cdtime_t ti { 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; @@@ -623,9 -620,8 +620,8 @@@ static int rrd_cache_insert(const char 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); @@@ -652,15 -648,12 +648,12 @@@ 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); @@@ -682,12 -675,9 +675,9 @@@ 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); @@@ -803,7 -793,7 +793,7 @@@ static int rrd_write(const data_set_t * 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; @@@ -816,9 -806,7 +806,7 @@@ 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)) { @@@ -1047,8 -1035,7 +1035,7 @@@ static int rrd_init(void) 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)); diff --combined src/snmp.c index 9847c765,8cb866d3..d0f9e846 --- a/src/snmp.c +++ b/src/snmp.c @@@ -398,7 -398,7 +398,7 @@@ static int csnmp_config_add_data(oconfi } 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); @@@ -1093,8 -1093,7 +1093,8 @@@ static int csnmp_instance_list_add(csnm 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 */ @@@ -1297,9 -1296,8 +1297,9 @@@ static int csnmp_read_table(host_defini } 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; } @@@ -1434,8 -1432,12 +1434,12 @@@ 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) */ @@@ -1472,7 -1474,7 +1476,7 @@@ * 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; @@@ -1484,7 -1486,7 +1488,7 @@@ * 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; @@@ -1576,9 -1578,8 +1580,9 @@@ static int csnmp_read_value(host_defini } 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; } diff --combined src/snmp_agent.c index 5c2350ef,948107b5..b213adb1 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@@ -166,7 -166,7 +166,7 @@@ static void snmp_agent_dump_data(void) 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); @@@ -190,7 -190,7 +190,7 @@@ 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); @@@ -1117,12 -1117,6 +1117,6 @@@ static int snmp_agent_config_table(ocon } } - 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) { @@@ -1137,6 -1131,11 +1131,11 @@@ 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; diff --combined src/table.c index 8506af3f,bc825428..20f02756 --- a/src/table.c +++ b/src/table.c @@@ -78,6 -78,10 +78,10 @@@ static void tbl_result_setup(tbl_result } /* tbl_result_setup */ static void tbl_result_clear(tbl_result_t *res) { + if (res == NULL) { + return; + } + sfree(res->type); sfree(res->instance_prefix); @@@ -103,11 -107,17 +107,17 @@@ static void tbl_setup(tbl_t *tbl, char } /* 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); @@@ -154,8 -164,7 +164,7 @@@ static int tbl_config_append_array_i(ch 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; @@@ -169,26 -178,21 +178,21 @@@ } /* 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(" 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) { @@@ -209,49 -213,43 +213,43 @@@ c->key); } + int status = 0; if (NULL == res->type) { - log_err("No \"Type\" option specified for " - "in table \"%s\".", + log_err("No \"Type\" option specified for in table \"%s\".", tbl->file); status = 1; } if (NULL == res->values) { - log_err("No \"ValuesFrom\" option specified for " - "in table \"%s\".", + log_err("No \"ValuesFrom\" option specified for 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(" 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) { @@@ -271,6 -269,7 +269,7 @@@ c->key, tbl->file); } + int status = 0; if (NULL == tbl->sep) { log_err("Table \"%s\" does not specify any separator.", tbl->file); status = 1; @@@ -284,13 -283,13 +283,13 @@@ } 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; } @@@ -305,6 -304,8 +304,8 @@@ if (res->values[j] > tbl->max_colnum) tbl->max_colnum = res->values[j]; } + + tables_num++; return 0; } /* tbl_config_table */ @@@ -335,8 -336,8 +336,8 @@@ static int tbl_prepare(tbl_t *tbl) } 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; @@@ -429,7 -430,7 +430,7 @@@ static int tbl_parse_line(tbl_t *tbl, c 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; } @@@ -449,9 -450,7 +450,7 @@@ static int tbl_read_table(tbl_t *tbl) 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; } @@@ -469,9 -468,7 +468,7 @@@ } 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; } diff --combined src/utils_cmd_getthreshold.c index 8cc1d21c,63e26e06..c1f3f562 --- a/src/utils_cmd_getthreshold.c +++ b/src/utils_cmd_getthreshold.c @@@ -36,9 -36,8 +36,8 @@@ #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; \ } @@@ -152,7 -151,7 +151,7 @@@ int handle_getthreshold(FILE *fh, char 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); diff --combined src/utils_cmd_getval.c index b0891619,23bafc73..f747d5b8 --- a/src/utils_cmd_getval.c +++ b/src/utils_cmd_getval.c @@@ -78,9 -78,8 +78,8 @@@ cmd_status_t cmd_parse_getval(size_t ar #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); \ @@@ -132,8 -131,8 +131,8 @@@ cmd_status_t cmd_handle_getval(FILE *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); @@@ -141,7 -140,7 +140,7 @@@ 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); diff --combined src/utils_format_json.c index ae8d8b3b,4ecbfbe2..6a0c6642 --- a/src/utils_format_json.c +++ b/src/utils_format_json.c @@@ -130,7 -130,7 +130,7 @@@ static int values_to_json(char *buffer 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) @@@ -500,6 -500,14 +500,14 @@@ static int json_add_string(yajl_gen g, } \ } 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) @@@ -525,7 -533,7 +533,7 @@@ 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); @@@ -544,14 -552,14 +552,14 @@@ static int format_time(yajl_gen g, cdti 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) @@@ -587,27 -595,30 +595,30 @@@ 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 */ @@@ -672,7 -683,11 +683,11 @@@ int format_json_notification(char *buff } /* 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); diff --combined src/utils_ovs.c index 296d6857,b3ce056d..0ee05e00 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@@ -105,6 -105,7 +105,7 @@@ #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 @@@ -263,12 -264,11 +264,11 @@@ static void ovs_db_callback_remove(ovs_ /* 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); } @@@ -560,7 -560,7 +560,7 @@@ static int ovs_db_json_data_process(ovs 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)); @@@ -751,21 -751,18 +751,18 @@@ static void ovs_db_reconnect(ovs_db_t * } /* 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; } } @@@ -796,12 -793,10 +793,10 @@@ static void *ovs_poll_worker(void *arg /* 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"); @@@ -827,8 -822,7 +822,7 @@@ 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; @@@ -869,26 -863,30 +863,30 @@@ static void *ovs_event_worker(void *arg 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"); @@@ -902,7 -900,7 +900,7 @@@ /* 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; @@@ -934,11 -932,12 +932,12 @@@ 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; @@@ -946,16 -945,21 +945,21 @@@ * 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; @@@ -973,10 -977,12 +977,12 @@@ } /* 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; @@@ -985,7 -991,7 +991,7 @@@ 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; } @@@ -1000,9 -1006,10 +1006,10 @@@ ovs_db_t *ovs_db_init(const char *node 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)); @@@ -1044,7 -1051,6 +1051,6 @@@ } /* init polling thread */ - pdb->sock = -1; if (ovs_db_poll_thread_init(pdb) < 0) { ovs_db_destroy(pdb); return NULL; @@@ -1250,23 -1256,28 +1256,28 @@@ int ovs_db_destroy(ovs_db_t *pdb) 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); @@@ -1276,7 -1287,6 +1287,6 @@@ close(pdb->sock); /* release DB handler */ - pthread_mutex_unlock(&pdb->mutex); pthread_mutex_destroy(&pdb->mutex); sfree(pdb); return ovs_db_ret; diff --combined src/virt.c index bf79c70d,174db2fa..06e2408f --- a/src/virt.c +++ b/src/virt.c @@@ -444,12 -444,10 +444,10 @@@ static void init_block_info(struct lv_b #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) { @@@ -699,11 -697,10 +697,11 @@@ static double cpu_ns_to_percent(unsigne (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; } @@@ -1661,7 -1658,7 +1659,7 @@@ static int lv_init_instance(size_t i, p 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); diff --combined src/write_graphite.c index 47d9642b,c301ae65..b39448ff --- a/src/write_graphite.c +++ b/src/write_graphite.c @@@ -156,11 -156,9 +156,9 @@@ static int wg_send_buffer(struct wg_cal 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); @@@ -177,7 -175,7 +175,7 @@@ static int wg_flush_nolock(cdtime_t tim 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 */ @@@ -238,9 -236,7 +236,7 @@@ static int wg_callback_init(struct wg_c 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; } @@@ -248,10 -244,8 +244,8 @@@ 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; @@@ -263,9 -257,6 +257,6 @@@ 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", @@@ -312,6 -303,7 +303,7 @@@ static void wg_callback_free(void *data sfree(cb->prefix); sfree(cb->postfix); + pthread_mutex_unlock(&cb->send_lock); pthread_mutex_destroy(&cb->send_lock); sfree(cb); @@@ -381,8 -373,7 +373,8 @@@ static int wg_send_message(char const * 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)), diff --combined src/write_riemann.c index 16533b76,86f0c1fa..55699d5d --- a/src/write_riemann.c +++ b/src/write_riemann.c @@@ -362,7 -362,7 +362,7 @@@ wrr_value_to_event(struct riemann_host { 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); } @@@ -610,6 -610,7 +610,7 @@@ static void wrr_free(void *p) /* {{{ * wrr_disconnect(host); + pthread_mutex_lock(&host->lock); pthread_mutex_destroy(&host->lock); sfree(host); } /* }}} void wrr_free */ diff --combined src/write_sensu.c index b0c9254c,ddeecf83..71dd5854 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@@ -31,6 -31,7 +31,6 @@@ #include "common.h" #include "plugin.h" #include "utils_cache.h" - #include #include #include @@@ -454,7 -455,7 +454,7 @@@ static char *sensu_value_to_json(struc // 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); @@@ -519,8 -520,7 +519,8 @@@ 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"); @@@ -880,11 -880,9 +880,9 @@@ static int sensu_send_msg(struct sensu_ 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; } @@@ -999,7 -997,10 +997,10 @@@ static void sensu_free(void *p) /* {{{ 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 */ diff --combined src/write_tsdb.c index 777f4ccf,d5d55987..349b0d0c --- a/src/write_tsdb.c +++ b/src/write_tsdb.c @@@ -112,9 -112,8 +112,8 @@@ static int wt_send_buffer(struct wt_cal 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; @@@ -130,7 -129,7 +129,7 @@@ static int wt_flush_nolock(cdtime_t tim 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 */ @@@ -242,10 -241,9 +241,9 @@@ static int wt_callback_init(struct wt_c } 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; } @@@ -279,6 -277,7 +277,7 @@@ static void wt_callback_free(void *data sfree(cb->service); sfree(cb->host_tags); + pthread_mutex_unlock(&cb->send_lock); pthread_mutex_destroy(&cb->send_lock); sfree(cb); @@@ -348,7 -347,7 +347,7 @@@ static int wt_format_values(char *ret, } 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) @@@ -465,7 -464,7 +464,7 @@@ static int wt_send_message(const char * if (message_len >= sizeof(message)) { ERROR("write_tsdb plugin: message buffer too small: " - "Need %zu bytes.", + "Need %" PRIsz " bytes.", message_len + 1); return -1; } @@@ -498,8 -497,8 +497,8 @@@ 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);