Path: blob/main/dns/dns_balance/files/patch-dns_balance.rb
16146 views
--- dns_balance.rb.orig 2017-02-09 19:28:01.643383000 -08001+++ dns_balance.rb 2017-02-09 19:26:31.609711000 -08002@@ -8,14 +8,7 @@3# $Id: dns_balance.rb,v 1.26 2017-02-09 17:18:59 chrish Exp $45# DNS Balance6-if ENV["ROOT"] == nil7- warn("\"ROOT\" environment is recommended. Use current directory in this time.")8- PREFIX = "."9-# exit(111)10-else11- PREFIX = ENV["ROOT"]12- $LOAD_PATH.unshift(PREFIX)13-end14+$LOAD_PATH.unshift("%%PREFIX%%/etc/%%PORTNAME%%", "%%PREFIX%%/lib/%%PORTNAME%%")15$LOAD_PATH.freeze1617require 'socket'18@@ -204,6 +197,14 @@19opt.on("--as", "Enable AS namespace") {20OPT["as"] = true21}22+ opt.on("-l LOGFILE", String, "Print log to LOGFILE") {23+ |o|24+ OPT["l"] = o;25+ }26+ opt.on("-p PIDFILE", String, "Record PID to PIDFILE") {27+ |o|28+ OPT["p"] = o;29+ }30opt.on_tail("-h", "--help", "Show this help message and exit") {31STDERR.printf("%s", opt.to_s)32exit(111)33@@ -212,10 +213,42 @@34}35OPT.freeze3637-ML = MultiLog::new38-ML.open39+exit! if fork40+Process::setsid41+exit! if fork42+STDIN.close43+STDOUT.close44+STDERR.close45+46+$pidfile = nil47+if OPT["p"]48+ $pidfile = OPT["p"]49+ File::open($pidfile, 'w') { |f| f.puts $$ }50+end51+52+$logout = nil53+if OPT["l"]54+ $logout = File::open(OPT["l"], 'a+')55+ $logout.sync = true56+end57+58+[0, 2, 3, 5, 10, 13, 15].each do |sig|59+ trap(sig) {60+ File::unlink($pidfile) if $pidfile61+ $logout.close if $logout62+ exit63+ }64+end65+66+ ML = MultiLog.new67+if OPT["l"]68+ $logout = File::open(OPT["l"], 'a+')69+ $logout.sync = true70+ ML.open($logout)71+else72+ ML.open73+end7475-ML.log("dir: " + PREFIX)76ML.log("start")777879@@ -224,7 +257,7 @@80#81Thread::start {82loop {83- if test(?r, PREFIX + "/addr") || test(?r, "./addr")84+ if test(?r, "%%ETCDIR%%" + "/addr")85begin86load("addr")8788@@ -234,7 +267,7 @@89end90end9192- #if test(?r, PREFIX + "/addr-once") || test(?r, "./addr-once")93+ #if test(?r, "%%ETCDIR%%" + "/addr-once")94# Thread.exit95#end96979899