diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-02-14 16:07:19 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-02-14 16:10:39 +0200 |
commit | 2d2e9e1fdadb5af7bfd5a2a77500218b592034e1 (patch) | |
tree | 01aab262490eeff1dcea109767719ba1f84b50fc /src | |
parent | fe4dd5c7fe77591ee8d7780d3f5e2e9b9334c2c5 (diff) | |
download | varnish-mib-2d2e9e1fdadb5af7bfd5a2a77500218b592034e1.tar.gz varnish-mib-2d2e9e1fdadb5af7bfd5a2a77500218b592034e1.tar.bz2 |
Version 4.0release-4.0
* Makefile.am: Add init.
* NEWS: Update.
* README: Mention initialization files from init.
* configure.ac: Version 4.0
* init/README: New file.
* init/debian: New file.
* init/rh: New file.
* init/slackware: New file.
* init/slackware.genrc: New file.
* init/varnish-mib.service: New file.
* src/main.c: Minor fixes.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 5 |
1 files changed, 2 insertions, 3 deletions
@@ -1,16 +1,17 @@ #include "varnish_mib.h" #include <unistd.h> #include <sys/types.h> #include <signal.h> +#include <string.h> char *progname; static void pidfile_check(char const *pid_file); static void pidfile_create(char const *pid_file); static int pidfile_remove(char const *pid_file); void usage(FILE *fp) { fprintf(fp, "usage: varnish-mib [OPTIONS]\n"); fprintf(fp, "SNMP agent for Varnish Cache monitoring\n"); @@ -165,25 +166,24 @@ main(int argc, char **argv) snmp_enable_stderrlog(); SOCK_STARTUP; init_agent(progname); init_varnish_mib(); init_snmp(progname); if (post_config()) exit(1); pidfile_check(pid_file); if (!foreground) { - int i; if (daemon(0, 1)) { fprintf(stderr, "%s: daemon: %s\n", progname, strerror(errno)); exit(1); } openlog(progname, LOG_CONS|LOG_PID, LOG_DAEMON); if (!log_set) { snmp_enable_syslog_ident(progname, LOG_DAEMON); snmp_disable_stderrlog(); } } @@ -221,50 +221,49 @@ pidfile_remove(char const *pid_file) static void pidfile_create(char const *pid_file) { FILE *fp; if (!pid_file) return; fp = fopen(pid_file, "w"); if (!fp) { snmp_log(LOG_CRIT, "cannot create pidfile `%s': %s\n", - progname, pid_file, strerror(errno)); exit(1); } fprintf(fp, "%lu\n", (unsigned long) getpid()); fclose(fp); } /* Check whether pidfile exists and if so, whether its PID is still active. Exit if it is. */ static void pidfile_check(char const *pid_file) { unsigned long pid; FILE *fp; if (!pid_file) return; fp = fopen(pid_file, "r"); if (fp) { if (fscanf(fp, "%lu", &pid) != 1) { snmp_log(LOG_ERR, - "cannot get pid from pidfile `%s'\n", + "cannot get pid from pidfile `%s': %s\n", pid_file, strerror(errno)); } else { if (kill(pid, 0) == 0) { snmp_log(LOG_ERR, "%s appears to run with pid %lu. " "If it does not, remove `%s' and retry.\n", progname, pid, pid_file); exit(1); } |