소스 검색

Merge pull request #32 from bjoe2k4/master

Read config directly from environment variables
tags/1.3
Timo Röhling 9 년 전
부모
커밋
541cf6e7f3
2개의 변경된 파일36개의 추가작업 그리고 3개의 파일을 삭제
  1. 0
    2
      init/postsrsd.systemd.in
  2. 36
    1
      postsrsd.c

+ 0
- 2
init/postsrsd.systemd.in 파일 보기

@@ -1,6 +1,5 @@
1 1
 [Unit]
2 2
 Description=PostSRSd Daemon
3
-After=network.target
4 3
 
5 4
 [Service]
6 5
 Type=simple
@@ -12,4 +11,3 @@ Restart=always
12 11
 
13 12
 [Install]
14 13
 WantedBy=multi-user.target
15
-

+ 36
- 1
postsrsd.c 파일 보기

@@ -221,6 +221,7 @@ static void show_help ()
221 221
     "   -u<user>       switch user id after port bind (default: none)\n"
222 222
     "   -t<seconds>    timeout for idle client connections (default: 1800)\n"
223 223
     "   -X<domain>     exclude additional domain from address rewriting\n"
224
+    "   -e             attempt to read above parameters from environment\n"
224 225
     "   -D             fork into background\n"
225 226
     "   -4             force IPv4 socket (default: any)\n"
226 227
     "   -6             force IPv6 socket (default: any)\n"
@@ -256,7 +257,7 @@ int main (int argc, char **argv)
256 257
   tmp = strrchr(argv[0], '/');
257 258
   if (tmp) self = strdup(tmp + 1); else self = strdup(argv[0]);
258 259
 
259
-  while ((opt = getopt(argc, argv, "46d:f:r:s:u:t:p:c:X::Dhv")) != -1) {
260
+  while ((opt = getopt(argc, argv, "46d:f:r:s:u:t:p:c:X::Dhev")) != -1) {
260 261
     switch (opt) {
261 262
       case '?':
262 263
         return EXIT_FAILURE;
@@ -314,6 +315,40 @@ int main (int argc, char **argv)
314 315
           excludes[s1] = NULL;
315 316
         }
316 317
         break;
318
+      case 'e':
319
+        if ( getenv("SRS_DOMAIN") != NULL )
320
+          domain = strdup(getenv("SRS_DOMAIN"));
321
+        if ( getenv("SRS_FORWARD_PORT") != NULL )
322
+          forward_service = strdup(getenv("SRS_FORWARD_PORT"));
323
+        if ( getenv("SRS_REVERSE_PORT") != NULL )
324
+          reverse_service = strdup(getenv("SRS_REVERSE_PORT"));
325
+        if ( getenv("SRS_TIMEOUT") != NULL )
326
+          timeout = atoi(getenv("SRS_TIMEOUT"));
327
+        if ( getenv("SRS_SECRET") != NULL )
328
+          secret_file = strdup(getenv("SRS_SECRET"));
329
+        if ( getenv("SRS_PID_FILE") != NULL )
330
+          pid_file = strdup(getenv("SRS_PID_FILE"));
331
+        if ( getenv("RUN_AS") != NULL )
332
+          user = strdup(getenv("RUN_AS"));
333
+        if ( getenv("CHROOT") != NULL )
334
+          chroot_dir = strdup(getenv("CHROOT"));
335
+        if (getenv("SRS_EXCLUDE_DOMAINS") != NULL) {
336
+          tmp = strtok(getenv("SRS_EXCLUDE_DOMAINS"), ",; \t\r\n");
337
+          while (tmp) {
338
+            if (s1 + 1 >= s2) {
339
+              s2 *= 2;
340
+              excludes = (const char **)realloc(excludes, s2 * sizeof(char*));
341
+              if (excludes == NULL) {
342
+                fprintf (stderr, "%s: Out of memory\n\n", self);
343
+                return EXIT_FAILURE;
344
+              }
345
+            }
346
+            excludes[s1++] = strdup(tmp);
347
+            tmp = strtok(NULL, ",; \t\r\n");
348
+          }
349
+          excludes[s1] = NULL;
350
+        }
351
+        break;
317 352
       case 'v':
318 353
         fprintf (stdout, "%s\n", VERSION);
319 354
         return EXIT_SUCCESS;

Loading…
취소
저장