1 From 64dd780905ae339a0a57e4aba541799016816a1a Mon Sep 17 00:00:00 2001
2 From: Darik Horn <dajhorn@vanadac.com>
3 Date: Fri, 3 Oct 2014 13:30:24 -0400
4 Subject: [PATCH] Create a non-forking softetherd for upstart and systemd.
6 Implement a daemon that expects to be invoked by a new-style init like upstart
9 /usr/sbin/softetherd [vpnbridge|vpnclient|vpnserver]
11 Alternatively, if the command line argument is empty, then use the
12 `SOFTETHER_MODE` environment variable instead.
15 src/bin/hamcore/strtable_en.stb
18 https://github.com/dajhorn/SoftEtherVPN/commit/64dd780905ae339a0a57e4aba541799016816a1a.
20 Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
21 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
24 src/Makefile.am | 3 ++
25 src/bin/hamcore/strtable_en.stb | 1 +
26 src/softetherd/Makefile.am | 28 ++++++++++
27 src/softetherd/softetherd.c | 114 ++++++++++++++++++++++++++++++++++++++++
28 5 files changed, 147 insertions(+)
29 create mode 100644 src/softetherd/Makefile.am
30 create mode 100644 src/softetherd/softetherd.c
33 ===================================================================
37 src/vpnclient/Makefile
38 src/vpnbridge/Makefile
40 + src/softetherd/Makefile
44 Index: b/src/Makefile.am
45 ===================================================================
50 # These are the final build products.
51 SUBDIRS += vpnserver vpnclient vpnbridge vpncmd
53 +# This is a daemon for upstart and systemd.
54 +SUBDIRS += softetherd
55 Index: b/src/bin/hamcore/strtable_en.stb
56 ===================================================================
57 --- a/src/bin/hamcore/strtable_en.stb
58 +++ b/src/bin/hamcore/strtable_en.stb
62 # Concerning services (UNIX)
63 +UNIX_DAEMON_HELP SoftEther VPN non-forking daemon for upstart and systemd.\nCommand Usage:\n %S vpnbridge - Enable bridging features.\n %S vpnclient - Enable client features.\n %S vpnserver - Enable all features.\nThe parameter can be set in the SOFTETHER_MODE environment variable.\n\n
64 UNIX_SVC_HELP %S service program\nCopyright (c) SoftEther VPN Project. All Rights Reserved.\n\n%S command usage:\n %S start - Start the %S service.\n %S stop - Stop the %S service if the service has been already started.\n\n
65 UNIX_SVC_STARTED The %S service has been started.\n
66 UNIX_SVC_STOPPING Stopping the %S service ...\n
67 Index: b/src/softetherd/Makefile.am
68 ===================================================================
70 +++ b/src/softetherd/Makefile.am
72 +# Copyright 2014 Darik Horn <dajhorn@vanadac.com>
74 +# This file is part of SoftEther.
76 +# SoftEther is free software: you can redistribute it and/or modify it under
77 +# the terms of the GNU General Public License as published by the Free
78 +# Software Foundation, either version 2 of the License, or (at your option)
81 +# SoftEther is distributed in the hope that it will be useful, but WITHOUT ANY
82 +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
83 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
86 +# You should have received a copy of the GNU General Public License along with
87 +# SoftEther. If not, see <http://www.gnu.org/licenses/>.
90 +include $(top_srcdir)/autotools/softether.am
95 +softetherd_SOURCES = \
99 + $(top_builddir)/src/libsoftether/libsoftether.la
100 Index: b/src/softetherd/softetherd.c
101 ===================================================================
103 +++ b/src/softetherd/softetherd.c
105 +// SoftEther VPN daemon for upstart and systemd.
107 +// Copyright 2014 Darik Horn <dajhorn@vanadac.com>
109 +// This file is part of SoftEther.
111 +// SoftEther is free software: you can redistribute it and/or modify it under
112 +// the terms of the GNU General Public License as published by the Free
113 +// Software Foundation, either version 2 of the License, or (at your option)
114 +// any later version.
116 +// SoftEther is distributed in the hope that it will be useful, but WITHOUT ANY
117 +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
118 +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
121 +// You should have received a copy of the GNU General Public License along with
122 +// SoftEther. If not, see <http://www.gnu.org/licenses/>.
125 +#include <GlobalConst.h>
135 +#include <Mayaqua/Mayaqua.h>
136 +#include <Cedar/Cedar.h>
138 +void DaemonUsage(char *name)
140 + UniPrint(_UU("UNIX_DAEMON_HELP"), name, name, name);
144 +void DaemonStartProcess()
146 + // This environment variable is exported by upstart.
147 + char *upstart_job = getenv("UPSTART_JOB");
151 + StStartServer(false);
153 + // Notify upstart that softetherd is ready.
154 + if (upstart_job != NULL)
156 + unsetenv("UPSTART_JOB");
162 +void DaemonStopProcess()
170 +int main(int argc, char *argv[])
172 + // This environment variable is sourced and exported by the init process from /etc/default/softether.
173 + char *softether_mode = getenv("SOFTETHER_MODE");
175 + InitMayaqua(false, false, argc, argv);
177 + // Check for an explicit invocation. (eg: "/usr/sbin/softetherd vpnserver")
180 + if (StrCmpi(argv[1], "vpnbridge") == 0
181 + || StrCmpi(argv[1], "vpnclient") == 0
182 + || StrCmpi(argv[1], "vpnserver") == 0)
184 + UnixExecService(argv[1], DaemonStartProcess, DaemonStopProcess);
189 + // Exit status codes 150..199 are reserved for the application by the LSB.
190 + fprintf(stderr, "Error: Unrecognized parameter: %s\n", argv[1]);
196 + // Alternatively, use the environment variable.
197 + if (softether_mode != NULL)
199 + if (StrCmpi(softether_mode, "vpnbridge") == 0
200 + || StrCmpi(softether_mode, "vpnclient") == 0
201 + || StrCmpi(softether_mode, "vpnserver") == 0)
203 + UnixExecService(softether_mode, DaemonStartProcess, DaemonStopProcess);
208 + // Exit status codes 150..199 are reserved for the application by the LSB.
209 + fprintf(stderr, "Error: Unrecognized environment variable: SOFTETHER_MODE=%s\n", softether_mode);
215 + DaemonUsage(argv[0]);