diff mbox series

[1/2] weston-init: improve XDG_RUNTIME_DIR fallback creation

Message ID 20250304111233.4038622-1-ross.burton@arm.com
State Accepted, archived
Commit a977c2a61dfabed9be061d742797248448aa5ade
Headers show
Series [1/2] weston-init: improve XDG_RUNTIME_DIR fallback creation | expand

Commit Message

Ross Burton March 4, 2025, 11:12 a.m. UTC
Sanity-check the permissions of the directory already exists, and clean
up the creation code.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 .../wayland/weston-init/weston-start          | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)

Comments

Peter Kjellerstedt March 5, 2025, 9:32 p.m. UTC | #1
> -----Original Message-----
> From: openembedded-core@lists.openembedded.org <openembedded-core@lists.openembedded.org> On Behalf Of Ross Burton via lists.openembedded.org
> Sent: den 4 mars 2025 12:13
> To: openembedded-core@lists.openembedded.org
> Subject: [OE-core] [PATCH 1/2] weston-init: improve XDG_RUNTIME_DIR fallback creation
> 
> Sanity-check the permissions of the directory already exists, and clean
> up the creation code.
> 
> Signed-off-by: Ross Burton <ross.burton@arm.com>
> ---
>  .../wayland/weston-init/weston-start          | 21 ++++++++++++-------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/meta/recipes-graphics/wayland/weston-init/weston-start b/meta/recipes-graphics/wayland/weston-init/weston-start
> index 01670cd4f51..3b13a0047a9 100755
> --- a/meta/recipes-graphics/wayland/weston-init/weston-start
> +++ b/meta/recipes-graphics/wayland/weston-init/weston-start
> @@ -58,14 +58,19 @@ fi
> 
>  if test -z "$XDG_RUNTIME_DIR"; then

For consistency, change to:

if [ -z "$XDG_RUNTIME_DIR" ]; then

>  	export XDG_RUNTIME_DIR=/run/user/`id -u ${WESTON_USER}`

For consistency, use $(...) instead of `...`:

	export XDG_RUNTIME_DIR=/run/user/$(id -u ${WESTON_USER})

> -	if ! test -d "$XDG_RUNTIME_DIR"; then
> -		mkdir --parents $XDG_RUNTIME_DIR
> -		chmod 0700 $XDG_RUNTIME_DIR
> -	fi
> -	if [ -n "$WESTON_USER" ]
> -	then
> -		chown $WESTON_USER:$WESTON_GROUP $XDG_RUNTIME_DIR
> +	if test -d "$XDG_RUNTIME_DIR"; then

For consistency, change to:

	if [ -d "$XDG_RUNTIME_DIR" ]; then

> +	    # Check permissions on existing directory
> +	    if [ "$(stat -c %u-%a "$XDG_RUNTIME_DIR")" != "$(id -u ${WESTON_USER})-700" ]; then

Inconsistent indentation (spaces instead of tabs).

> +			echo "ERROR: $XDG_RUNTIME_DIR has incorrect permissions"
> +			exit 1
> +		fi
> +	else
> +		mkdir --mode 0700 --parents $XDG_RUNTIME_DIR
> +		if [ -n "$WESTON_USER" ]
> +		then

For consistency, change to:

		if [ -n "$WESTON_USER" ]; then

> +			chown $WESTON_USER:$WESTON_GROUP $XDG_RUNTIME_DIR
> +		fi
>  	fi	
>  fi
> 
> -su -c "XDG_RUNTIME_DIR=/run/user/`id -u ${WESTON_USER}` weston $weston_args --log=/tmp/weston.log" $WESTON_USER
> +su -c "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR weston $weston_args --log=/tmp/weston.log" $WESTON_USER
> --
> 2.43.0

//Peter
diff mbox series

Patch

diff --git a/meta/recipes-graphics/wayland/weston-init/weston-start b/meta/recipes-graphics/wayland/weston-init/weston-start
index 01670cd4f51..3b13a0047a9 100755
--- a/meta/recipes-graphics/wayland/weston-init/weston-start
+++ b/meta/recipes-graphics/wayland/weston-init/weston-start
@@ -58,14 +58,19 @@  fi
 
 if test -z "$XDG_RUNTIME_DIR"; then
 	export XDG_RUNTIME_DIR=/run/user/`id -u ${WESTON_USER}`
-	if ! test -d "$XDG_RUNTIME_DIR"; then
-		mkdir --parents $XDG_RUNTIME_DIR
-		chmod 0700 $XDG_RUNTIME_DIR
-	fi
-	if [ -n "$WESTON_USER" ]
-	then
-		chown $WESTON_USER:$WESTON_GROUP $XDG_RUNTIME_DIR
+	if test -d "$XDG_RUNTIME_DIR"; then
+	    # Check permissions on existing directory
+	    if [ "$(stat -c %u-%a "$XDG_RUNTIME_DIR")" != "$(id -u ${WESTON_USER})-700" ]; then
+			echo "ERROR: $XDG_RUNTIME_DIR has incorrect permissions"
+			exit 1
+		fi
+	else
+		mkdir --mode 0700 --parents $XDG_RUNTIME_DIR
+		if [ -n "$WESTON_USER" ]
+		then
+			chown $WESTON_USER:$WESTON_GROUP $XDG_RUNTIME_DIR
+		fi
 	fi
 fi
 
-su -c "XDG_RUNTIME_DIR=/run/user/`id -u ${WESTON_USER}` weston $weston_args --log=/tmp/weston.log" $WESTON_USER
+su -c "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR weston $weston_args --log=/tmp/weston.log" $WESTON_USER