[PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp

Bin Meng posted 51 patches 3 years, 5 months ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Thomas Huth <thuth@redhat.com>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Beraldo Leal <bleal@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Greg Kurz <groug@kaod.org>, Christian Schoenebeck <qemu_oss@crudebyte.com>, "Cédric Le Goater" <clg@kaod.org>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Gerd Hoffmann <kraxel@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Michael Roth <michael.roth@amd.com>, Konstantin Kostiuk <kkostiuk@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Juan Quintela <quintela@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, John Snow <jsnow@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Andrew Jeffery <andrew@aj.id.au>, Joel Stanley <joel@jms.id.au>, "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <ani@anisinha.ca>, Alexander Bulekov <alxndr@bu.edu>, Bandan Das <bsd@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, Havard Skinnemoen <hskinnemoen@google.com>, Tyrone Ting <kfting@nuvoton.com>, Markus Armbruster <armbru@redhat.com>, Coiby Xu <Coiby.Xu@gmail.com>, Jason Wang <jasowang@redhat.com>, Fam Zheng <fam@euphon.net>
There is a newer version of this series
[PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
Posted by Bin Meng 3 years, 5 months ago
From: Bin Meng <bin.meng@windriver.com>

Use g_get_tmp_dir() to get the directory to use for temporary files.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 semihosting/arm-compat-semi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index e741674238..d5e66cc298 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -503,7 +503,8 @@ void do_common_semihosting(CPUState *cs)
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
-        len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff);
+        len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
+                       getpid(), (int)arg1 & 0xff);
         if (len < 0) {
             common_semi_set_ret(cs, -1);
             break;
-- 
2.34.1
Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
Posted by Marc-André Lureau 3 years, 5 months ago
Hi

On Wed, Aug 24, 2022 at 1:54 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Use g_get_tmp_dir() to get the directory to use for temporary files.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  semihosting/arm-compat-semi.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
> index e741674238..d5e66cc298 100644
> --- a/semihosting/arm-compat-semi.c
> +++ b/semihosting/arm-compat-semi.c
> @@ -503,7 +503,8 @@ void do_common_semihosting(CPUState *cs)
>          GET_ARG(0);
>          GET_ARG(1);
>          GET_ARG(2);
> -        len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 &
> 0xff);
> +        len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
> +                       getpid(), (int)arg1 & 0xff);
>

This is most likely wrong. I am not familiar with semihosting, but I
believe we are implementing tmpnam(), it should return a POSIX filename.


>          if (len < 0) {
>              common_semi_set_ret(cs, -1);
>              break;
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau
Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
Posted by Bin Meng 3 years, 5 months ago
On Wed, Aug 31, 2022 at 8:59 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 1:54 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> Use g_get_tmp_dir() to get the directory to use for temporary files.
>>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>>  semihosting/arm-compat-semi.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
>> index e741674238..d5e66cc298 100644
>> --- a/semihosting/arm-compat-semi.c
>> +++ b/semihosting/arm-compat-semi.c
>> @@ -503,7 +503,8 @@ void do_common_semihosting(CPUState *cs)
>>          GET_ARG(0);
>>          GET_ARG(1);
>>          GET_ARG(2);
>> -        len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff);
>> +        len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
>> +                       getpid(), (int)arg1 & 0xff);
>
>
> This is most likely wrong. I am not familiar with semihosting, but I believe we are implementing tmpnam(), it should return a POSIX filename.

Replacing /tmp with g_get_tmp_dir() is not wrong, correct?

I checked the semihosting spec, it does not mention the file name
should be a POSIX compliant path.
https://developer.arm.com/documentation/dui0058/d/semihosting/semihosting-swis/sys-tmpnam--0x0d-

Certainly this needs a semihosting expert to take a look.

>
>>
>>          if (len < 0) {
>>              common_semi_set_ret(cs, -1);
>>              break;
>> --

Regards,
Bin
Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
Posted by Richard Henderson 3 years, 5 months ago
On 9/1/22 08:11, Bin Meng wrote:
>>> -        len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff);
>>> +        len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
>>> +                       getpid(), (int)arg1 & 0xff);
>>
>>
>> This is most likely wrong. I am not familiar with semihosting, but I believe we are implementing tmpnam(), it should return a POSIX filename.
> 
> Replacing /tmp with g_get_tmp_dir() is not wrong, correct?

The replacement is correct.


r~