Skip to content

Commit

Permalink
Run all changed files 68 8.c/1*.h through clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
zebity committed May 16, 2019
1 parent 43d22c1 commit eada465
Show file tree
Hide file tree
Showing 58 changed files with 612 additions and 470 deletions.
23 changes: 12 additions & 11 deletions src/aggregation.c
Expand Up @@ -198,15 +198,17 @@ static int agg_instance_create_name(agg_instance_t *inst, /* {{{ */
sstrncpy(inst->ident.plugin_instance, AGG_FUNC_PLACEHOLDER,
sizeof(inst->ident.plugin_instance));
else if (strcmp("", tmp_plugin) != 0)
ssnprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
"%s-%s", tmp_plugin, AGG_FUNC_PLACEHOLDER);
ssnprintf(inst->ident.plugin_instance,
sizeof(inst->ident.plugin_instance), "%s-%s", tmp_plugin,
AGG_FUNC_PLACEHOLDER);
else if (strcmp("", tmp_plugin_instance) != 0)
ssnprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
"%s-%s", tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
ssnprintf(inst->ident.plugin_instance,
sizeof(inst->ident.plugin_instance), "%s-%s",
tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
else
ssnprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
"%s-%s-%s", tmp_plugin, tmp_plugin_instance,
AGG_FUNC_PLACEHOLDER);
ssnprintf(inst->ident.plugin_instance,
sizeof(inst->ident.plugin_instance), "%s-%s-%s", tmp_plugin,
tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
}

/* Type */
Expand Down Expand Up @@ -396,10 +398,9 @@ static int agg_instance_read(agg_instance_t *inst, cdtime_t t) /* {{{ */
READ_FUNC(average, (inst->sum / ((gauge_t)inst->num)));
READ_FUNC(min, inst->min);
READ_FUNC(max, inst->max);
READ_FUNC(stddev,
sqrt((((gauge_t)inst->num) * inst->squares_sum) -
(inst->sum * inst->sum)) /
((gauge_t)inst->num));
READ_FUNC(stddev, sqrt((((gauge_t)inst->num) * inst->squares_sum) -
(inst->sum * inst->sum)) /
((gauge_t)inst->num));
}

/* Reset internal state. */
Expand Down
43 changes: 22 additions & 21 deletions src/amqp.c
Expand Up @@ -218,17 +218,17 @@ static char *camqp_strerror(camqp_config_t *conf, /* {{{ */
amqp_connection_close_t *m = r.reply.decoded;
char *tmp = camqp_bytes_cstring(&m->reply_text);
ssnprintf(buffer, buffer_size, "Server connection error %d: %s",
m->reply_code, tmp);
m->reply_code, tmp);
sfree(tmp);
} else if (r.reply.id == AMQP_CHANNEL_CLOSE_METHOD) {
amqp_channel_close_t *m = r.reply.decoded;
char *tmp = camqp_bytes_cstring(&m->reply_text);
ssnprintf(buffer, buffer_size, "Server channel error %d: %s",
m->reply_code, tmp);
m->reply_code, tmp);
sfree(tmp);
} else {
ssnprintf(buffer, buffer_size, "Server error method %#" PRIx32,
r.reply.id);
r.reply.id);
}
break;

Expand Down Expand Up @@ -322,7 +322,8 @@ static int camqp_setup_queue(camqp_config_t *conf) /* {{{ */

