xl2tpd: conditionally build with flags for more verbose log output.
[feed/packages.git] / net / xl2tpd / patches / 207-xl2tpd-introduce-new-option-l-for-using-syslog-as-th.patch
1 From b3402a68a4d29e9b1ae4e012e39a7bcb14fea3cf Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Thu, 30 Apr 2015 13:57:36 +0800
4 Subject: [PATCH 207/210] xl2tpd: introduce new option -l for using syslog as
5 the logging facility.
6
7 Defaults to old behaviour if no -l option was specified. Also update
8 manual doc to reflect this change.
9 ---
10 doc/xl2tpd.8 | 5 +++++
11 file.h | 1 +
12 misc.c | 2 +-
13 xl2tpd.c | 13 ++++++++++++-
14 4 files changed, 19 insertions(+), 2 deletions(-)
15
16 diff --git a/doc/xl2tpd.8 b/doc/xl2tpd.8
17 index 915b247..7afccac 100644
18 --- a/doc/xl2tpd.8
19 +++ b/doc/xl2tpd.8
20 @@ -20,6 +20,11 @@ This option prevents xl2tpd from detaching from the terminal and
21 daemonizing.
22
23 .TP
24 +.B -l
25 +This option tells xl2tpd to use syslog for logging even when \fB\-D\fR
26 +was specified.
27 +
28 +.TP
29 .B -c <config file>
30 Tells xl2tpd to use an alternate config file. Default is
31 /etc/xl2tpd/xl2tpd.conf. Fallback configuration file is
32 diff --git a/file.h b/file.h
33 index 89987ae..92df046 100644
34 --- a/file.h
35 +++ b/file.h
36 @@ -151,6 +151,7 @@ struct global
37 char pidfile[STRLEN]; /* File containing the pid number*/
38 char controlfile[STRLEN]; /* Control file name (named pipe) */
39 int daemon; /* Use daemon mode? */
40 + int syslog; /* Use syslog for logging? */
41 int accesscontrol; /* Use access control? */
42 int forceuserspace; /* Force userspace? */
43 int packet_dump; /* Dump (print) all packets? */
44 diff --git a/misc.c b/misc.c
45 index 3092401..cccf4ca 100644
46 --- a/misc.c
47 +++ b/misc.c
48 @@ -57,7 +57,7 @@ void l2tp_log (int level, const char *fmt, ...)
49 vsnprintf (buf, sizeof (buf), fmt, args);
50 va_end (args);
51
52 - if(gconfig.daemon) {
53 + if(gconfig.syslog) {
54 init_log();
55 SYSLOG_CALL( syslog (level, "%s", buf) );
56 } else {
57 diff --git a/xl2tpd.c b/xl2tpd.c
58 index 017adfd..1937690 100644
59 --- a/xl2tpd.c
60 +++ b/xl2tpd.c
61 @@ -1594,7 +1594,7 @@ void do_control ()
62 void usage(void) {
63 printf("\nxl2tpd version: %s\n", SERVER_VERSION);
64 printf("Usage: xl2tpd [-c <config file>] [-s <secret file>] [-p <pid file>]\n"
65 - " [-C <control file>] [-D]\n"
66 + " [-C <control file>] [-D] [-l]\n"
67 " [-v, --version]\n");
68 printf("\n");
69 exit(1);
70 @@ -1605,6 +1605,7 @@ void init_args(int argc, char *argv[])
71 int i=0;
72
73 gconfig.daemon=1;
74 + gconfig.syslog=-1;
75 memset(gconfig.altauthfile,0,STRLEN);
76 memset(gconfig.altconfigfile,0,STRLEN);
77 memset(gconfig.authfile,0,STRLEN);
78 @@ -1642,6 +1643,9 @@ void init_args(int argc, char *argv[])
79 else if (! strncmp(argv[i],"-D",2)) {
80 gconfig.daemon=0;
81 }
82 + else if (! strncmp(argv[i],"-l",2)) {
83 + gconfig.syslog=1;
84 + }
85 else if (! strncmp(argv[i],"-s",2)) {
86 if(++i == argc)
87 usage();
88 @@ -1667,6 +1671,13 @@ void init_args(int argc, char *argv[])
89 usage();
90 }
91 }
92 +
93 + /*
94 + * defaults to syslog if no log facility was explicitly
95 + * specified and we are about to daemonize
96 + */
97 + if (gconfig.syslog < 0)
98 + gconfig.syslog = gconfig.daemon;
99 }
100
101
102 --
103 1.7.10.4
104