dejagnu
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set environment variable on remote target


From: Jie Zhang
Subject: Re: Set environment variable on remote target
Date: Fri, 18 Jul 2008 18:45:08 +0800
User-agent: Mozilla-Thunderbird 2.0.0.14 (X11/20080509)

Andreas Schwab wrote:
Jie Zhang <address@hidden> writes:

So we have to use single quotes. The updated patch is attached.

This will break if the value can contain single quotes.

How about using double quotes but escaping ", \, $, and ` using backslash? The patch is attached.


Jie
diff --git a/lib/rsh.exp b/lib/rsh.exp
index 1a207a8..d846887 100644
--- a/lib/rsh.exp
+++ b/lib/rsh.exp
@@ -225,6 +225,7 @@ proc rsh_upload {desthost srcfile destfile} {
 #
 proc rsh_exec { boardname program pargs inp outp } {
     global timeout
+    global remote_env
 
     verbose "Executing $boardname:$program $pargs < $inp"
 
@@ -261,7 +262,14 @@ proc rsh_exec { boardname program pargs inp outp } {
        set inp "/dev/null"
     }
 
-    set ret [local_exec "$RSH $rsh_useropts $hostname sh -c '$program $pargs 
\\; echo XYZ\\\${?}ZYX'" $inp $outp $timeout]
+    set remote_envs ""
+    foreach envvar [array names remote_env] {
+       set tmp_env "$remote_env($envvar)"
+       # Escape ", \, $, and `, which cannot be protected by double quotes.
+       regsub -all "(\[\"\\\\$`])" $tmp_env "\\\\\\1" tmp_env
+       set remote_envs "$remote_envs $envvar=\"$tmp_env\""
+    }
+    set ret [local_exec "$RSH $rsh_useropts $hostname sh -c '$remote_envs 
$program $pargs \\; echo XYZ\\\${?}ZYX'" $inp $outp $timeout]
     set status [lindex $ret 0]
     set output [lindex $ret 1]
 
diff --git a/lib/utils.exp b/lib/utils.exp
index 6c9ff98..6325dd8 100644
--- a/lib/utils.exp
+++ b/lib/utils.exp
@@ -414,3 +414,12 @@ proc getenv { var } {
     }
 }
 
+#
+# Set an environment variable remotely
+#
+proc remote_setenv { var val } {
+    global remote_env
+
+    set remote_env($var) $val
+}
+

reply via email to

[Prev in Thread] Current Thread [Next in Thread]