openembedded-core.lists.openembedded.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sstate: fix touching files inside pseudo
@ 2021-10-18 18:47 Jose Quaresma
  2021-10-19 19:37 ` [OE-core] " Peter Kjellerstedt
  0 siblings, 1 reply; 3+ messages in thread
From: Jose Quaresma @ 2021-10-18 18:47 UTC (permalink / raw)
  To: openembedded-core; +Cc: Jose Quaresma

running the 'id' command inside the sstate_create_package
function shows that this funcion run inside the pseudo:

 uid=0(root) gid=0(root) groups=0(root)

The check for touch files [ ! -w ${SSTATE_PKG} ]
will always return true and the touch can fail
when the real user don't have permission or
in readonly filesystem.

As the documentation refers, the file test operator "-w"
check if the file has write permission (for the user running the test).

We can avoid this test running the touch and mask any return errors
that we have.

Signed-off-by: Jose Quaresma <quaresma.jose@gmail.com>
---
 meta/classes/sstate.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/meta/classes/sstate.bbclass b/meta/classes/sstate.bbclass
index 7f034d746a..d4555150c4 100644
--- a/meta/classes/sstate.bbclass
+++ b/meta/classes/sstate.bbclass
@@ -830,7 +830,7 @@ sstate_task_postfunc[dirs] = "${WORKDIR}"
 sstate_create_package () {
 	# Exit early if it already exists
 	if [ -e ${SSTATE_PKG} ]; then
-		[ ! -w ${SSTATE_PKG} ] || touch ${SSTATE_PKG}
+		touch ${SSTATE_PKG} || true
 		return
 	fi
 
@@ -865,7 +865,7 @@ sstate_create_package () {
 	else
 		rm $TFILE
 	fi
-	[ ! -w ${SSTATE_PKG} ] || touch ${SSTATE_PKG}
+	touch ${SSTATE_PKG} || true
 }
 
 python sstate_sign_package () {
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [OE-core] [PATCH] sstate: fix touching files inside pseudo
  2021-10-18 18:47 [PATCH] sstate: fix touching files inside pseudo Jose Quaresma
@ 2021-10-19 19:37 ` Peter Kjellerstedt
  2021-10-20 11:13   ` Jose Quaresma
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Kjellerstedt @ 2021-10-19 19:37 UTC (permalink / raw)
  To: Jose Quaresma, openembedded-core

> -----Original Message-----
> From: openembedded-core@lists.openembedded.org <openembedded-
> core@lists.openembedded.org> On Behalf Of Jose Quaresma
> Sent: den 18 oktober 2021 20:47
> To: openembedded-core@lists.openembedded.org
> Cc: Jose Quaresma <quaresma.jose@gmail.com>
> Subject: [OE-core] [PATCH] sstate: fix touching files inside pseudo
> 
> running the 'id' command inside the sstate_create_package
> function shows that this funcion run inside the pseudo:
> 
>  uid=0(root) gid=0(root) groups=0(root)
> 
> The check for touch files [ ! -w ${SSTATE_PKG} ]
> will always return true and the touch can fail
> when the real user don't have permission or
> in readonly filesystem.
> 
> As the documentation refers, the file test operator "-w"
> check if the file has write permission (for the user running the test).
> 
> We can avoid this test running the touch and mask any return errors
> that we have.
> 
> Signed-off-by: Jose Quaresma <quaresma.jose@gmail.com>
> ---
>  meta/classes/sstate.bbclass | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/sstate.bbclass b/meta/classes/sstate.bbclass
> index 7f034d746a..d4555150c4 100644
> --- a/meta/classes/sstate.bbclass
> +++ b/meta/classes/sstate.bbclass
> @@ -830,7 +830,7 @@ sstate_task_postfunc[dirs] = "${WORKDIR}"
>  sstate_create_package () {
>  	# Exit early if it already exists
>  	if [ -e ${SSTATE_PKG} ]; then
> -		[ ! -w ${SSTATE_PKG} ] || touch ${SSTATE_PKG}
> +		touch ${SSTATE_PKG} || true

You should pass stderr to /dev/null to avoid messages in the log 
if/when touch fails, i.e.:

		touch ${SSTATE_PKG} 2>/dev/null || :

>  		return
>  	fi
> 
> @@ -865,7 +865,7 @@ sstate_create_package () {
>  	else
>  		rm $TFILE
>  	fi
> -	[ ! -w ${SSTATE_PKG} ] || touch ${SSTATE_PKG}
> +	touch ${SSTATE_PKG} || true
>  }
> 
>  python sstate_sign_package () {
> --
> 2.33.1

//Peter



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [OE-core] [PATCH] sstate: fix touching files inside pseudo
  2021-10-19 19:37 ` [OE-core] " Peter Kjellerstedt
