- indentation
This commit is contained in:
parent
8ef5f2e9d2
commit
d94abab5ed
57
ifstatd.c
57
ifstatd.c
@ -73,7 +73,8 @@ struct pidfh *pfh;
|
||||
/*
|
||||
* Prepare for a clean shutdown
|
||||
*/
|
||||
void daemon_shutdown()
|
||||
void
|
||||
daemon_shutdown()
|
||||
{
|
||||
pidfile_remove(pfh);
|
||||
}
|
||||
@ -81,7 +82,8 @@ void daemon_shutdown()
|
||||
/*
|
||||
* Act upon receiving signals
|
||||
*/
|
||||
void signal_handler(int sig)
|
||||
void
|
||||
signal_handler(int sig)
|
||||
{
|
||||
switch (sig) {
|
||||
|
||||
@ -99,7 +101,8 @@ void signal_handler(int sig)
|
||||
/*
|
||||
* Obtain stats for interface(s).
|
||||
*/
|
||||
static void fill_iftot(struct iftot *st)
|
||||
static void
|
||||
fill_iftot(struct iftot *st)
|
||||
{
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
bool found = false;
|
||||
@ -134,10 +137,10 @@ static void fill_iftot(struct iftot *st)
|
||||
/*
|
||||
* Print out munin plugin configuration
|
||||
*/
|
||||
int config(char *iface)
|
||||
int
|
||||
config(char *iface)
|
||||
{
|
||||
printf(
|
||||
"graph_order rbytes obytes\n"
|
||||
printf("graph_order rbytes obytes\n"
|
||||
"graph_title %s Interface (%d seconds sampling)\n"
|
||||
"graph_category network\n"
|
||||
"graph_vlabel bits per second\n"
|
||||
@ -153,9 +156,7 @@ int config(char *iface)
|
||||
"obytes.negative rbytes\n"
|
||||
"obytes.cdef obytes,8,*\n"
|
||||
"obytes.min 0\n"
|
||||
"obytes.draw AREA\n"
|
||||
,iface,RESOLUTION,RESOLUTION,RESOLUTION
|
||||
);
|
||||
"obytes.draw AREA\n", iface, RESOLUTION, RESOLUTION, RESOLUTION);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -163,7 +164,9 @@ int config(char *iface)
|
||||
/*
|
||||
* Wait for a certain amount of time
|
||||
*/
|
||||
time_t wait_for(int seconds) {
|
||||
time_t
|
||||
wait_for(int seconds)
|
||||
{
|
||||
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_REALTIME, &tp);
|
||||
@ -184,7 +187,8 @@ time_t wait_for(int seconds) {
|
||||
/*
|
||||
* Daemonize and persist pid
|
||||
*/
|
||||
int daemon_start()
|
||||
int
|
||||
daemon_start()
|
||||
{
|
||||
struct iftot ift, *tot;
|
||||
time_t epoch;
|
||||
@ -198,8 +202,7 @@ int daemon_start()
|
||||
if (!no_fork || strcmp("1", no_fork)) {
|
||||
|
||||
/* Check if parent process id is set */
|
||||
if (getppid() == 1)
|
||||
{
|
||||
if (getppid() == 1) {
|
||||
/* PPID exists, therefore we are already a daemon */
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
@ -209,14 +212,15 @@ int daemon_start()
|
||||
|
||||
if (pfh == NULL) {
|
||||
if (errno == EEXIST) {
|
||||
errx(EXIT_FAILURE, "Daemon already running, pid: %jd.", (intmax_t)otherpid);
|
||||
errx(EXIT_FAILURE,
|
||||
"Daemon already running, pid: %jd.",
|
||||
(intmax_t) otherpid);
|
||||
}
|
||||
warn("Cannot open or create pidfile: %s", pid_filename);
|
||||
}
|
||||
|
||||
/* fork ourselves if not asked otherwise */
|
||||
if (fork())
|
||||
{
|
||||
if (fork()) {
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@ -229,11 +233,13 @@ int daemon_start()
|
||||
|
||||
/* Block unnecessary signals */
|
||||
sigemptyset(&sig_set);
|
||||
sigaddset(&sig_set, SIGCHLD); /* ignore child - i.e. we don't need to wait for it */
|
||||
sigaddset(&sig_set, SIGCHLD); /* ignore child - i.e. we don't need
|
||||
* to wait for it */
|
||||
sigaddset(&sig_set, SIGTSTP); /* ignore Tty stop signals */
|
||||
sigaddset(&sig_set, SIGTTOU); /* ignore Tty background writes */
|
||||
sigaddset(&sig_set, SIGTTIN); /* ignore Tty background reads */
|
||||
sigprocmask(SIG_BLOCK, &sig_set, NULL); /* Block the above specified signals */
|
||||
sigprocmask(SIG_BLOCK, &sig_set, NULL); /* Block the above specified
|
||||
* signals */
|
||||
|
||||
/* Catch necessary signals */
|
||||
sig_action.sa_handler = signal_handler;
|
||||
@ -262,7 +268,8 @@ int daemon_start()
|
||||
flockfile(cache_file);
|
||||
|
||||
fill_iftot(tot);
|
||||
fprintf(cache_file, "obytes.value %ld:%lu\nrbytes.value %ld:%lu\n", epoch, tot->ift_ob, epoch, tot->ift_ib);
|
||||
fprintf(cache_file, "obytes.value %ld:%lu\nrbytes.value %ld:%lu\n",
|
||||
epoch, tot->ift_ob, epoch, tot->ift_ib);
|
||||
fflush(cache_file);
|
||||
|
||||
funlockfile(cache_file);
|
||||
@ -272,7 +279,8 @@ int daemon_start()
|
||||
return (0);
|
||||
}
|
||||
|
||||
int fetch()
|
||||
int
|
||||
fetch()
|
||||
{
|
||||
/* this should return data from cache file */
|
||||
FILE *cache_file = fopen(cache_filename, "r+");
|
||||
@ -292,7 +300,8 @@ int fetch()
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argv[0] && argv[0][0])
|
||||
program_name = argv[0];
|
||||
@ -307,8 +316,7 @@ int main(int argc, char* argv[])
|
||||
interface = strchr(program_name, '_') + 1;
|
||||
}
|
||||
|
||||
/* program should always run with a valid
|
||||
executable name */
|
||||
/* program should always run with a valid executable name */
|
||||
if (strlen(interface) < 1) {
|
||||
errx(EX_USAGE, "Please run from symlink");
|
||||
}
|
||||
@ -317,7 +325,8 @@ int main(int argc, char* argv[])
|
||||
char *MUNIN_PLUGSTATE = getenv("MUNIN_PLUGSTATE");
|
||||
|
||||
/* Default is current directory */
|
||||
if (!MUNIN_PLUGSTATE) MUNIN_PLUGSTATE = ".";
|
||||
if (!MUNIN_PLUGSTATE)
|
||||
MUNIN_PLUGSTATE = ".";
|
||||
|
||||
asprintf(&pid_filename, "%s/%s.pid", MUNIN_PLUGSTATE, program_name);
|
||||
asprintf(&cache_filename, "%s/%s.value", MUNIN_PLUGSTATE, program_name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user