Skip to content

Commit

Permalink
format strings: apply gcc format string attributes and fix the issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
saaros committed Oct 15, 2012
1 parent 0b10af9 commit 3c23b23
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 35 deletions.
18 changes: 9 additions & 9 deletions gmetad/conf.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -162,46 +162,46 @@ static DOTCONF_CB(cb_data_source)
if(!find)
err_quit("Unable to insert list pointer into source hash\n");

debug_msg("Data inserted for [%s] into sources hash", key.data);
debug_msg("Data inserted for [%s] into sources hash", (const char *) key.data);
return NULL;
}

static DOTCONF_CB(cb_debug_level)
{
gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
c->debug_level = cmd->data.value;
debug_msg("Setting the debug level to %d", cmd->data.value);
debug_msg("Setting the debug level to %ld", cmd->data.value);
return NULL;
}

static DOTCONF_CB(cb_xml_port)
{
gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
debug_msg("Setting xml port to %d", cmd->data.value);
debug_msg("Setting xml port to %ld", cmd->data.value);
c->xml_port = cmd->data.value;
return NULL;
}

static DOTCONF_CB(cb_interactive_port)
{
gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
debug_msg("Setting interactive port to %d", cmd->data.value);
debug_msg("Setting interactive port to %ld", cmd->data.value);
c->interactive_port = cmd->data.value;
return NULL;
}

static DOTCONF_CB(cb_server_threads)
{
gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
debug_msg("Setting number of xml server threads to %d", cmd->data.value);
debug_msg("Setting number of xml server threads to %ld", cmd->data.value);
c->server_threads = cmd->data.value;
return NULL;
}

static DOTCONF_CB(cb_umask)
{
gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
debug_msg("Setting umask to %.5o & 07077", cmd->data.value);
debug_msg("Setting umask to %.5lo & 07077", cmd->data.value);
c->umask = cmd->data.value & 07077; /* protect owner permissions */
return NULL;
}
Expand Down Expand Up @@ -265,15 +265,15 @@ static DOTCONF_CB(cb_carbon_server)
static DOTCONF_CB(cb_carbon_port)
{
gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
debug_msg("Setting carbon port to %d", cmd->data.value);
debug_msg("Setting carbon port to %ld", cmd->data.value);
c->carbon_port = cmd->data.value;
return NULL;
}

static DOTCONF_CB(cb_carbon_timeout)
{
gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
debug_msg("Setting carbon timeout to %d", cmd->data.value);
debug_msg("Setting carbon timeout to %ld", cmd->data.value);
c->carbon_timeout = cmd->data.value;
return NULL;
}
Expand All @@ -297,7 +297,7 @@ static DOTCONF_CB(cb_unsummarized_metrics)
le = (llist_entry *)malloc(sizeof(llist_entry));
le->val = strdup(cmd->data.list[i]);
llist_add(&(c->unsummarized_metrics), le);
debug_msg("Adding %s to unsummarized_metrics", le->val);
debug_msg("Adding %s to unsummarized_metrics", (const char *) le->val);
}
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions gmetad/process_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ startElement_EXTRA_ELEMENT (void *data, const char *el, const char **attr)
*/
if (metric.ednameslen >= MAX_EXTRA_ELEMENTS)
{
debug_msg("Can not add more extra elements for [%s]. Capacity of %d reached[%s].",
debug_msg("Can not add more extra elements for [%s]. Capacity of %d reached.",
name, MAX_EXTRA_ELEMENTS);
return 0;
}
Expand Down Expand Up @@ -1225,7 +1225,7 @@ process_xml(data_source_list_t *d, char *buf)
{
err_msg ("Process XML (%s): XML_ParseBuffer() error at line %d:\n%s\n",
d->name,
XML_GetCurrentLineNumber (xml_parser),
(int) XML_GetCurrentLineNumber (xml_parser),
XML_ErrorString (XML_GetErrorCode (xml_parser)));
xmldata.rval = 1;
}
Expand Down
27 changes: 16 additions & 11 deletions gmetad/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern char* getfield(char *buf, short int index);
extern struct type_tag* in_type_list (char *, unsigned int);


static inline int
static inline int CHECK_FMT(2, 3)
xml_print( client_t *client, const char *fmt, ... )
{
int rval, len;
Expand Down Expand Up @@ -150,7 +150,8 @@ metric_report_start(Generic_t *self, datum_t *key, client_t *client, void *arg)
"SOURCE=\"%s\">\n",
name, getfield(metric->strings, metric->valstr),
getfield(metric->strings, metric->type),
getfield(metric->strings, metric->units), tn,
getfield(metric->strings, metric->units),
(unsigned int) tn,
metric->tmax, metric->dmax, getfield(metric->strings, metric->slope),
getfield(metric->strings, metric->source));

Expand Down Expand Up @@ -191,9 +192,10 @@ host_report_start(Generic_t *self, datum_t *key, client_t *client, void *arg)
/* Note the hash key is the host's IP address. */
rc = xml_print(client, "<HOST NAME=\"%s\" IP=\"%s\" REPORTED=\"%u\" "
"TN=\"%u\" TMAX=\"%u\" DMAX=\"%u\" LOCATION=\"%s\" GMOND_STARTED=\"%u\" TAGS=\"%s\">\n",
name, getfield(host->strings, host->ip), host->reported, tn,
name, getfield(host->strings, host->ip), host->reported,
(unsigned int) tn,
host->tmax, host->dmax, getfield(host->strings, host->location),
host->started, getfield(host->strings, host->tags));
host->started, getfield(host->strings, host->tags));

return rc;
}
Expand Down Expand Up @@ -256,7 +258,8 @@ root_report_start(client_t *client)
VERSION);

