pidlock 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pidlock.rb CHANGED
@@ -21,7 +21,7 @@ class Pidlock
21
21
  unless (File.writable?(File.dirname(@filename)))
22
22
  @filename = File.join('/', 'tmp', @name)
23
23
  end
24
- @file = File.open(@filename, 'r+')
24
+ @file = File.open(@filename, File::RDWR|File::CREAT, 0600)
25
25
  if (old_pid = @file.gets)
26
26
  if (old_process = Sys::ProcTable.ps(old_pid.chomp.to_i))
27
27
  raise ProcessRunning if old_process.comm == File.basename(@name, File.extname(@name))
@@ -9,7 +9,7 @@ describe Pidlock do
9
9
  @file.stub(:flock => 0)
10
10
  @file.stub(:flush)
11
11
  @file.stub(:gets)
12
- File.stub(:open).with('/var/run/my.pid', 'r+').and_return(@file)
12
+ File.stub(:open).with('/var/run/my.pid', File::RDWR|File::CREAT, 0600).and_return(@file)
13
13
  File.stub(:writable?).with('/var/run').and_return(true)
14
14
  Logger.stub!(:new => logger)
15
15
  end
@@ -26,7 +26,7 @@ describe Pidlock do
26
26
  Pidlock.new('my.pid').lock
27
27
  end
28
28
  it "uses a directory under /var/run if given" do
29
- File.should_receive(:open).with("/var/run/my/my.pid", 'r+').and_return(@file)
29
+ File.should_receive(:open).with("/var/run/my/my.pid", File::RDWR|File::CREAT, 0600).and_return(@file)
30
30
  File.should_receive(:writable?).with("/var/run/my").and_return(true)
31
31
  @file.should_receive(:write).with(666)
32
32
  Pidlock.new('my/my.pid').lock
@@ -61,7 +61,7 @@ describe Pidlock do
61
61
 
62
62
  it "uses /tmp if /var/run is not writeable" do
63
63
  File.should_receive(:writable?).with('/var/run').and_return(false)
64
- File.should_receive(:open).with('/tmp/my.pid', 'r+').and_return(@file)
64
+ File.should_receive(:open).with('/tmp/my.pid', File::RDWR|File::CREAT, 0600).and_return(@file)
65
65
  Pidlock.new('my.pid').lock
66
66
  end
67
67
  it "warns but continue if the file exists but the process name does not" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pidlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: