Append username to filenames to avoid collisions

Previously webplot always just used '/tmp/webplot.png' and
'/tmp/webplot.dat' as the locations where it saved screenshots and
event logs.  This works fine as long as webplot is always run as the
same user.  When we have multiple people running tests on the same
machine, sometimes a webplot.png will be left in /tmp but without
global write permissions.  When this happens other users can't
use webplot to save screenshots until the other user deletes their
file.

This CL adds in a snippet of code to append the current user's
username to the end of the file to prevent these collisions.  Now
instead, it'll use filenames of the form '/tmp/webplot_USERNAME.png'
and in my case, '/tmp/webplot_charliemooney.png'.  This should
prevent two users from interfereing with one another.

BUG=chromium:493355
TEST=I made some unwritable webplot.png's and made sure I could
still use webplot successfully.  It worked, so it stands to reason
this will also apply to multiple users as well.

Change-Id: Ib3bc205fbbaf7cdb2eb0e68177ecff807931278d
Signed-off-by: Charlie Mooney <charliemooney@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/284623
Reviewed-by: Shyh-In Hwang <josephsih@chromium.org>
diff --git a/webplot/webplot.py b/webplot/webplot.py
index f5e2dc4..294d091 100755
--- a/webplot/webplot.py
+++ b/webplot/webplot.py
@@ -11,6 +11,7 @@
 import json
 import logging
 import os
+import pwd
 import re
 import subprocess
 import time
@@ -30,8 +31,9 @@
 state = None
 
 # The touch events are saved in this file as default.
-SAVED_FILE = '/tmp/webplot.dat'
-SAVED_IMAGE = '/tmp/webplot.png'
+current_username = pwd.getpwuid(os.getuid()).pw_name
+SAVED_FILE = '/tmp/webplot_%s.dat' % current_username
+SAVED_IMAGE = '/tmp/webplot_%s.png' % current_username
 
 
 def SimpleSystem(cmd):
@@ -451,9 +453,9 @@
     """
     state.QuitAndShutdown()
 
-  def Save(self, wait_for_image=False):
-    """Notify clients to save the screen, then wait for the file to appear
-    on disk and return it.
+  def Save(self):
+    """Notify clients to save the screen, then wait for the image file to be
+    created, and return the image.
     """
     global image_lock
     global image_string