Jie Zhang | 16 Jul 18:51

Set environment variable on remote target

libmudflap tests set a environment MUDFLAP_OPTIONS=-viol-segv before 
testing such that violations are promoted to SIGSEGV signals in testing. 
Otherwise, the exit value would be 0 even the test has violations. 
libmudflap testsuite depends on the exit value of tests to decide if the 
test PASS or FAIL. Setting MUDFLAP_OPTIONS is done in DejaGNU by

   setenv MUDFLAP_OPTIONS "-viol-segv"

which works fine on native testing. But when doing remote cross testing, 
setenv does not help. I cannot find existing mechanism in DejaGNU. So I 
want to use a global array like remote_env. If remote cross testing, add 
the environment variable in this array. Then set the environment 
variables according to the array when remote execute test case. I wrote 
a draft patch show what I means, which is attached. In mudflap 
testsuite, replace each setenv with

         if { ![is_remote target] } {
             setenv MUDFLAP_OPTIONS "-viol-segv"
         } else {
             remote_setenv MUDFLAP_OPTIONS "-viol-segv"
         }

Is it the right way to do this, or is there existing method I can use 
but I missed?

Thanks,

Jie
(Continue reading)

Andreas Schwab | 16 Jul 19:22

Re: Set environment variable on remote target

Jie Zhang <jie.zhang <at> analog.com> 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.

Andreas.

--

-- 
Andreas Schwab, SuSE Labs, schwab <at> suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

Jie Zhang | 17 Jul 06:26

Re: Set environment variable on remote target

Andreas Schwab wrote:
> Jie Zhang <jie.zhang <at> analog.com> 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?

I also dropped remote_getenv from the new patch, since I just realized 
it cannot get remote environment variable indeed. remote_unsetenv was 
dropped for the same reason.

The patch for gcc is also attached for review.

Jie

diff --git a/lib/rsh.exp b/lib/rsh.exp
index 1a207a8..13be541 100644
--- a/lib/rsh.exp
(Continue reading)

Andreas Schwab | 17 Jul 10:00

Re: Set environment variable on remote target

Jie Zhang <jie.zhang <at> analog.com> writes:

> Andreas Schwab wrote:
>> Jie Zhang <jie.zhang <at> analog.com> 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.

Andreas.

--

-- 
Andreas Schwab, SuSE Labs, schwab <at> suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

(Continue reading)

Jie Zhang | 17 Jul 13:23

Re: Set environment variable on remote target

Andreas Schwab wrote:
> Jie Zhang <jie.zhang <at> analog.com> writes:
> 
>> Andreas Schwab wrote:
>>> Jie Zhang <jie.zhang <at> analog.com> 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
(Continue reading)

Andreas Schwab | 17 Jul 14:09

Re: Set environment variable on remote target

Jie Zhang <jie.zhang <at> analog.com> writes:

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

This will break if the value can contain single quotes.

Andreas.

--

-- 
Andreas Schwab, SuSE Labs, schwab <at> suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

Jie Zhang | 18 Jul 12:45

Re: Set environment variable on remote target

Andreas Schwab wrote:
> Jie Zhang <jie.zhang <at> analog.com> 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
(Continue reading)


Gmane