micropython: replace local fix with upstream one
[buildroot-gz.git] / package / softether / 0002-create-non-forking-softetherd-for-upstart-and-systemd.patch
blob72913b0bf3fa4de6d6c091e64d4158a54fc5773d
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
7 or systemd as:
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.
14 Conflicts:
15 src/bin/hamcore/strtable_en.stb
17 Taken from Github at
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>
22 ---
23 configure.ac | 1 +
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
32 Index: b/configure.ac
33 ===================================================================
34 --- a/configure.ac
35 +++ b/configure.ac
36 @@ -36,6 +36,7 @@
37 src/vpnclient/Makefile
38 src/vpnbridge/Makefile
39 src/vpncmd/Makefile
40 + src/softetherd/Makefile
44 Index: b/src/Makefile.am
45 ===================================================================
46 --- a/src/Makefile.am
47 +++ b/src/Makefile.am
48 @@ -27,3 +27,6 @@
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
59 @@ -1062,6 +1062,7 @@
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 ===================================================================
69 --- /dev/null
70 +++ b/src/softetherd/Makefile.am
71 @@ -0,0 +1,28 @@
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)
79 +# any later version.
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
84 +# details.
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
92 +sbin_PROGRAMS = \
93 + softetherd
95 +softetherd_SOURCES = \
96 + softetherd.c
98 +softetherd_LDADD = \
99 + $(top_builddir)/src/libsoftether/libsoftether.la
100 Index: b/src/softetherd/softetherd.c
101 ===================================================================
102 --- /dev/null
103 +++ b/src/softetherd/softetherd.c
104 @@ -0,0 +1,114 @@
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
119 +// details.
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>
127 +#define VPN_EXE
129 +#include <stdio.h>
130 +#include <stdlib.h>
131 +#include <string.h>
132 +#include <wchar.h>
133 +#include <stdarg.h>
134 +#include <time.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");
149 + InitCedar();
150 + StInit();
151 + StStartServer(false);
153 + // Notify upstart that softetherd is ready.
154 + if (upstart_job != NULL)
156 + unsetenv("UPSTART_JOB");
157 + raise(SIGSTOP);
162 +void DaemonStopProcess()
164 + StStopServer();
165 + StFree();
166 + FreeCedar();
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")
178 + if (argc >= 2)
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);
185 + FreeMayaqua();
186 + return 0;
189 + // Exit status codes 150..199 are reserved for the application by the LSB.
190 + fprintf(stderr, "Error: Unrecognized parameter: %s\n", argv[1]);
191 + fflush(stderr);
192 + FreeMayaqua();
193 + return 150;
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);
204 + FreeMayaqua();
205 + return 0;
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);
210 + fflush(stderr);
211 + FreeMayaqua();
212 + return 151;
215 + DaemonUsage(argv[0]);
216 + FreeMayaqua();
217 + return 3;