You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.2 KiB

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