Skip to content

Commit

Permalink
fixed stale status bug and better error handling
Browse files Browse the repository at this point in the history
solved duplicate event processing
  • Loading branch information
Patrick Schleizer committed Apr 22, 2016
1 parent ddd3d80 commit 0046d21
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
24 changes: 15 additions & 9 deletions usr/lib/python2.7/dist-packages/sdwdate_gui/sdwdate_gui.py
Expand Up @@ -83,8 +83,7 @@ def __init__(self, parent=None):
if os.path.exists(self.status_path):
## Read status when GUI is loaded.
self.status_changed()
self.watcher = watcher([self.status_path])
self.watcher.fileChanged.connect(self.status_changed)
self.watch_file()
else:
self.setIcon(QtGui.QIcon('/usr/share/icons/oxygen/16x16/status/dialog-error.png'))
error_msg = '''<b>sdwdate is not running</b><br>
Expand Down Expand Up @@ -141,12 +140,13 @@ def update_tip(self):
self.show_message('update')

def status_changed(self):
## Prevent race condition.
## Likely due to the issue below.
time.sleep(0.01)

with open(self.status_path, 'rb') as f:
status = pickle.load(f)
## When the file is quickly rewritten by another operation, reading
## would fail. TOCTOU
try:
with open(self.status_path, 'rb') as f:
status = pickle.load(f)
except:
return

self.setIcon(QtGui.QIcon(status['icon']))
## Remove double quotes from message as they would be interpreted as
Expand All @@ -164,10 +164,16 @@ def status_changed(self):
self.update.update_tip.emit()
self.previous_message = self.message

def watch_folder(self):
def watch_file(self):
self.watcher = watcher([self.status_path])
self.watcher.fileChanged.connect(self.status_changed)

def watch_folder(self):
if os.path.exists(self.status_path):
self.watcher_2.removePath(self.path)
self.status_changed()
self.watch_file()


def show_log():
show_konsole = ('konsole --hold --hide-menubar --hide-tabbar ' +
Expand Down
33 changes: 33 additions & 0 deletions usr/share/sdwdate-gui/unit-test/fuzzer
@@ -0,0 +1,33 @@
#!/bin/bash

set -x
set -e

counter=0

while true ; do
for icon in /usr/share/icons/sdwdate-gui/* ; do
msg="$(cat /proc/sys/kernel/random/uuid)"

echo "(dp0
S'message'
p1
S\"$msg\"
p2
sS'icon'
p3
S'$icon'
p4
s." > /var/run/sdwdate/status

counter=$(( counter + 1 ))
if [ "$counter" -ge 1000 ]; then
do_break=true
fi

#sleep 1
done
if [ "$do_break" = "true" ]; then
break
fi
done

0 comments on commit 0046d21

Please sign in to comment.