rc = xml_print(client, "<GRID NAME=\"%s\" AUTHORITY=\"%s\" LOCALTIME=\"%u\">\n",
gmetad_config.gridname, getfield(root.strings, root.authority_ptr), time(0));
gmetad_config.gridname, getfield(root.strings, root.authority_ptr),
(unsigned int) time(0));

return rc;
}
Expand Down Expand Up @@ -576,8 +579,8 @@ server_thread (void *arg)
if ( client.fd < 0 )
{
err_ret("server_thread() error");
debug_msg("server_thread() %d clientfd = %d errno=%d\n",
pthread_self(), client.fd, errno);
debug_msg("server_thread() %lx clientfd = %d errno=%d\n",
(unsigned long) pthread_self(), client.fd, errno);
continue;
}

Expand Down Expand Up @@ -624,8 +627,8 @@ server_thread (void *arg)

if(root_report_start(&client))
{
err_msg("server_thread() %d unable to write root preamble (DTD, etc)",
pthread_self() );
err_msg("server_thread() %lx unable to write root preamble (DTD, etc)",
(unsigned long) pthread_self() );
close(client.fd);
continue;
}
Expand All @@ -636,14 +639,16 @@ server_thread (void *arg)

if (process_path(&client, request, &rootdatum, NULL))
{
err_msg("server_thread() %d unable to write XML tree info", pthread_self() );
err_msg("server_thread() %lx unable to write XML tree info",
(unsigned long) pthread_self() );
close(client.fd);
continue;
}

if(root_report_end(&client))
{
err_msg("server_thread() %d unable to write root epilog", pthread_self() );
err_msg("server_thread() %lx unable to write root epilog",
(unsigned long) pthread_self() );
}

close(client.fd);
Expand Down
3 changes: 2 additions & 1 deletion gmond/gmond.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,8 @@ setup_listen_channels_pollset( void )
{
err_msg("Error setting UDP receive buffer for port %d bind=%s to size: %d.\n",
port, bindaddr? bindaddr: "unspecified", (apr_int32_t) buffer);
err_msg("Reported buffer size by OS: %d : does not match config setting.\n");
err_msg("Reported buffer size by OS: %d : does not match config setting %d.\n",
(int) (rx_buf_sz/2), (int) buffer);
err_msg("NOTE: only supported on systems that have Apache Portable Runtime library version 0.9.4 or higher.\n");
err_msg("Check Operating System (kernel) limits, change or disable buffer size. Exiting.\n");
exit(1);
Expand Down
18 changes: 12 additions & 6 deletions include/gm_msg.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#ifndef GM_MSG_H
#define GM_MSG_H 1

#ifdef __GNUC__
# define CHECK_FMT(posf,posv) __attribute__((format(printf, posf, posv)))
#else
# define CHECK_FMT(posf,posv)
#endif // __GNUC__

#ifdef __cplusplus
extern "C" {
#endif

extern int ganglia_quiet_errors;

void debug_msg(const char *format, ...);
void debug_msg(const char *format, ...) CHECK_FMT(1,2);
void set_debug_msg_level(int level);
int get_debug_msg_level();

void err_quiet( void );
void err_ret (const char *fmt, ...);
void err_sys (const char *fmt, ...);
void err_dump (const char *fmt, ...);
void err_msg (const char *fmt, ...);
void err_quit (const char *fmt, ...);
void err_ret (const char *fmt, ...) CHECK_FMT(1,2);
void err_sys (const char *fmt, ...) CHECK_FMT(1,2);
void err_dump (const char *fmt, ...) CHECK_FMT(1,2);
void err_msg (const char *fmt, ...) CHECK_FMT(1,2);
void err_quit (const char *fmt, ...) CHECK_FMT(1,2);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ganglia.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ gexec_cluster (gexec_cluster_t *cluster, char *ip, unsigned short port)
{
gexec_errno = 7;
err_msg ("gexec_cluster() XML_ParseBuffer() error at line %d:\n%s\n",
XML_GetCurrentLineNumber (xml_parser),
XML_ErrorString (XML_GetErrorCode (xml_parser)));
(int) XML_GetCurrentLineNumber (xml_parser),
XML_ErrorString (XML_GetErrorCode (xml_parser)));
goto error;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ hash_create (size_t size)
size_t i;
hash_t *hash;

debug_msg("hash_create size = %d", size);
debug_msg("hash_create size = %zd", size);

hash = (hash_t *) malloc ( sizeof(hash_t) );
if( hash == NULL )
Expand All @@ -114,7 +114,7 @@ hash_create (size_t size)

hash->size = hash_prime(size);

debug_msg("hash->size is %d", hash->size);
debug_msg("hash->size is %zd", hash->size);

hash->node = (node_t * *) malloc (sizeof (node_t *) * hash->size);
if (hash->node == NULL)
Expand Down
3 changes: 1 addition & 2 deletions libmetrics/linux/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static net_dev_stats *hash_lookup(char *devname, size_t nlen)
stats = (net_dev_stats *)malloc(sizeof(net_dev_stats));
if ( stats == NULL )
{
err_msg("unable to allocate memory for /proc/net/dev/stats in hash_lookup(%s,%d)", name, nlen);
err_msg("unable to allocate memory for /proc/net/dev/stats in hash_lookup(%s,%zd)", name, nlen);
free(name);
return NULL;
}
Expand Down Expand Up @@ -1257,7 +1257,6 @@ float find_disk_space(double *total_size, double *total_free)
double reported_units = 1e9;
/* Track the most full disk partition, report with a percentage. */
float thispct, max=0.0;
int rc;

/* Read all currently mounted filesystems. */
mounts=fopen(MOUNTS,"r");
Expand Down

0 comments on commit 3c23b23

Please sign in to comment.