summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAntonio Terceiro <terceiro@softwarelivre.org>2015-05-03 20:13:29 -0300
committerAntonio Terceiro <terceiro@softwarelivre.org>2015-05-03 20:20:01 -0300
commitc1e5c1c00bd996140d2a74ee4b5e50182b846bc6 (patch)
treeab46ddb807e385432a0b145a3b3a6e9c1ffd3761 /lib
parent7ce801979c3a17622dc74edf67cbb0d001d7ca02 (diff)
downloadfeed2imap-c1e5c1c00bd996140d2a74ee4b5e50182b846bc6.tar.gz
feed2imap-c1e5c1c00bd996140d2a74ee4b5e50182b846bc6.tar.bz2
feed2imap-c1e5c1c00bd996140d2a74ee4b5e50182b846bc6.zip
Fix usage of filters
- avoid accessing $? unless it is actually available - when calling a filter, make sure to release the mutex even if there is an exception during the filter handling. The long term solution is to drastically reorganize concurrency code.
Diffstat (limited to 'lib')
-rw-r--r--lib/feed2imap/feed2imap.rb35
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb
index 64663c6..b84b6b6 100644
--- a/lib/feed2imap/feed2imap.rb
+++ b/lib/feed2imap/feed2imap.rb
@@ -130,7 +130,7 @@ class Feed2Imap
# thread-safe, and we need to get the right exitcode
mutex.lock
s = %x{#{feed.execurl}}
- if $?.exitstatus != 0
+ if $? && $?.exitstatus != 0
@logger.warn("Command for #{feed.name} exited with status #{$?.exitstatus} !")
end
mutex.unlock
@@ -143,22 +143,25 @@ class Feed2Imap
# thread-safe, and we need to get the right exitcode.
mutex.lock
# hack hack hack, avoid buffering problems
- stdin, stdout, stderr = Open3::popen3(feed.filter)
- inth = Thread::new do
- stdin.puts s
- stdin.close
+ begin
+ stdin, stdout, stderr = Open3::popen3(feed.filter)
+ inth = Thread::new do
+ stdin.puts s
+ stdin.close
+ end
+ output = nil
+ outh = Thread::new do
+ output = stdout.read
+ end
+ inth.join
+ outh.join
+ s = output
+ if $? && $?.exitstatus != 0
+ @logger.warn("Filter command for #{feed.name} exited with status #{$?.exitstatus}. Output might be corrupted !")
+ end
+ ensure
+ mutex.unlock
end
- output = nil
- outh = Thread::new do
- output = stdout.read
- end
- inth.join
- outh.join
- s = output
- if $?.exitstatus != 0
- @logger.warn("Filter command for #{feed.name} exited with status #{$?.exitstatus}. Output might be corrupted !")
- end
- mutex.unlock
end
if Time::now - fetch_start > F2I_WARNFETCHTIME
@logger.info("Fetching feed #{feed.name} took #{(Time::now - fetch_start).to_i}s")