6b13f685e
김민수
BSP 최초 추가
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
From 64dd780905ae339a0a57e4aba541799016816a1a Mon Sep 17 00:00:00 2001
From: Darik Horn <dajhorn@vanadac.com>
Date: Fri, 3 Oct 2014 13:30:24 -0400
Subject: [PATCH] Create a non-forking softetherd for upstart and systemd.
Implement a daemon that expects to be invoked by a new-style init like upstart
or systemd as:
/usr/sbin/softetherd [vpnbridge|vpnclient|vpnserver]
Alternatively, if the command line argument is empty, then use the
`SOFTETHER_MODE` environment variable instead.
Conflicts:
src/bin/hamcore/strtable_en.stb
Taken from Github at
https://github.com/dajhorn/SoftEtherVPN/commit/64dd780905ae339a0a57e4aba541799016816a1a.
Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
configure.ac | 1 +
src/Makefile.am | 3 ++
src/bin/hamcore/strtable_en.stb | 1 +
src/softetherd/Makefile.am | 28 ++++++++++
src/softetherd/softetherd.c | 114 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 147 insertions(+)
create mode 100644 src/softetherd/Makefile.am
create mode 100644 src/softetherd/softetherd.c
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -36,6 +36,7 @@
src/vpnclient/Makefile
src/vpnbridge/Makefile
src/vpncmd/Makefile
+ src/softetherd/Makefile
])
Index: b/src/Makefile.am
===================================================================
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,3 +27,6 @@
# These are the final build products.
SUBDIRS += vpnserver vpnclient vpnbridge vpncmd
+
+# This is a daemon for upstart and systemd.
+SUBDIRS += softetherd
Index: b/src/bin/hamcore/strtable_en.stb
===================================================================
--- a/src/bin/hamcore/strtable_en.stb
+++ b/src/bin/hamcore/strtable_en.stb
@@ -1062,6 +1062,7 @@
# Concerning services (UNIX)
+UNIX_DAEMON_HELP SoftEther VPN non-forking daemon for upstart and systemd.
Command Usage:
%S vpnbridge - Enable bridging features.
%S vpnclient - Enable client features.
%S vpnserver - Enable all features.
The parameter can be set in the SOFTETHER_MODE environment variable.
UNIX_SVC_HELP %S service program
Copyright (c) SoftEther VPN Project. All Rights Reserved.
%S command usage:
%S start - Start the %S service.
%S stop - Stop the %S service if the service has been already started.
UNIX_SVC_STARTED The %S service has been started.
UNIX_SVC_STOPPING Stopping the %S service ...
Index: b/src/softetherd/Makefile.am
===================================================================
--- /dev/null
+++ b/src/softetherd/Makefile.am
@@ -0,0 +1,28 @@
+# Copyright 2014 Darik Horn <dajhorn@vanadac.com>
+#
+# This file is part of SoftEther.
+#
+# SoftEther is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 2 of the License, or (at your option)
+# any later version.
+#
+# SoftEther is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# SoftEther. If not, see <http://www.gnu.org/licenses/>.
+
+
+include $(top_srcdir)/autotools/softether.am
+
+sbin_PROGRAMS = \
+ softetherd
+
+softetherd_SOURCES = \
+ softetherd.c
+
+softetherd_LDADD = \
+ $(top_builddir)/src/libsoftether/libsoftether.la
Index: b/src/softetherd/softetherd.c
===================================================================
--- /dev/null
+++ b/src/softetherd/softetherd.c
@@ -0,0 +1,114 @@
+// SoftEther VPN daemon for upstart and systemd.
+//
+// Copyright 2014 Darik Horn <dajhorn@vanadac.com>
+//
+// This file is part of SoftEther.
+//
+// SoftEther is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, either version 2 of the License, or (at your option)
+// any later version.
+//
+// SoftEther is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along with
+// SoftEther. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include <GlobalConst.h>
+
+#define VPN_EXE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <stdarg.h>
+#include <time.h>
+#include <Mayaqua/Mayaqua.h>
+#include <Cedar/Cedar.h>
+
+void DaemonUsage(char *name)
+{
+ UniPrint(_UU("UNIX_DAEMON_HELP"), name, name, name);
+}
+
+
+void DaemonStartProcess()
+{
+ // This environment variable is exported by upstart.
+ char *upstart_job = getenv("UPSTART_JOB");
+
+ InitCedar();
+ StInit();
+ StStartServer(false);
+
+ // Notify upstart that softetherd is ready.
+ if (upstart_job != NULL)
+ {
+ unsetenv("UPSTART_JOB");
+ raise(SIGSTOP);
+ }
+}
+
+
+void DaemonStopProcess()
+{
+ StStopServer();
+ StFree();
+ FreeCedar();
+}
+
+
+int main(int argc, char *argv[])
+{
+ // This environment variable is sourced and exported by the init process from /etc/default/softether.
+ char *softether_mode = getenv("SOFTETHER_MODE");
+
+ InitMayaqua(false, false, argc, argv);
+
+ // Check for an explicit invocation. (eg: "/usr/sbin/softetherd vpnserver")
+ if (argc >= 2)
+ {
+ if (StrCmpi(argv[1], "vpnbridge") == 0
+ || StrCmpi(argv[1], "vpnclient") == 0
+ || StrCmpi(argv[1], "vpnserver") == 0)
+ {
+ UnixExecService(argv[1], DaemonStartProcess, DaemonStopProcess);
+ FreeMayaqua();
+ return 0;
+ }
+
+ // Exit status codes 150..199 are reserved for the application by the LSB.
+ fprintf(stderr, "Error: Unrecognized parameter: %s
", argv[1]);
+ fflush(stderr);
+ FreeMayaqua();
+ return 150;
+ }
+
+ // Alternatively, use the environment variable.
+ if (softether_mode != NULL)
+ {
+ if (StrCmpi(softether_mode, "vpnbridge") == 0
+ || StrCmpi(softether_mode, "vpnclient") == 0
+ || StrCmpi(softether_mode, "vpnserver") == 0)
+ {
+ UnixExecService(softether_mode, DaemonStartProcess, DaemonStopProcess);
+ FreeMayaqua();
+ return 0;
+ }
+
+ // Exit status codes 150..199 are reserved for the application by the LSB.
+ fprintf(stderr, "Error: Unrecognized environment variable: SOFTETHER_MODE=%s
", softether_mode);
+ fflush(stderr);
+ FreeMayaqua();
+ return 151;
+ }
+
+ DaemonUsage(argv[0]);
+ FreeMayaqua();
+ return 3;
+}
|