qd_ret = amqp_queue_declare(conf->connection,
/* channel = */ CAMQP_CHANNEL,
/* queue = */ (conf->queue != NULL)
/* queue = */
(conf->queue != NULL)
? amqp_cstring_bytes(conf->queue)
: AMQP_EMPTY_BYTES,
/* passive = */ 0,
Expand Down Expand Up @@ -353,15 +354,15 @@ static int camqp_setup_queue(camqp_config_t *conf) /* {{{ */
amqp_queue_bind_ok_t *qb_ret;

assert(conf->queue != NULL);
qb_ret =
amqp_queue_bind(conf->connection,
/* channel = */ CAMQP_CHANNEL,
/* queue = */ amqp_cstring_bytes(conf->queue),
/* exchange = */ amqp_cstring_bytes(conf->exchange),
/* routing_key = */ (conf->routing_key != NULL)
? amqp_cstring_bytes(conf->routing_key)
: AMQP_EMPTY_BYTES,
/* arguments = */ AMQP_EMPTY_TABLE);
qb_ret = amqp_queue_bind(
conf->connection,
/* channel = */ CAMQP_CHANNEL,
/* queue = */ amqp_cstring_bytes(conf->queue),
/* exchange = */ amqp_cstring_bytes(conf->exchange),
/* routing_key = */
(conf->routing_key != NULL) ? amqp_cstring_bytes(conf->routing_key)
: AMQP_EMPTY_BYTES,
/* arguments = */ AMQP_EMPTY_TABLE);
if ((qb_ret == NULL) && camqp_is_error(conf)) {
char errbuf[1024];
ERROR("amqp plugin: amqp_queue_bind failed: %s",
Expand Down Expand Up @@ -428,7 +429,7 @@ static int camqp_connect(camqp_config_t *conf) /* {{{ */

#ifdef HAVE_AMQP_TCP_SOCKET
#define CLOSE_SOCKET() /* amqp_destroy_connection() closes the socket for us \
*/
*/
/* TODO: add support for SSL using amqp_ssl_socket_new
* and related functions */
socket = amqp_tcp_socket_new(conf->connection);
Expand Down Expand Up @@ -749,8 +750,8 @@ static int camqp_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
sstrncpy(routing_key, conf->routing_key, sizeof(routing_key));
} else {
ssnprintf(routing_key, sizeof(routing_key), "collectd/%s/%s/%s/%s/%s",
vl->host, vl->plugin, vl->plugin_instance, vl->type,
vl->type_instance);
vl->host, vl->plugin, vl->plugin_instance, vl->type,
vl->type_instance);

/* Switch slashes (the only character forbidden by collectd) and dots
* (the separation character used by AMQP). */
Expand Down Expand Up @@ -972,11 +973,11 @@ static int camqp_config_connection(oconfig_item_t *ci, /* {{{ */
char cbname[128];
ssnprintf(cbname, sizeof(cbname), "amqp/%s", conf->name);

status =
plugin_register_write(cbname, camqp_write,
&(user_data_t){
.data = conf, .free_func = camqp_config_free,
});
status = plugin_register_write(cbname, camqp_write,
&(user_data_t){
.data = conf,
.free_func = camqp_config_free,
});
if (status != 0) {
camqp_config_free(conf);
return status;
Expand Down
16 changes: 9 additions & 7 deletions src/amqp1.c
Expand Up @@ -630,7 +630,7 @@ static int amqp1_config_instance(oconfig_item_t *ci) /* {{{ */
return -1;
}
status = ssnprintf(instance->send_to, sizeof(instance->send_to), "/%s/%s",
transport->address, instance->name);
transport->address, instance->name);
if ((status < 0) || (size_t)status >= sizeof(instance->send_to)) {
ERROR("amqp1 plugin: send_to address would have been truncated.");
return -1;
Expand All @@ -639,14 +639,16 @@ static int amqp1_config_instance(oconfig_item_t *ci) /* {{{ */
status = plugin_register_notification(
tpname, amqp1_notify,
&(user_data_t){
.data = instance, .free_func = amqp1_config_instance_free,
.data = instance,
.free_func = amqp1_config_instance_free,
});
} else {
status = plugin_register_write(
tpname, amqp1_write,
&(user_data_t){
.data = instance, .free_func = amqp1_config_instance_free,
});
status =
plugin_register_write(tpname, amqp1_write,
&(user_data_t){
.data = instance,
.free_func = amqp1_config_instance_free,
});
}

if (status != 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/aquaero.c
Expand Up @@ -81,8 +81,8 @@ static void aquaero_submit_array(const char *type,
if (value_array[i] == AQ5_FLOAT_UNDEF)
continue;

ssnprintf(type_instance, sizeof(type_instance), "%s%d", type_instance_prefix,
i + 1);
ssnprintf(type_instance, sizeof(type_instance), "%s%d",
type_instance_prefix, i + 1);
aquaero_submit(type, type_instance, value_array[i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ascent.c
Expand Up @@ -500,7 +500,7 @@ static int ascent_init(void) /* {{{ */
int status;

status = ssnprintf(credentials, sizeof(credentials), "%s:%s", user,
(pass == NULL) ? "" : pass);
(pass == NULL) ? "" : pass);
if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
ERROR("ascent plugin: ascent_init: Returning an error because the "
"credentials have been truncated.");
Expand Down
2 changes: 1 addition & 1 deletion src/ceph.c
Expand Up @@ -1154,7 +1154,7 @@ static ssize_t cconn_handle_event(struct cconn *io) {
case CSTATE_WRITE_REQUEST: {
char cmd[32];
ssnprintf(cmd, sizeof(cmd), "%s%d%s", "{ \"prefix\": \"", io->request_type,
"\" }\n");
"\" }\n");
size_t cmd_len = strlen(cmd);
RETRY_ON_EINTR(
ret, write(io->asok, ((char *)&cmd) + io->amt, cmd_len - io->amt));
Expand Down
22 changes: 13 additions & 9 deletions src/collectdctl.c
Expand Up @@ -25,9 +25,9 @@
#include "config.h"
#endif

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
Expand Down Expand Up @@ -293,8 +293,9 @@ static int flush(lcc_connection_t *c, int argc, char **argv) {
value);
BAIL_OUT(-1);
} else if ((endptr != NULL) && (*endptr != '\0')) {
fprintf(stderr, "WARNING: Ignoring trailing garbage after timeout: "
"%s.\n",
fprintf(stderr,
"WARNING: Ignoring trailing garbage after timeout: "
"%s.\n",
endptr);
}
} else if (strcasecmp(key, "plugin") == 0) {
Expand Down Expand Up @@ -341,8 +342,9 @@ static int flush(lcc_connection_t *c, int argc, char **argv) {
char id[1024];

lcc_identifier_to_string(c, id, sizeof(id), identifiers + j);
fprintf(stderr, "ERROR: Failed to flush plugin `%s', "
"identifier `%s': %s.\n",
fprintf(stderr,
"ERROR: Failed to flush plugin `%s', "
"identifier `%s': %s.\n",
(plugins[i] == NULL) ? "(all)" : plugins[i], id,
lcc_strerror(c));
}
Expand Down Expand Up @@ -386,8 +388,9 @@ static int listval(lcc_connection_t *c, int argc, char **argv) {

status = lcc_identifier_to_string(c, id, sizeof(id), ret_ident + i);
if (status != 0) {
fprintf(stderr, "ERROR: listval: Failed to convert returned "
"identifier to a string: %s\n",
fprintf(stderr,
"ERROR: listval: Failed to convert returned "
"identifier to a string: %s\n",
lcc_strerror(c));
continue;
}
Expand Down Expand Up @@ -445,8 +448,9 @@ static int putval(lcc_connection_t *c, int argc, char **argv) {
value);
return -1;
} else if ((endptr != NULL) && (*endptr != '\0')) {
fprintf(stderr, "WARNING: Ignoring trailing garbage after "
"interval: %s.\n",
fprintf(stderr,
"WARNING: Ignoring trailing garbage after "
"interval: %s.\n",
endptr);
}
} else {
Expand Down
20 changes: 10 additions & 10 deletions src/daemon/configfile.c
Expand Up @@ -267,7 +267,8 @@ static int dispatch_loadplugin(oconfig_item_t *ci) {

/* default to the global interval set before loading this plugin */
plugin_ctx_t ctx = {
.interval = cf_get_default_interval(), .name = strdup(name),
.interval = cf_get_default_interval(),
.name = strdup(name),
};
if (ctx.name == NULL)
return ENOMEM;
Expand Down Expand Up @@ -313,11 +314,11 @@ static int dispatch_value_plugin(const char *plugin, oconfig_item_t *ci) {
status =
ssnprintf(buffer_ptr, buffer_free, " %s", ci->values[i].value.string);
else if (ci->values[i].type == OCONFIG_TYPE_NUMBER)
status =
ssnprintf(buffer_ptr, buffer_free, " %lf", ci->values[i].value.number);
status = ssnprintf(buffer_ptr, buffer_free, " %lf",
ci->values[i].value.number);
else if (ci->values[i].type == OCONFIG_TYPE_BOOLEAN)
status = ssnprintf(buffer_ptr, buffer_free, " %s",
ci->values[i].value.boolean ? "true" : "false");
ci->values[i].value.boolean ? "true" : "false");

if ((status < 0) || (status >= buffer_free))
return -1;
Expand Down Expand Up @@ -475,9 +476,9 @@ static int cf_ci_replace_child(oconfig_item_t *dst, oconfig_item_t *src,
return 0;
}

temp = realloc(dst->children,
sizeof(oconfig_item_t) *
(dst->children_num + src->children_num - 1));
temp =
realloc(dst->children, sizeof(oconfig_item_t) *
(dst->children_num + src->children_num - 1));
if (temp == NULL) {
ERROR("configfile: realloc failed.");
return -1;
Expand Down Expand Up @@ -516,9 +517,8 @@ static int cf_ci_append_children(oconfig_item_t *dst, oconfig_item_t *src) {
if ((src == NULL) || (src->children_num == 0))
return 0;

temp =
realloc(dst->children,
sizeof(oconfig_item_t) * (dst->children_num + src->children_num));
temp = realloc(dst->children, sizeof(oconfig_item_t) *
(dst->children_num + src->children_num));
if (temp == NULL) {
ERROR("configfile: realloc failed.");
return -1;
Expand Down
23 changes: 13 additions & 10 deletions src/disk.c
Expand Up @@ -209,7 +209,7 @@ static int disk_init(void) {
io_master_port = MACH_PORT_NULL;
return -1;
}
/* #endif HAVE_IOKIT_IOKITLIB_H */
/* #endif HAVE_IOKIT_IOKITLIB_H */

#elif KERNEL_LINUX
#if HAVE_LIBUDEV_H
Expand All @@ -221,7 +221,7 @@ static int disk_init(void) {
}
}
#endif /* HAVE_LIBUDEV_H */
/* #endif KERNEL_LINUX */
/* #endif KERNEL_LINUX */

#elif KERNEL_FREEBSD
int rv;
Expand All @@ -236,7 +236,7 @@ static int disk_init(void) {
ERROR("geom_stats_open() failed, returned %d", rv);
return -1;
}
/* #endif KERNEL_FREEBSD */
/* #endif KERNEL_FREEBSD */

#elif HAVE_LIBKSTAT
kstat_t *ksp_chain;
Expand Down Expand Up @@ -275,7 +275,8 @@ static void disk_submit(const char *plugin_instance, const char *type,
derive_t read, derive_t write) {
value_list_t vl = VALUE_LIST_INIT;
value_t values[] = {
{.derive = read}, {.derive = write},
{.derive = read},
{.derive = write},
};

vl.values = values;
Expand All @@ -292,7 +293,8 @@ static void submit_io_time(char const *plugin_instance, derive_t io_time,
derive_t weighted_time) {
value_list_t vl = VALUE_LIST_INIT;
value_t values[] = {
{.derive = io_time}, {.derive = weighted_time},
{.derive = io_time},
{.derive = weighted_time},
};

vl.values = values;
Expand Down Expand Up @@ -493,7 +495,8 @@ static int disk_read(void) {
sstrncpy(disk_name, props_disk_name_bsd, sizeof(disk_name));
else {
ERROR("disk plugin: can't find bsd disk name.");
ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor);
ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major,
disk_minor);
}
} else
ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor);
Expand Down Expand Up @@ -532,7 +535,7 @@ static int disk_read(void) {
disk_submit(disk_name, "disk_time", read_tme / 1000, write_tme / 1000);
}
IOObjectRelease(disk_list);
/* #endif HAVE_IOKIT_IOKITLIB_H */
/* #endif HAVE_IOKIT_IOKITLIB_H */

#elif KERNEL_FREEBSD
int retry, dirty;
Expand Down Expand Up @@ -896,7 +899,7 @@ static int disk_read(void) {
free(missing_ds);
}
fclose(fh);
/* #endif defined(KERNEL_LINUX) */
/* #endif defined(KERNEL_LINUX) */

#elif HAVE_LIBKSTAT
#if HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_NWRITES && HAVE_KSTAT_IO_T_WTIME
Expand Down Expand Up @@ -944,7 +947,7 @@ static int disk_read(void) {
disk_submit(ksp[i]->ks_name, "disk_ops", kio.KIO_ROPS, kio.KIO_WOPS);
}
}
/* #endif defined(HAVE_LIBKSTAT) */
/* #endif defined(HAVE_LIBKSTAT) */

#elif defined(HAVE_LIBSTATGRAB)
sg_disk_io_stats *ds;
Expand All @@ -971,7 +974,7 @@ static int disk_read(void) {
disk_submit(name, "disk_octets", ds->read_bytes, ds->write_bytes);
ds++;
}
/* #endif defined(HAVE_LIBSTATGRAB) */
/* #endif defined(HAVE_LIBSTATGRAB) */

#elif defined(HAVE_PERFSTAT)
derive_t read_sectors;
Expand Down

0 comments on commit eada465

Please sign in to comment.