Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/drb
File: unix.rb
# frozen_string_literal: false
[0] Fix | Delete
require 'socket'
[1] Fix | Delete
require_relative 'drb'
[2] Fix | Delete
require 'tmpdir'
[3] Fix | Delete
[4] Fix | Delete
raise(LoadError, "UNIXServer is required") unless defined?(UNIXServer)
[5] Fix | Delete
[6] Fix | Delete
module DRb
[7] Fix | Delete
[8] Fix | Delete
# Implements DRb over a UNIX socket
[9] Fix | Delete
#
[10] Fix | Delete
# DRb UNIX socket URIs look like <code>drbunix:<path>?<option></code>. The
[11] Fix | Delete
# option is optional.
[12] Fix | Delete
[13] Fix | Delete
class DRbUNIXSocket < DRbTCPSocket
[14] Fix | Delete
# :stopdoc:
[15] Fix | Delete
def self.parse_uri(uri)
[16] Fix | Delete
if /\Adrbunix:(.*?)(\?(.*))?\z/ =~ uri
[17] Fix | Delete
filename = $1
[18] Fix | Delete
option = $3
[19] Fix | Delete
[filename, option]
[20] Fix | Delete
else
[21] Fix | Delete
raise(DRbBadScheme, uri) unless uri.start_with?('drbunix:')
[22] Fix | Delete
raise(DRbBadURI, 'can\'t parse uri:' + uri)
[23] Fix | Delete
end
[24] Fix | Delete
end
[25] Fix | Delete
[26] Fix | Delete
def self.open(uri, config)
[27] Fix | Delete
filename, = parse_uri(uri)
[28] Fix | Delete
soc = UNIXSocket.open(filename)
[29] Fix | Delete
self.new(uri, soc, config)
[30] Fix | Delete
end
[31] Fix | Delete
[32] Fix | Delete
def self.open_server(uri, config)
[33] Fix | Delete
filename, = parse_uri(uri)
[34] Fix | Delete
if filename.size == 0
[35] Fix | Delete
soc = temp_server
[36] Fix | Delete
filename = soc.path
[37] Fix | Delete
uri = 'drbunix:' + soc.path
[38] Fix | Delete
else
[39] Fix | Delete
soc = UNIXServer.open(filename)
[40] Fix | Delete
end
[41] Fix | Delete
owner = config[:UNIXFileOwner]
[42] Fix | Delete
group = config[:UNIXFileGroup]
[43] Fix | Delete
if owner || group
[44] Fix | Delete
require 'etc'
[45] Fix | Delete
owner = Etc.getpwnam( owner ).uid if owner
[46] Fix | Delete
group = Etc.getgrnam( group ).gid if group
[47] Fix | Delete
File.chown owner, group, filename
[48] Fix | Delete
end
[49] Fix | Delete
mode = config[:UNIXFileMode]
[50] Fix | Delete
File.chmod(mode, filename) if mode
[51] Fix | Delete
[52] Fix | Delete
self.new(uri, soc, config, true)
[53] Fix | Delete
end
[54] Fix | Delete
[55] Fix | Delete
def self.uri_option(uri, config)
[56] Fix | Delete
filename, option = parse_uri(uri)
[57] Fix | Delete
return "drbunix:#{filename}", option
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
def initialize(uri, soc, config={}, server_mode = false)
[61] Fix | Delete
super(uri, soc, config)
[62] Fix | Delete
set_sockopt(@socket)
[63] Fix | Delete
@server_mode = server_mode
[64] Fix | Delete
@acl = nil
[65] Fix | Delete
end
[66] Fix | Delete
[67] Fix | Delete
# import from tempfile.rb
[68] Fix | Delete
Max_try = 10
[69] Fix | Delete
private
[70] Fix | Delete
def self.temp_server
[71] Fix | Delete
tmpdir = Dir::tmpdir
[72] Fix | Delete
n = 0
[73] Fix | Delete
while true
[74] Fix | Delete
begin
[75] Fix | Delete
tmpname = sprintf('%s/druby%d.%d', tmpdir, $$, n)
[76] Fix | Delete
lock = tmpname + '.lock'
[77] Fix | Delete
unless File.exist?(tmpname) or File.exist?(lock)
[78] Fix | Delete
Dir.mkdir(lock)
[79] Fix | Delete
break
[80] Fix | Delete
end
[81] Fix | Delete
rescue
[82] Fix | Delete
raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try
[83] Fix | Delete
#sleep(1)
[84] Fix | Delete
end
[85] Fix | Delete
n += 1
[86] Fix | Delete
end
[87] Fix | Delete
soc = UNIXServer.new(tmpname)
[88] Fix | Delete
Dir.rmdir(lock)
[89] Fix | Delete
soc
[90] Fix | Delete
end
[91] Fix | Delete
[92] Fix | Delete
public
[93] Fix | Delete
def close
[94] Fix | Delete
return unless @socket
[95] Fix | Delete
shutdown # DRbProtocol#shutdown
[96] Fix | Delete
path = @socket.path if @server_mode
[97] Fix | Delete
@socket.close
[98] Fix | Delete
File.unlink(path) if @server_mode
[99] Fix | Delete
@socket = nil
[100] Fix | Delete
close_shutdown_pipe
[101] Fix | Delete
end
[102] Fix | Delete
[103] Fix | Delete
def accept
[104] Fix | Delete
s = accept_or_shutdown
[105] Fix | Delete
return nil unless s
[106] Fix | Delete
self.class.new(nil, s, @config)
[107] Fix | Delete
end
[108] Fix | Delete
[109] Fix | Delete
def set_sockopt(soc)
[110] Fix | Delete
# no-op for now
[111] Fix | Delete
end
[112] Fix | Delete
end
[113] Fix | Delete
[114] Fix | Delete
DRbProtocol.add_protocol(DRbUNIXSocket)
[115] Fix | Delete
# :startdoc:
[116] Fix | Delete
end
[117] Fix | Delete
[118] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function