Moved server.utils.sh_escape function to client.common_lib.utils
(there's nothing server specific about it) and updated users. Fixed what
it seems an invalid reference bug in utils.pid_is_alive() calling a
function in the same module.

Signed-off-by: Mihai Rusu <dizzy@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3394 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 68a2247..b7ac4f2 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -539,7 +539,7 @@
     pid can be integer, or text of integer.
     """
     try:
-        stat = utils.read_one_line('/proc/%s/stat' % pid)  # pid exists
+        stat = read_one_line('/proc/%s/stat' % pid)  # pid exists
         return stat.split()[2] != 'Z'  # and is not in Zombie state
     except Exception:
         return False  # process no longer exists at all
@@ -1010,3 +1010,25 @@
     path_list[:0] = ['..'] * (len(ref_list) - i)
 
     return os.path.join(*path_list)
+
+
+def sh_escape(command):
+    """
+    Escape special characters from a command so that it can be passed
+    as a double quoted (" ") string in a (ba)sh command.
+
+    Args:
+            command: the command string to escape.
+
+    Returns:
+            The escaped command string. The required englobing double
+            quotes are NOT added and so should be added at some point by
+            the caller.
+
+    See also: http://www.tldp.org/LDP/abs/html/escapingsection.html
+    """
+    command = command.replace("\\", "\\\\")
+    command = command.replace("$", r'\$')
+    command = command.replace('"', r'\"')
+    command = command.replace('`', r'\`')
+    return command