Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/dns/dns_balance/files/patch-dns_balance.rb
16146 views
1
--- dns_balance.rb.orig 2017-02-09 19:28:01.643383000 -0800
2
+++ dns_balance.rb 2017-02-09 19:26:31.609711000 -0800
3
@@ -8,14 +8,7 @@
4
# $Id: dns_balance.rb,v 1.26 2017-02-09 17:18:59 chrish Exp $
5
6
# DNS Balance
7
-if ENV["ROOT"] == nil
8
- warn("\"ROOT\" environment is recommended. Use current directory in this time.")
9
- PREFIX = "."
10
-# exit(111)
11
-else
12
- PREFIX = ENV["ROOT"]
13
- $LOAD_PATH.unshift(PREFIX)
14
-end
15
+$LOAD_PATH.unshift("%%PREFIX%%/etc/%%PORTNAME%%", "%%PREFIX%%/lib/%%PORTNAME%%")
16
$LOAD_PATH.freeze
17
18
require 'socket'
19
@@ -204,6 +197,14 @@
20
opt.on("--as", "Enable AS namespace") {
21
OPT["as"] = true
22
}
23
+ opt.on("-l LOGFILE", String, "Print log to LOGFILE") {
24
+ |o|
25
+ OPT["l"] = o;
26
+ }
27
+ opt.on("-p PIDFILE", String, "Record PID to PIDFILE") {
28
+ |o|
29
+ OPT["p"] = o;
30
+ }
31
opt.on_tail("-h", "--help", "Show this help message and exit") {
32
STDERR.printf("%s", opt.to_s)
33
exit(111)
34
@@ -212,10 +213,42 @@
35
}
36
OPT.freeze
37
38
-ML = MultiLog::new
39
-ML.open
40
+exit! if fork
41
+Process::setsid
42
+exit! if fork
43
+STDIN.close
44
+STDOUT.close
45
+STDERR.close
46
+
47
+$pidfile = nil
48
+if OPT["p"]
49
+ $pidfile = OPT["p"]
50
+ File::open($pidfile, 'w') { |f| f.puts $$ }
51
+end
52
+
53
+$logout = nil
54
+if OPT["l"]
55
+ $logout = File::open(OPT["l"], 'a+')
56
+ $logout.sync = true
57
+end
58
+
59
+[0, 2, 3, 5, 10, 13, 15].each do |sig|
60
+ trap(sig) {
61
+ File::unlink($pidfile) if $pidfile
62
+ $logout.close if $logout
63
+ exit
64
+ }
65
+end
66
+
67
+ ML = MultiLog.new
68
+if OPT["l"]
69
+ $logout = File::open(OPT["l"], 'a+')
70
+ $logout.sync = true
71
+ ML.open($logout)
72
+else
73
+ ML.open
74
+end
75
76
-ML.log("dir: " + PREFIX)
77
ML.log("start")
78
79
80
@@ -224,7 +257,7 @@
81
#
82
Thread::start {
83
loop {
84
- if test(?r, PREFIX + "/addr") || test(?r, "./addr")
85
+ if test(?r, "%%ETCDIR%%" + "/addr")
86
begin
87
load("addr")
88
89
@@ -234,7 +267,7 @@
90
end
91
end
92
93
- #if test(?r, PREFIX + "/addr-once") || test(?r, "./addr-once")
94
+ #if test(?r, "%%ETCDIR%%" + "/addr-once")
95
# Thread.exit
96
#end
97
98
99