From: Tom de Vries <tdevries@suse.de>
To: Guinevere Larsen <blarsen@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v3] gdb/testsuite: XFAIL some gdb.base/fileio.exp
Date: Wed, 4 Oct 2023 17:33:05 +0200 [thread overview]
Message-ID: <ba066dfd-04b8-4cd2-b8da-a105ec9feda1@suse.de> (raw)
In-Reply-To: <20231004140247.16091-2-blarsen@redhat.com>
On 10/4/23 16:02, Guinevere Larsen via Gdb-patches wrote:
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index de22da8d8a8..5b90b8af3b8 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -9981,5 +9981,25 @@ gdb_caching_proc have_system_header { file } {
> return [gdb_can_simple_compile have_system_header_$name $src object]
> }
>
> +# Return 1 if the test is being run as root, 0 otherwise.
> +
> +gdb_caching_proc root_user {} {
> + # ID outputs to stdout, we have to use exec to capture it here.
> + set user [remote_exec target id]
> +
> + regexp -all "(-?\[0-9\]+).*" $user user ret_val
I can see that this works, but it's a bit unusual (and hard to parse for
me) to use regexp to pick apart a list. The usual way is using lindex.
> +
> + # If ret_val is not 0, we couldn't run `id` on the target for some
> + # reason. Return that we are not root, so problems are easier to
> + # spot.
> + if {[expr $ret_val != 0]} {
The expr is not necessary here.
> + return 0
> + }
> +
> + regexp -all ".*uid=(\[0-9\]+).*" $user user uid
> +
Also, the 'user' variable is used as dummy, better make that explicit.
So, please do:
...
set res [remote_exec target id]
set ret_val [lindex $res 0]
set output [lindex $res 1]
# If ret_val is not 0, we couldn't run `id` on the target for some
# reason. Return that we are not root, so problems are easier to
# spot.
if { $ret_val != 0 } {
return 0
}
regexp -all ".*uid=(\[0-9\]+).*" $output dummy uid
return [expr $uid == 0]
...
Approved with that change.
Approved-By: Tom de Vries <tdevries@suse.de>
Thanks,
- Tom
> + return [expr $uid == 0]
> +}
> +
> # Always load compatibility stuff.
> load_lib future.exp
next prev parent reply other threads:[~2023-10-04 15:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 10:21 [PATCH] " Guinevere Larsen
2023-08-11 13:19 ` Lancelot SIX
2023-08-11 14:26 ` Guinevere Larsen
2023-08-14 10:24 ` [PATCH v2] " Guinevere Larsen
2023-09-14 13:12 ` [PING][PATCH " Guinevere Larsen
2023-09-26 13:21 ` [PATCH " Tom de Vries
2023-10-04 14:02 ` [PATCH v3] " Guinevere Larsen
2023-10-04 15:33 ` Tom de Vries [this message]
2023-10-04 15:47 ` Guinevere Larsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ba066dfd-04b8-4cd2-b8da-a105ec9feda1@suse.de \
--to=tdevries@suse.de \
--cc=blarsen@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).