~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/drb/unix.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
  class DRbUNIXSocket < DRbTCPSocket
10
10
    def self.parse_uri(uri)
11
11
      if /^drbunix:(.*?)(\?(.*))?$/ =~ uri
12
 
        filename = $1
13
 
        option = $3
14
 
        [filename, option]
 
12
        filename = $1
 
13
        option = $3
 
14
        [filename, option]
15
15
      else
16
 
        raise(DRbBadScheme, uri) unless uri =~ /^drbunix:/
17
 
        raise(DRbBadURI, 'can\'t parse uri:' + uri)
 
16
        raise(DRbBadScheme, uri) unless uri =~ /^drbunix:/
 
17
        raise(DRbBadURI, 'can\'t parse uri:' + uri)
18
18
      end
19
19
    end
20
20
 
21
21
    def self.open(uri, config)
22
 
      filename, option = parse_uri(uri)
 
22
      filename, = parse_uri(uri)
23
23
      filename.untaint
24
24
      soc = UNIXSocket.open(filename)
25
25
      self.new(uri, soc, config)
26
26
    end
27
27
 
28
28
    def self.open_server(uri, config)
29
 
      filename, option = parse_uri(uri)
 
29
      filename, = parse_uri(uri)
30
30
      if filename.size == 0
31
 
        soc = temp_server
 
31
        soc = temp_server
32
32
        filename = soc.path
33
 
        uri = 'drbunix:' + soc.path
 
33
        uri = 'drbunix:' + soc.path
34
34
      else
35
 
        soc = UNIXServer.open(filename)
 
35
        soc = UNIXServer.open(filename)
36
36
      end
37
37
      owner = config[:UNIXFileOwner]
38
38
      group = config[:UNIXFileGroup]
67
67
      tmpdir = Dir::tmpdir
68
68
      n = 0
69
69
      while true
70
 
        begin
71
 
          tmpname = sprintf('%s/druby%d.%d', tmpdir, $$, n)
72
 
          lock = tmpname + '.lock'
73
 
          unless File.exist?(tmpname) or File.exist?(lock)
74
 
            Dir.mkdir(lock)
75
 
            break
76
 
          end
77
 
        rescue
78
 
          raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try
79
 
          #sleep(1)
80
 
        end
81
 
        n += 1
 
70
        begin
 
71
          tmpname = sprintf('%s/druby%d.%d', tmpdir, $$, n)
 
72
          lock = tmpname + '.lock'
 
73
          unless File.exist?(tmpname) or File.exist?(lock)
 
74
            Dir.mkdir(lock)
 
75
            break
 
76
          end
 
77
        rescue
 
78
          raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try
 
79
          #sleep(1)
 
80
        end
 
81
        n += 1
82
82
      end
83
83
      soc = UNIXServer.new(tmpname)
84
84
      Dir.rmdir(lock)