Andreas Schwab wrote:
Jie Zhang <[EMAIL PROTECTED]> writes:

Andreas Schwab wrote:
Jie Zhang <[EMAIL PROTECTED]> writes:

@@ -261,7 +262,11 @@ 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 remote_envs "$remote_envs $envvar=$remote_env($envvar)"
That needs to do proper quoting to protect shell meta characters.

Thanks for pointing out this. A new patch is attached. Is the quoting right?

That won't protect all meta characters.  Inside double quotes the dollar
sign, backslash and backquote are still special.

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

Thanks,
Jie
diff --git a/lib/rsh.exp b/lib/rsh.exp
index 1a207a8..94122e8 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,11 @@ 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 remote_envs "$remote_envs $envvar='$remote_env($envvar)'"
+    }
+    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