@ 2021-10-20 11:13   ` Jose Quaresma
  0 siblings, 0 replies; 3+ messages in thread
From: Jose Quaresma @ 2021-10-20 11:13 UTC (permalink / raw)
  To: Peter Kjellerstedt; +Cc: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 2413 bytes --]

Peter Kjellerstedt <peter.kjellerstedt@axis.com> escreveu no dia terça,
19/10/2021 à(s) 20:37:

> > -----Original Message-----
> > From: openembedded-core@lists.openembedded.org <openembedded-
> > core@lists.openembedded.org> On Behalf Of Jose Quaresma
> > Sent: den 18 oktober 2021 20:47
> > To: openembedded-core@lists.openembedded.org
> > Cc: Jose Quaresma <quaresma.jose@gmail.com>
> > Subject: [OE-core] [PATCH] sstate: fix touching files inside pseudo
> >
> > running the 'id' command inside the sstate_create_package
> > function shows that this funcion run inside the pseudo:
> >
> >  uid=0(root) gid=0(root) groups=0(root)
> >
> > The check for touch files [ ! -w ${SSTATE_PKG} ]
> > will always return true and the touch can fail
> > when the real user don't have permission or
> > in readonly filesystem.
> >
> > As the documentation refers, the file test operator "-w"
> > check if the file has write permission (for the user running the test).
> >
> > We can avoid this test running the touch and mask any return errors
> > that we have.
> >
> > Signed-off-by: Jose Quaresma <quaresma.jose@gmail.com>
> > ---
> >  meta/classes/sstate.bbclass | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/meta/classes/sstate.bbclass b/meta/classes/sstate.bbclass
> > index 7f034d746a..d4555150c4 100644
> > --- a/meta/classes/sstate.bbclass
> > +++ b/meta/classes/sstate.bbclass
> > @@ -830,7 +830,7 @@ sstate_task_postfunc[dirs] = "${WORKDIR}"
> >  sstate_create_package () {
> >       # Exit early if it already exists
> >       if [ -e ${SSTATE_PKG} ]; then
> > -             [ ! -w ${SSTATE_PKG} ] || touch ${SSTATE_PKG}
> > +             touch ${SSTATE_PKG} || true
>
> You should pass stderr to /dev/null to avoid messages in the log
> if/when touch fails, i.e.:
>
>                 touch ${SSTATE_PKG} 2>/dev/null || :
>
>
I only see the logs when the task fails but I will add the redirection and
send a V2.
Thanks for the review.


> >               return
> >       fi
> >
> > @@ -865,7 +865,7 @@ sstate_create_package () {
> >       else
> >               rm $TFILE
> >       fi
> > -     [ ! -w ${SSTATE_PKG} ] || touch ${SSTATE_PKG}
> > +     touch ${SSTATE_PKG} || true
> >  }
> >
> >  python sstate_sign_package () {
> > --
> > 2.33.1
>
> //Peter
>
>

-- 
Best regards,

José Quaresma

[-- Attachment #2: Type: text/html, Size: 3759 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-20 11:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18 18:47 [PATCH] sstate: fix touching files inside pseudo Jose Quaresma
2021-10-19 19:37 ` [OE-core] " Peter Kjellerstedt
2021-10-20 11:13   ` Jose Quaresma

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 NNTP newsgroup(s).