diff mbox series

weston-init: Allow weston user to be specified

Message ID 20251015160438.1310918-1-JPEWhacker@gmail.com
State New
Headers show
Series weston-init: Allow weston user to be specified | expand

Commit Message

Joshua Watt Oct. 15, 2025, 4:04 p.m. UTC
Adds variables to set the name of the weston user (defaulting to
"weston") and the home directory (defaulting to "/home/weston"). This
allows users to easily change which user the compositor runs as.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 meta/recipes-graphics/wayland/weston-init.bb  | 21 ++++++++++++-------
 .../wayland/weston-init/weston-socket.sh      |  2 +-
 .../wayland/weston-init/weston.service        | 10 ++++-----
 .../wayland/weston-init/weston.socket         |  6 +++---
 4 files changed, 23 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/meta/recipes-graphics/wayland/weston-init.bb b/meta/recipes-graphics/wayland/weston-init.bb
index fc817d113f..e236bdb253 100644
--- a/meta/recipes-graphics/wayland/weston-init.bb
+++ b/meta/recipes-graphics/wayland/weston-init.bb
@@ -25,6 +25,8 @@  PACKAGECONFIG[use-pixman] = ",,"
 
 DEFAULTBACKEND ??= ""
 DEFAULTBACKEND:qemuall ?= "drm"
+WESTON_USER ??= "weston"
+WESTON_USER_HOME ??= "/home/${WESTON_USER}"
 
 do_install() {
 	# Install weston-start script
@@ -41,10 +43,15 @@  do_install() {
 		install -D -p -m0644 ${S}/weston.service ${D}${systemd_system_unitdir}/weston.service
 		install -D -p -m0644 ${S}/weston.socket ${D}${systemd_system_unitdir}/weston.socket
 		install -D -p -m0644 ${S}/weston-socket.sh ${D}${sysconfdir}/profile.d/weston-socket.sh
-		sed -i -e s:/etc:${sysconfdir}:g \
-			-e s:/usr/bin:${bindir}:g \
-			-e s:/var:${localstatedir}:g \
-			${D}${systemd_system_unitdir}/weston.service
+		sed -i -e s:@sysconfdir@:${sysconfdir}:g \
+			-e s:@bindir@:${bindir}:g \
+			-e s:@localstatedir@:${localstatedir}:g \
+			-e s:@runtimedir@:${runtimedir}:g \
+			-e s:@WESTON_USER@:${WESTON_USER}:g \
+			-e s:@WESTON_USER_HOME@:${WESTON_USER_HOME}:g \
+			${D}${systemd_system_unitdir}/weston.service \
+			${D}${systemd_system_unitdir}/weston.socket \
+			${D}${sysconfdir}/profile.d/weston-socket.sh
 	fi
 
 	if [ "${@bb.utils.filter('DISTRO_FEATURES', 'pam', d)}" ]; then
@@ -70,7 +77,7 @@  do_install() {
 		sed -i -e "/^\[core\]/a use-pixman=true" ${D}${sysconfdir}/xdg/weston/weston.ini
 	fi
 
-	install -dm 755 -o weston -g weston ${D}/home/weston
+	install -dm 755 -o ${WESTON_USER} -g ${WESTON_USER} ${D}/${WESTON_USER_HOME}
 }
 
 INHIBIT_UPDATERCD_BBCLASS = "${@oe.utils.conditional('VIRTUAL-RUNTIME_init_manager', 'systemd', '1', '', d)}"
@@ -95,11 +102,11 @@  FILES:${PN} += "\
     ${systemd_system_unitdir}/weston.socket \
     ${sysconfdir}/default/weston \
     ${sysconfdir}/pam.d/ \
-    /home/weston \
+    ${WESTON_USER_HOME} \
     "
 
 CONFFILES:${PN} += "${sysconfdir}/xdg/weston/weston.ini ${sysconfdir}/default/weston"
 
 SYSTEMD_SERVICE:${PN} = "weston.service weston.socket"
-USERADD_PARAM:${PN} = "--home /home/weston --shell /bin/sh --user-group -G video,input,render,seat,wayland weston"
+USERADD_PARAM:${PN} = "--home ${WESTON_USER_HOME} --shell /bin/sh --user-group -G video,input,render,seat,wayland ${WESTON_USER}"
 GROUPADD_PARAM:${PN} = "-r wayland; -r render; -r seat"
diff --git a/meta/recipes-graphics/wayland/weston-init/weston-socket.sh b/meta/recipes-graphics/wayland/weston-init/weston-socket.sh
index 86389d63a3..8f652862da 100755
--- a/meta/recipes-graphics/wayland/weston-init/weston-socket.sh
+++ b/meta/recipes-graphics/wayland/weston-init/weston-socket.sh
@@ -1,7 +1,7 @@ 
 #!/bin/sh
 
 # set weston variables for use with global weston socket
-global_socket="/run/wayland-0"
+global_socket="@runtimedir@/wayland-0"
 if [ -e "$global_socket" ]; then
 	weston_group=$(stat -c "%G" "$global_socket")
 	if [ "$(id -u)" = "0" ]; then
diff --git a/meta/recipes-graphics/wayland/weston-init/weston.service b/meta/recipes-graphics/wayland/weston-init/weston.service
index 80745998ed..b7e845e88d 100644
--- a/meta/recipes-graphics/wayland/weston-init/weston.service
+++ b/meta/recipes-graphics/wayland/weston-init/weston.service
@@ -33,19 +33,19 @@  ConditionPathExists=/dev/tty0
 [Service]
 # Requires systemd-notify.so Weston plugin.
 Type=notify
-EnvironmentFile=/etc/default/weston
-ExecStart=/usr/bin/weston --modules=systemd-notify.so
+EnvironmentFile=@sysconfdir@/default/weston
+ExecStart=@bindir@/weston --modules=systemd-notify.so
 
 # Optional watchdog setup
 #TimeoutStartSec=60
 #WatchdogSec=20
 
 # The user to run Weston as.
-User=weston
-Group=weston
+User=@WESTON_USER@
+Group=@WESTON_USER@
 
 # Make sure the working directory is the users home directory
-WorkingDirectory=/home/weston
+WorkingDirectory=@WESTON_USER_HOME@
 
 # Set up a full user session for the user, required by Weston.
 PAMName=weston-autologin
diff --git a/meta/recipes-graphics/wayland/weston-init/weston.socket b/meta/recipes-graphics/wayland/weston-init/weston.socket
index c1bdc83c05..a7d461ee30 100644
--- a/meta/recipes-graphics/wayland/weston-init/weston.socket
+++ b/meta/recipes-graphics/wayland/weston-init/weston.socket
@@ -1,11 +1,11 @@ 
 [Unit]
 Description=Weston socket
-RequiresMountsFor=/run
+RequiresMountsFor=@runtimedir@
 
 [Socket]
-ListenStream=/run/wayland-0
+ListenStream=@runtimedir@/wayland-0
 SocketMode=0775
-SocketUser=weston
+SocketUser=@WESTON_USER@
 SocketGroup=wayland
 RemoveOnStop=yes