summaryrefslogtreecommitdiff
path: root/munin/owfs_temperature_
diff options
context:
space:
mode:
Diffstat (limited to 'munin/owfs_temperature_')
-rwxr-xr-xmunin/owfs_temperature_70
1 files changed, 53 insertions, 17 deletions
diff --git a/munin/owfs_temperature_ b/munin/owfs_temperature_
index f797b21..8713990 100755
--- a/munin/owfs_temperature_
+++ b/munin/owfs_temperature_
@@ -74,32 +74,68 @@ def config
puts "#{n}.label #{label}"
end
+
+def runcmd(command, input)
+ rdin , wrin = IO.pipe
+ rdout, wrout = IO.pipe
+ rderr, wrerr = IO.pipe
+
+ pid = fork
+ unless pid
+ # child
+ wrin.close
+ rdout.close
+ rderr.close
+ STDIN.reopen rdin
+ STDOUT.reopen wrout
+ STDERR.reopen wrerr
+ exec(*command)
+ throw("fell through exec(). WTF.")
+ end
+ rdin.close
+ wrout.close
+ wrerr.close
+
+ out = []
+ err = []
+ tin = Thread.new { wrin.print input; wrin.close }
+ tout = Thread.new { out = rdout.readlines }
+ terr = Thread.new { err = rderr.readlines }
+ tin.join
+ tout.join
+ terr.join
+ Process.wait pid
+
+ exitstatus = $?.exitstatus
+
+ [exitstatus, out, err]
+end
+
def report
device = query_device
Process.gid=0
Process.egid=0
- temp = nil
# fuse does weird checks. this fails:
# File.new($owfs_path+'/'+device+'/temperature', "r") ---> FAILS: in `initialize': Permission denied - /var/lib/owfs/10.D234EE000800/temperature (Errno::EACCES)
- IO.popen("-") do |f|
- unless f # child
- begin
- exec('cat', $owfs_path+'/'+device+'/temperature')
- rescue => e
- puts "Cannot exec cat: "+e.message
- exit 1
- end
- end
- temp = f.readlines
- end
- if $? != 0
- STDERR.puts "Child exited with non-zero exit code(%d): %s"%[$? >> 8, temp.join('')]
- else
- n = normalize_sensor device
- puts "#{n}.value #{temp.join('')}"
+ # Sometimes the directory in OWFS does not exist, and cat will say
+ # cat: /var/lib/owfs/10.D234EE000800/temperature: Invalid argument
+ # so retry it a few times, since ls'ing the directory helps on the command line at least
+ 5.times do
+ exitstatus, out, err = runcmd(['cat', $owfs_path+'/'+device+'/temperature'], '')
+ if exitstatus != 0
+ STDERR.puts "Child exited with non-zero exit code(%d): %s"%[exitstatus >> 8, err.join]
+ runcmd(['ls', $owfs_path])
+ sleep 1
+ else
+ STDERR.puts "command succeeded but returned something on stderr: #{err.join}" if err.size > 0
+ n = normalize_sensor device
+ puts "#{n}.value #{out.join}"
+ return
+ end
end
+ STDERR.puts "Could not get data."
end