projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
treewide: declare loop variable in loop expression
[collectd.git]
/
src
/
daemon
/
collectd.c
diff --git
a/src/daemon/collectd.c
b/src/daemon/collectd.c
index
7b324e1
..
8573579
100644
(file)
--- a/
src/daemon/collectd.c
+++ b/
src/daemon/collectd.c
@@
-26,8
+26,8
@@
**/
#include "collectd.h"
**/
#include "collectd.h"
-#include "common.h"
+#include "common.h"
#include "plugin.h"
#include "configfile.h"
#include "plugin.h"
#include "configfile.h"
@@
-35,8
+35,6
@@
#include <sys/un.h>
#include <netdb.h>
#include <sys/un.h>
#include <netdb.h>
-#include <pthread.h>
-
#if HAVE_LOCALE_H
# include <locale.h>
#endif
#if HAVE_LOCALE_H
# include <locale.h>
#endif
@@
-54,7
+52,6
@@
*/
char hostname_g[DATA_MAX_NAME_LEN];
cdtime_t interval_g;
*/
char hostname_g[DATA_MAX_NAME_LEN];
cdtime_t interval_g;
-int pidfile_from_cli = 0;
int timeout_g;
#if HAVE_LIBKSTAT
kstat_ctl_t *kc;
int timeout_g;
#if HAVE_LIBKSTAT
kstat_ctl_t *kc;
@@
-100,9
+97,7
@@
static int init_hostname (void)
{
const char *str;
{
const char *str;
- struct addrinfo ai_hints;
struct addrinfo *ai_list;
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
int status;
str = global_option_get ("Hostname");
int status;
str = global_option_get ("Hostname");
@@
-123,8
+118,9
@@
static int init_hostname (void)
if (IS_FALSE (str))
return (0);
if (IS_FALSE (str))
return (0);
- memset (&ai_hints, '\0', sizeof (ai_hints));
- ai_hints.ai_flags = AI_CANONNAME;
+ struct addrinfo ai_hints = {
+ .ai_flags = AI_CANONNAME
+ };
status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list);
if (status != 0)
status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list);
if (status != 0)
@@
-137,7
+133,7
@@
static int init_hostname (void)
return (-1);
}
return (-1);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (
struct addrinfo *
ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
if (ai_ptr->ai_canonname == NULL)
continue;
{
if (ai_ptr->ai_canonname == NULL)
continue;
@@
-196,7
+192,7
@@
static int change_basedir (const char *orig_dir)
while ((dirlen > 0) && (dir[dirlen - 1] == '/'))
dir[--dirlen] = '\0';
while ((dirlen > 0) && (dir[dirlen - 1] == '/'))
dir[--dirlen] = '\0';
- if (dirlen
<
= 0) {
+ if (dirlen
=
= 0) {
free (dir);
return (-1);
}
free (dir);
return (-1);
}
@@
-269,6
+265,7
@@
static void update_kstat (void)
/* TODO
* Remove all settings but `-f' and `-C'
*/
/* TODO
* Remove all settings but `-f' and `-C'
*/
+__attribute__((noreturn))
static void exit_usage (int status)
{
printf ("Usage: "PACKAGE_NAME" [OPTIONS]\n\n"
static void exit_usage (int status)
{
printf ("Usage: "PACKAGE_NAME" [OPTIONS]\n\n"
@@
-331,9
+328,7
@@
static int do_init (void)
}
#endif
}
#endif
- plugin_init_all ();
-
- return (0);
+ return plugin_init_all ();
} /* int do_init () */
} /* int do_init () */
@@
-387,8
+382,7
@@
static int do_loop (void)
static int do_shutdown (void)
{
static int do_shutdown (void)
{
- plugin_shutdown_all ();
- return (0);
+ return plugin_shutdown_all ();
} /* int do_shutdown */
#if COLLECT_DAEMON
} /* int do_shutdown */
#if COLLECT_DAEMON
@@
-422,7
+416,7
@@
static int pidfile_remove (void)
#endif /* COLLECT_DAEMON */
#ifdef KERNEL_LINUX
#endif /* COLLECT_DAEMON */
#ifdef KERNEL_LINUX
-int notify_upstart (void)
+
static
int notify_upstart (void)
{
char const *upstart_job = getenv("UPSTART_JOB");
{
char const *upstart_job = getenv("UPSTART_JOB");
@@
-442,11
+436,11
@@
int notify_upstart (void)
return 1;
}
return 1;
}
-int notify_systemd (void)
+
static
int notify_systemd (void)
{
int fd;
const char *notifysocket;
{
int fd;
const char *notifysocket;
- struct sockaddr_un su;
+ struct sockaddr_un su
= { 0 }
;
size_t su_size;
char buffer[] = "READY=1\n";
size_t su_size;
char buffer[] = "READY=1\n";
@@
-476,7
+470,6
@@
int notify_systemd (void)
return 0;
}
return 0;
}
- memset (&su, 0, sizeof (su));
su.sun_family = AF_UNIX;
if (notifysocket[0] != '@')
{
su.sun_family = AF_UNIX;
if (notifysocket[0] != '@')
{
@@
-514,16
+507,11
@@
int notify_systemd (void)
int main (int argc, char **argv)
{
int main (int argc, char **argv)
{
- struct sigaction sig_int_action;
- struct sigaction sig_term_action;
- struct sigaction sig_usr1_action;
- struct sigaction sig_pipe_action;
- char *configfile = CONFIGFILE;
+ const char *configfile = CONFIGFILE;
int test_config = 0;
int test_readall = 0;
const char *basedir;
#if COLLECT_DAEMON
int test_config = 0;
int test_readall = 0;
const char *basedir;
#if COLLECT_DAEMON
- struct sigaction sig_chld_action;
pid_t pid;
int daemonize = 1;
#endif
pid_t pid;
int daemonize = 1;
#endif
@@
-553,15
+541,14
@@
int main (int argc, char **argv)
break;
case 'T':
test_readall = 1;
break;
case 'T':
test_readall = 1;
- global_option_set ("ReadThreads", "-1");
+ global_option_set ("ReadThreads", "-1"
, 1
);
#if COLLECT_DAEMON
daemonize = 0;
#endif /* COLLECT_DAEMON */
break;
#if COLLECT_DAEMON
case 'P':
#if COLLECT_DAEMON
daemonize = 0;
#endif /* COLLECT_DAEMON */
break;
#if COLLECT_DAEMON
case 'P':
- global_option_set ("PIDFile", optarg);
- pidfile_from_cli = 1;
+ global_option_set ("PIDFile", optarg, 1);
break;
case 'f':
daemonize = 0;
break;
case 'f':
daemonize = 0;
@@
-624,8
+611,10
@@
int main (int argc, char **argv)
/*
* fork off child
*/
/*
* fork off child
*/
- memset (&sig_chld_action, '\0', sizeof (sig_chld_action));
- sig_chld_action.sa_handler = SIG_IGN;
+ struct sigaction sig_chld_action = {
+ .sa_handler = SIG_IGN
+ };
+
sigaction (SIGCHLD, &sig_chld_action, NULL);
/*
sigaction (SIGCHLD, &sig_chld_action, NULL);
/*
@@
-691,15
+680,19
@@
int main (int argc, char **argv)
} /* if (daemonize) */
#endif /* COLLECT_DAEMON */
} /* if (daemonize) */
#endif /* COLLECT_DAEMON */
- memset (&sig_pipe_action, '\0', sizeof (sig_pipe_action));
- sig_pipe_action.sa_handler = SIG_IGN;
+ struct sigaction sig_pipe_action = {
+ .sa_handler = SIG_IGN
+ };
+
sigaction (SIGPIPE, &sig_pipe_action, NULL);
/*
* install signal handlers
*/
sigaction (SIGPIPE, &sig_pipe_action, NULL);
/*
* install signal handlers
*/
- memset (&sig_int_action, '\0', sizeof (sig_int_action));
- sig_int_action.sa_handler = sig_int_handler;
+ struct sigaction sig_int_action = {
+ .sa_handler = sig_int_handler
+ };
+
if (0 != sigaction (SIGINT, &sig_int_action, NULL)) {
char errbuf[1024];
ERROR ("Error: Failed to install a signal handler for signal INT: %s",
if (0 != sigaction (SIGINT, &sig_int_action, NULL)) {
char errbuf[1024];
ERROR ("Error: Failed to install a signal handler for signal INT: %s",
@@
-707,8
+700,10
@@
int main (int argc, char **argv)
return (1);
}
return (1);
}
- memset (&sig_term_action, '\0', sizeof (sig_term_action));
- sig_term_action.sa_handler = sig_term_handler;
+ struct sigaction sig_term_action = {
+ .sa_handler = sig_term_handler
+ };
+
if (0 != sigaction (SIGTERM, &sig_term_action, NULL)) {
char errbuf[1024];
ERROR ("Error: Failed to install a signal handler for signal TERM: %s",
if (0 != sigaction (SIGTERM, &sig_term_action, NULL)) {
char errbuf[1024];
ERROR ("Error: Failed to install a signal handler for signal TERM: %s",
@@
-716,8
+711,10
@@
int main (int argc, char **argv)
return (1);
}
return (1);
}
- memset (&sig_usr1_action, '\0', sizeof (sig_usr1_action));
- sig_usr1_action.sa_handler = sig_usr1_handler;
+ struct sigaction sig_usr1_action = {
+ .sa_handler = sig_usr1_handler
+ };
+
if (0 != sigaction (SIGUSR1, &sig_usr1_action, NULL)) {
char errbuf[1024];
ERROR ("Error: Failed to install a signal handler for signal USR1: %s",
if (0 != sigaction (SIGUSR1, &sig_usr1_action, NULL)) {
char errbuf[1024];
ERROR ("Error: Failed to install a signal handler for signal USR1: %s",
@@
-728,12
+725,19
@@
int main (int argc, char **argv)
/*
* run the actual loops
*/
/*
* run the actual loops
*/
- do_init ();
+ if (do_init () != 0)
+ {
+ ERROR ("Error: one or more plugin init callbacks failed.");
+ exit_status = 1;
+ }
if (test_readall)
{
if (plugin_read_all_once () != 0)
if (test_readall)
{
if (plugin_read_all_once () != 0)
+ {
+ ERROR ("Error: one or more plugin read callbacks failed.");
exit_status = 1;
exit_status = 1;
+ }
}
else
{
}
else
{
@@
-744,7
+748,11
@@
int main (int argc, char **argv)
/* close syslog */
INFO ("Exiting normally.");
/* close syslog */
INFO ("Exiting normally.");
- do_shutdown ();
+ if (do_shutdown () != 0)
+ {
+ ERROR ("Error: one or more plugin shutdown callbacks failed.");
+ exit_status = 1;
+ }
#if COLLECT_DAEMON
if (daemonize)
#if COLLECT_DAEMON
if (daemonize)