PATCH: syslog while not running as a daemon
Hi!
When not running as a daemon (--daemon option), OpenVPN writes all output to stderr. When OpenVPN isn't run interactively, but it actually isn't run with the --daemon option as well, it's rather inconvenient that syslog isn't used. This is primarily an issue for the development of a VPN appliance I'm working on (http://adsl-dc-3b681.adsl.wanadoo.nl/vvpn) but if for example OpenVPN would be controlled by inittab the same problem is there.
Attached a patch that solves the problem for me, it may be of use to others as well.
Cheers!
Rolf
options.c renamed from options.c.fks +26 -2
@@ -232,6 +232,9 @@" See --daemon above for a description of the 'name' parm.\n" "--log file : Output log to file which is created/truncated on open.\n" "--log-append file : Append log to file, or create file if nonexistent.\n" +"--syslog [name] : Output log to syslog.\n" +" The optional 'name' parameter will be passed\n" +" as the program name to the system logger.\n" "--suppress-timestamps : Don't log timestamps to stdout/stderr.\n" "--writepid file : Write main process ID to file.\n" "--nice n : Change process priority (>0 = lower, <0 = higher).\n"
@@ -1014,6 +1017,7 @@SHOW_BOOL (up_restart);SHOW_BOOL (up_delay);SHOW_BOOL (daemon); +SHOW_BOOL (syslog);SHOW_INT (inetd);SHOW_BOOL (log);SHOW_BOOL (suppress_timestamps);
@@ -2895,12 +2899,32 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->up_restart = true; } +else if (streq (p[0 ],"syslog" )) + { +bool didit = false; +VERIFY_PERMISSION (OPT_P_GENERAL ); +if (!options->syslog) + { + options->syslog = didit = true; +open_syslog (p[1 ], false); + } +if (p[1 ]) + { + ++i; +if (!didit) + { +msg (M_WARN ,"WARNING: Multiple --daemon/syslog directives specified, ignoring --syslog %s. (Note that initscripts sometimes add their own --daemon/syslog directive.)" , p[1 ]); + goto err; + } + } + }else if (streq (p[0 ],"daemon" )) {bool didit = false;VERIFY_PERMISSION (OPT_P_GENERAL ); -if (!options->daemon) +if (!options->syslog) { + options->syslog = didit = true; options->daemon = didit = true;open_syslog (p[1 ], false); }
@@ -2909,7 +2933,7 @@ ++i;if (!didit) { -msg (M_WARN ,"WARNING: Multiple --daemon directives specified, ignoring --daemon %s. (Note that initscripts sometimes add their own --daemon directive.)" , p[1 ]); +msg (M_WARN ,"WARNING: Multiple --daemon/syslog directives specified, ignoring --daemon %s. (Note that initscripts sometimes add their own --daemon/syslog directive.)" , p[1 ]); goto err; } }
options.h renamed from options.h.fks +1 -0
@@ -199,6 +199,7 @@bool up_delay;bool up_restart;bool daemon; +bool syslog;int remap_sigusr1;
Rolf,
A patch very similar to this one was already added in 2.0.1-rc1:
options.c 2005-02-02 12:26:04.678006080 -0600 renamed from options.c 2005-01-26 13:17:32.851107832 -0600 +7 -0
@@ -2813,6 +2813,13 @@ VERIFY_PERMISSION (OPT_P_GENERAL); options->up_restart = true; } + else if (streq (p[0], "syslog")) + { + VERIFY_PERMISSION (OPT_P_GENERAL); + if (p[1]) + ++i; + open_syslog (p[1], false); + } else if (streq (p[0], "daemon")) { bool didit = false;
James
Quoted 17 lines · Rolf Fokkens
Hi!
When not running as a daemon (--daemon option), OpenVPN writes all output to stderr. When OpenVPN isn't run interactively, but it actually isn't run with the --daemon option as well, it's rather inconvenient that syslog isn't used. This is primarily an issue for the development of a VPN appliance I'm working on
(http://adsl-dc-3b681.adsl.wanadoo.nl/vvpn) but if for example OpenVPN would be controlled by inittab the same problem is there.Attached a patch that solves the problem for me, it may be of use to others as well.
Cheers!
Rolf
Quoted 5 lines · James Yonan
Rolf,
A patch very similar to this one was already added in 2.0.1-rc1:
Thanks, then I'll wait for 2.0.1 to become final.