summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2006-06-24 11:05:33 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2006-06-24 11:05:33 +0000
commitca4d4a0051aba1852e73d11033d76073b3b404ef (patch)
treea41a2622cd3bb3907a3f3e9ece864f0e1bf069b8
parentd7d22932f9a4c427a464ca0cea3bb45952ffeb04 (diff)
Retry gathering data
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@147 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-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