webplot: handle IOError properly and quit only once
This patch handles the IOError exceptions. The exception may occur
when webplot tries to open a file owned by root which would fail
because an ordinary user does not have the permission to overwrite
those files. In that condition, the server notifies the clients to
quit and terminates itself properly.
Note that the event data file or the image file may be owned by root
if a user ran webplot as root previously. In that case, print out the
error message, tell the user to remove the files owned by root, and
restart webplot again.
This patch also adds quit flags in both the server and the client
to prevent from sending the quit message multiple times.
BUG=chromium:476833
TEST=Launch a webplot server on a chromebook
$ webplot
Create /tmp/webplot.dat and /tmp/webplot.png with vi as root, and
write a random message in the files.
Observe that the program would terminate properly and print out
the following messages about how to handle the situation.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[Errno 13] Permission denied: '/tmp/webplot.dat'
It is likely that /tmp/webplot.dat is owned by root.
Please remove the file and then run webplot again.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Change-Id: If365400f8cf38f7a5876866b2bb4028334cfea97
Reviewed-on: https://chromium-review.googlesource.com/265523
Reviewed-by: Charlie Mooney <charliemooney@chromium.org>
Commit-Queue: Shyh-In Hwang <josephsih@chromium.org>
Tested-by: Shyh-In Hwang <josephsih@chromium.org>
diff --git a/webplot/webplot.js b/webplot/webplot.js
index 7c352a0..b1c6439 100644
--- a/webplot/webplot.js
+++ b/webplot/webplot.js
@@ -102,7 +102,8 @@
this.clickDown = false;
this.pressureMode = true;
this.pointRadius = 2;
- this.saved_file = '/tmp/webplot.dat';
+ this.saved_events = '/tmp/webplot.dat';
+ this.saved_image = '/tmp/webplot.png';
}
@@ -274,6 +275,9 @@
}
+Webplot.quitFlag = false;
+
+
/**
* An handler for onresize event to update the canvas dimensions.
*/
@@ -296,15 +300,19 @@
// Capture the image before clearing the canvas and send it to the server,
// and notify the server that this client quits.
- window.ws.send('quit');
+ if (!Webplot.quitFlag) {
+ Webplot.quitFlag = true;
+ window.ws.send('quit');
- clear(false);
- if (closed_by_server) {
- webplot.fillText('The python server has quit.', startX, startY, font);
- startY += 100;
+ clear(false);
+ if (closed_by_server) {
+ webplot.fillText('The python server has quit.', startX, startY, font);
+ }
+ webplot.fillText('Events are saved in "' + webplot.saved_events + '"',
+ startX, startY + 100, font);
+ webplot.fillText('The image is saved in "' + webplot.saved_image + '"',
+ startX, startY + 200, font);
}
- webplot.fillText('Events are saved in "' + webplot.saved_file + '"',
- startX, startY, font);
}
function save() {