Commit 07ddef40 authored by Geoff Simmons's avatar Geoff Simmons

trackrdrd: added the -y option to set the syslog facility

parent aae6304b
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
default, syslog(3) is used for logging. Log levels correspond default, syslog(3) is used for logging. Log levels correspond
to the 'priorities' defined by syslog(3). to the 'priorities' defined by syslog(3).
-y syslog_facility
Set the syslog facility; legal values are 'user' or 'local0'
through 'local7', and the default is 'local0'. Options -y and
-l are mutually exclusive.
-f varnishlog_bindump -f varnishlog_bindump
A binary dump of the Varnish SHM log produced by 'varnishlog A binary dump of the Varnish SHM log produced by 'varnishlog
-w'. If this option is specified, trackrdrd reads from the -w'. If this option is specified, trackrdrd reads from the
......
...@@ -35,12 +35,16 @@ ...@@ -35,12 +35,16 @@
#include <stdarg.h> #include <stdarg.h>
#include <strings.h> #include <strings.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "trackrdrd.h" #include "trackrdrd.h"
#include "libvarnish.h" #include "libvarnish.h"
static const char *level2name[LOG_DEBUG]; static const char *level2name[LOG_DEBUG];
static const int facilitynum[8] =
{ LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5,
LOG_LOCAL6, LOG_LOCAL7 };
static void static void
syslog_setlevel(int level) syslog_setlevel(int level)
...@@ -48,6 +52,22 @@ syslog_setlevel(int level) ...@@ -48,6 +52,22 @@ syslog_setlevel(int level)
setlogmask(LOG_UPTO(level)); setlogmask(LOG_UPTO(level));
} }
static int
syslog_getFacility(const char *facility) {
int localnum;
if (strcasecmp(facility, "USER") == 0)
return LOG_USER;
if (strlen(facility) != 6
|| strncasecmp(facility, "LOCAL", 5) != 0
|| !isdigit(facility[5]))
return(-1);
localnum = atoi(&facility[5]);
if (localnum > 7)
return(-1);
return(facilitynum[localnum]);
}
/* XXX: is this safe? */ /* XXX: is this safe? */
static void static void
stdio_initnames(void) stdio_initnames(void)
...@@ -88,15 +108,23 @@ stdio_close(void) ...@@ -88,15 +108,23 @@ stdio_close(void)
fclose(logconf.out); fclose(logconf.out);
} }
int LOG_Open(const char *progname, const char *dest) int LOG_Open(const char *progname, const char *dest, const char *facility)
{ {
if (dest == NULL) { if (dest == NULL) {
/* syslog */ /* syslog */
int fac = LOG_LOCAL0;
if (facility != NULL) {
fac = syslog_getFacility(facility);
if (fac < 0) {
fprintf(stderr, "Invalid facility: %s\n", facility);
return(-1);
}
}
logconf.log = syslog; logconf.log = syslog;
logconf.setlevel = syslog_setlevel; logconf.setlevel = syslog_setlevel;
logconf.close = closelog; logconf.close = closelog;
openlog(progname, LOG_PID | LOG_CONS | LOG_NDELAY | LOG_NOWAIT, openlog(progname, LOG_PID | LOG_CONS | LOG_NDELAY | LOG_NOWAIT, fac);
LOG_USER);
setlogmask(LOG_UPTO(LOG_INFO)); setlogmask(LOG_UPTO(LOG_INFO));
atexit(closelog); atexit(closelog);
return(0); return(0);
...@@ -106,8 +134,10 @@ int LOG_Open(const char *progname, const char *dest) ...@@ -106,8 +134,10 @@ int LOG_Open(const char *progname, const char *dest)
logconf.out = stdout; logconf.out = stdout;
else { else {
logconf.out = fopen(dest, "w"); logconf.out = fopen(dest, "w");
if (logconf.out == NULL) if (logconf.out == NULL) {
perror(dest);
return(-1); return(-1);
}
} }
logconf.level = LOG_INFO; logconf.level = LOG_INFO;
logconf.log = stdio_log; logconf.log = stdio_log;
......
...@@ -76,10 +76,10 @@ OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len, ...@@ -76,10 +76,10 @@ OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
int datalen; int datalen;
char *data; char *data;
(void) priv;
(void) bitmap; (void) bitmap;
#if 1 #if 1
(void) spec; (void) spec;
(void) priv;
(void) fd; (void) fd;
#endif #endif
#if 0 #if 0
...@@ -191,14 +191,15 @@ main(int argc, char * const *argv) ...@@ -191,14 +191,15 @@ main(int argc, char * const *argv)
{ {
int c; int c;
int D_flag = 0, d_flag = 0; int D_flag = 0, d_flag = 0;
const char *P_arg = NULL, *l_arg = NULL, *n_arg = NULL, *f_arg = NULL; const char *P_arg = NULL, *l_arg = NULL, *n_arg = NULL, *f_arg = NULL,
*y_arg = NULL;
struct vpf_fh *pfh = NULL; struct vpf_fh *pfh = NULL;
struct VSM_data *vd; struct VSM_data *vd;
vd = VSM_New(); vd = VSM_New();
VSL_Setup(vd); VSL_Setup(vd);
while ((c = getopt(argc, argv, "DP:Vn:hl:df:")) != -1) { while ((c = getopt(argc, argv, "DP:Vn:hl:df:y:")) != -1) {
switch (c) { switch (c) {
case 'D': case 'D':
D_flag = 1; D_flag = 1;
...@@ -221,6 +222,9 @@ main(int argc, char * const *argv) ...@@ -221,6 +222,9 @@ main(int argc, char * const *argv)
case 'f': case 'f':
f_arg = optarg; f_arg = optarg;
break; break;
case 'y':
y_arg = optarg;
break;
case 'h': case 'h':
usage(EXIT_SUCCESS); usage(EXIT_SUCCESS);
default: default:
...@@ -233,14 +237,15 @@ main(int argc, char * const *argv) ...@@ -233,14 +237,15 @@ main(int argc, char * const *argv)
if (f_arg && n_arg) if (f_arg && n_arg)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
if (l_arg && y_arg)
usage(EXIT_FAILURE);
if (f_arg && VSL_Arg(vd, 'r', f_arg) <= 0) if (f_arg && VSL_Arg(vd, 'r', f_arg) <= 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
else if (n_arg && VSL_Arg(vd, 'n', n_arg) <= 0) else if (n_arg && VSL_Arg(vd, 'n', n_arg) <= 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (LOG_Open(PACKAGE_NAME, l_arg) != 0) { if (LOG_Open(PACKAGE_NAME, l_arg, y_arg) != 0) {
perror(l_arg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (d_flag) if (d_flag)
...@@ -273,13 +278,9 @@ main(int argc, char * const *argv) ...@@ -273,13 +278,9 @@ main(int argc, char * const *argv)
/* Only read the VSL tags relevant to tracking */ /* Only read the VSL tags relevant to tracking */
assert(VSL_Arg(vd, 'i', TRACK_TAGS) > 0); assert(VSL_Arg(vd, 'i', TRACK_TAGS) > 0);
while (VSL_Dispatch(vd, OSL_Track, stdout) >= 0) { while (VSL_Dispatch(vd, OSL_Track, NULL) >= 0)
if (fflush(stdout) != 0) { ;
perror("stdout");
break;
}
}
/* XXX: Parent removes PID */ /* XXX: Parent removes PID */
if (pfh != NULL) if (pfh != NULL)
VPF_Remove(pfh); VPF_Remove(pfh);
......
...@@ -44,7 +44,7 @@ struct logconf { ...@@ -44,7 +44,7 @@ struct logconf {
int level; int level;
} logconf; } logconf;
int LOG_Open(const char *progname, const char *dest); int LOG_Open(const char *progname, const char *dest, const char *facility);
/* XXX: __VA_ARGS__ can't be empty ... */ /* XXX: __VA_ARGS__ can't be empty ... */
#define LOG_Log0(level, msg) logconf.log(level, msg) #define LOG_Log0(level, msg) logconf.log(level, msg)
#define LOG_Log(level, msg, ...) logconf.log(level, msg, __VA_ARGS__) #define LOG_Log(level, msg, ...) logconf.log(level, msg, __VA_ARGS__)
......
trackrdrd [-n varnish_name] [-l log_file] [-f varnishlog_bindump] trackrdrd [[-n varnish_name] | [-f varnishlog_bindump]]
[[-l log_file] | [-y syslog_facility]]
[-d] [-V] [-h] [-d] [-V] [-h]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment