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 +1 -1
- data/spec/lib/pidlock_spec.rb +3 -3
- metadata +1 -1
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,
|
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))
|
data/spec/lib/pidlock_spec.rb
CHANGED
@@ -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',
|
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",
|
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',
|
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
|