Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v5 0/5] package/petitboot: misc fixes/enhancement
@ 2024-02-07 17:51 Reza Arbab
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup Reza Arbab
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Reza Arbab @ 2024-02-07 17:51 UTC (permalink / raw)
  To: buildroot, Arnout Vandecappelle, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier

The br2-external tree used to build OpenPOWER firmware has long carried
petitboot as a custom package[1]. Now that petitboot has been added to
buildroot proper, it would be nice to leverage the base package instead.

To make that transition easier, here is a set of patches which port over
some of the enhancements made to that external package.

[1] https://github.com/open-power/op-build/tree/master/openpower/package/petitboot
---
v5:
* Rebase to apply on top of some recent NLS fixes.

* Nobody replied to v4. Cc'ing some more people in hopes of getting
  these changes into the next release.

v4:
* Change the buildroot menu help to say that petitboot *looks best* in a
  UTF-8 locale, not that it *needs* one.

* Change the shutdown patch to accomodate any buildroot init system.

* Split the user separation patch into a couple of smaller ones with 
  better log messages.

v3:
* Add a number of small fixes.

* Add user separation, so the UI runs as non-root.

* Remove udev rules that enabled some additional types of boot devices.
  These should more appropriately live outside of buildroot.

* Remove a sysctl.d file to silence kernel output. I think there's a
  bug upstream; see https://github.com/open-power/petitboot/pull/103

v2:
* Use Laurent's suggested additions to "run pb-console at boot" patch.

Reza Arbab (5):
  package/petitboot: minor makefile cleanup
  package/petitboot: prefer UTF-8 support
  package/petitboot: fix shutdown
  package/petitboot: run script when exiting to shell
  package/petitboot: run UI as non-root user

 package/petitboot/Config.in      |  4 ++++
 package/petitboot/S15pb-discover |  4 +++-
 package/petitboot/kexec-restart  | 26 ++++++++++++++++++++++++
 package/petitboot/pb-console     |  6 ++++--
 package/petitboot/pb-shell       | 10 +++++++++
 package/petitboot/petitboot.mk   | 35 ++++++++++++++++++++++++++------
 package/petitboot/shell_profile  |  3 +++
 7 files changed, 79 insertions(+), 9 deletions(-)
 create mode 100644 package/petitboot/kexec-restart
 create mode 100644 package/petitboot/pb-shell
 create mode 100644 package/petitboot/shell_profile

-- 
2.39.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup
  2024-02-07 17:51 [Buildroot] [PATCH v5 0/5] package/petitboot: misc fixes/enhancement Reza Arbab
@ 2024-02-07 17:51 ` Reza Arbab
  2024-02-07 19:14   ` Yann E. MORIN
  2024-03-08 11:27   ` Peter Korsgaard
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support Reza Arbab
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Reza Arbab @ 2024-02-07 17:51 UTC (permalink / raw)
  To: buildroot, Arnout Vandecappelle, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier

Normalize the order of arguments to $(INSTALL). Remove an unnecessary
pair of parentheses.

Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
---
 package/petitboot/petitboot.mk | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
index 2087f01b090c..4c8bc35adb38 100644
--- a/package/petitboot/petitboot.mk
+++ b/package/petitboot/petitboot.mk
@@ -63,15 +63,15 @@ define PETITBOOT_POST_INSTALL
 		$(TARGET_DIR)/etc/petitboot/boot.d/01-create-default-dtb
 	$(INSTALL) -D -m 0755 $(@D)/utils/hooks/90-sort-dtb \
 		$(TARGET_DIR)/etc/petitboot/boot.d/90-sort-dtb
-	$(INSTALL) -m 0755 -D $(PETITBOOT_PKGDIR)/S15pb-discover \
+	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/S15pb-discover \
 		$(TARGET_DIR)/etc/init.d/S15pb-discover
 	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
 		$(TARGET_DIR)/etc/init.d/pb-console
 
 	mkdir -p $(TARGET_DIR)/etc/udev/rules.d
-	(for port in $(PETITBOOT_GETTY_PORT); do \
+	for port in $(PETITBOOT_GETTY_PORT); do \
 		printf 'SUBSYSTEM=="tty", KERNEL=="%s", RUN+="/etc/init.d/pb-console start $$name"\n' "$$port"; \
-	done) > $(TARGET_DIR)/etc/udev/rules.d/petitboot-console-ui.rules
+	done > $(TARGET_DIR)/etc/udev/rules.d/petitboot-console-ui.rules
 
 	mkdir -p $(TARGET_DIR)/usr/share/udhcpc/default.script.d/
 	ln -sf /usr/sbin/pb-udhcpc \
-- 
2.39.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support
  2024-02-07 17:51 [Buildroot] [PATCH v5 0/5] package/petitboot: misc fixes/enhancement Reza Arbab
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup Reza Arbab
@ 2024-02-07 17:51 ` Reza Arbab
  2024-02-07 19:43   ` Yann E. MORIN
  2024-03-08 11:27   ` Peter Korsgaard
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown Reza Arbab
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Reza Arbab @ 2024-02-07 17:51 UTC (permalink / raw)
  To: buildroot, Arnout Vandecappelle, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier

The petitboot UI looks much nicer in a Unicode locale:

* Items in the language selection submenu use multibyte Unicode
  characters. In other locales, they say "Unable to display text in this
  locale".

* The combination of TERM=linux with a UTF-8 locale is required to
  trigger a special-case workaround in ncurses code[1]. Without
  this, line-drawing characters in the menu look like q's.

Turn on wchar support in ncurses, and add a reminder that a UTF-8 locale
should be generated for things to look right.

[1] https://invisible-island.net/ncurses/ncurses.faq.html#no_line_drawing

Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
---
 package/petitboot/Config.in | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/package/petitboot/Config.in b/package/petitboot/Config.in
index 6a3d476b11b3..4f3b1c1ea4d1 100644
--- a/package/petitboot/Config.in
+++ b/package/petitboot/Config.in
@@ -10,6 +10,7 @@ config BR2_PACKAGE_PETITBOOT
 	select BR2_PACKAGE_ELFUTILS
 	select BR2_PACKAGE_LVM2 # devmapper
 	select BR2_PACKAGE_NCURSES
+	select BR2_PACKAGE_NCURSES_WCHAR
 	# run-time dependencies
 	select BR2_PACKAGE_KEXEC if !BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS
 	select BR2_PACKAGE_KEXEC_LITE if BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS && !BR2_PACKAGE_KEXEC
@@ -18,6 +19,8 @@ config BR2_PACKAGE_PETITBOOT
 	help
 	  Petitboot is a small kexec-based bootloader
 
+	  NOTE: petitboot looks best in a UTF-8 locale (BR2_GENERATE_LOCALE)
+
 	  http://www.kernel.org/pub/linux/kernel/people/geoff/petitboot/petitboot.html
 
 if BR2_PACKAGE_PETITBOOT
-- 
2.39.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown
  2024-02-07 17:51 [Buildroot] [PATCH v5 0/5] package/petitboot: misc fixes/enhancement Reza Arbab
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup Reza Arbab
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support Reza Arbab
@ 2024-02-07 17:51 ` Reza Arbab
  2024-07-12 22:02   ` Arnout Vandecappelle via buildroot
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 4/5] package/petitboot: run script when exiting to shell Reza Arbab
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 5/5] package/petitboot: run UI as non-root user Reza Arbab
  4 siblings, 1 reply; 13+ messages in thread
From: Reza Arbab @ 2024-02-07 17:51 UTC (permalink / raw)
  To: buildroot, Arnout Vandecappelle, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier

It's good practice to unmount filesystems and gracefully terminate
running services before running "kexec -e". So when a boot option has
been chosen from the petitboot menu, poke init to shut the system down
and kexec the new kernel.

One benefit to us in particular is that when pb-console is killed, it
notifies the user that we're booting:

  trap 'reset; echo "SIGTERM received, booting..."; sleep 2' SIGTERM

This terminal reset is also useful, exiting the ncurses visual mode so
subsequent boot output is raw rather than being confined to the window
set up for the petitboot menu.

Currently we assume busybox init, but do not add an accompanying entry
in the inittab to run kexec, so things aren't working. Fix this and
accomodate the other buildroot init systems as well.

Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
---
 package/petitboot/kexec-restart | 26 ++++++++++++++++++++++++++
 package/petitboot/petitboot.mk  | 20 +++++++++++++++++---
 2 files changed, 43 insertions(+), 3 deletions(-)
 create mode 100644 package/petitboot/kexec-restart

diff --git a/package/petitboot/kexec-restart b/package/petitboot/kexec-restart
new file mode 100644
index 000000000000..14e6899f70bb
--- /dev/null
+++ b/package/petitboot/kexec-restart
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+case "$(/usr/bin/readlink -f /proc/1/exe)" in
+	/bin/busybox)
+		# inittab "restart" runlevel entry runs kexec
+		/bin/kill -QUIT 1
+		;;
+	/sbin/init)
+		# inittab runlevel 6 entry runs kexec
+		/sbin/shutdown -r now
+		;;
+	/sbin/openrc-init)
+		/sbin/openrc-shutdown --kexec now
+		;;
+	/usr/lib/systemd/systemd)
+		/usr/bin/systemctl kexec
+		;;
+	*)
+		/usr/sbin/kexec -f -e
+		;;
+esac
+
+while :
+do
+	sleep 1
+done
diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
index 4c8bc35adb38..291083269ae9 100644
--- a/package/petitboot/petitboot.mk
+++ b/package/petitboot/petitboot.mk
@@ -29,7 +29,7 @@ PETITBOOT_CONF_OPTS = \
 	--without-twin-x11 \
 	$(if $(BR2_PACKAGE_BUSYBOX),--enable-busybox,--disable-busybox) \
 	HOST_PROG_KEXEC=/usr/sbin/kexec \
-	HOST_PROG_SHUTDOWN=/usr/libexec/petitboot/bb-kexec-reboot
+	HOST_PROG_SHUTDOWN=/usr/sbin/kexec-restart
 
 # HPA and Busybox tftp are supported. HPA tftp is part of Buildroot's tftpd
 # package.
@@ -54,17 +54,31 @@ else
 PETITBOOT_CONF_OPTS += --without-fdt
 endif
 
+ifeq ($(BR2_INIT_BUSYBOX),y)
+define PETITBOOT_BUSYBOX_INITTAB
+	grep -q kexec $(TARGET_DIR)/etc/inittab || \
+		printf "\nnull::restart:/usr/sbin/kexec -f -e\n" >> $(TARGET_DIR)/etc/inittab
+endef
+PETITBOOT_TARGET_FINALIZE_HOOKS += PETITBOOT_BUSYBOX_INITTAB
+else ifeq ($(BR2_INIT_SYSV),y)
+define PETITBOOT_SYSV_INITTAB
+	grep -q kexec $(TARGET_DIR)/etc/inittab || \
+		$(SED) 's~^reb0:.*~reb0:6:wait:/usr/sbin/kexec -f -e~' $(TARGET_DIR)/etc/inittab
+endef
+PETITBOOT_TARGET_FINALIZE_HOOKS += PETITBOOT_SYSV_INITTAB
+endif
+
 PETITBOOT_GETTY_PORT = $(patsubst %,'%',$(call qstrip,$(BR2_PACKAGE_PETITBOOT_GETTY_PORT)))
 
 define PETITBOOT_POST_INSTALL
-	$(INSTALL) -D -m 0755 $(@D)/utils/bb-kexec-reboot \
-		$(TARGET_DIR)/usr/libexec/petitboot/bb-kexec-reboot
 	$(INSTALL) -D -m 0755 $(@D)/utils/hooks/01-create-default-dtb \
 		$(TARGET_DIR)/etc/petitboot/boot.d/01-create-default-dtb
 	$(INSTALL) -D -m 0755 $(@D)/utils/hooks/90-sort-dtb \
 		$(TARGET_DIR)/etc/petitboot/boot.d/90-sort-dtb
 	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/S15pb-discover \
 		$(TARGET_DIR)/etc/init.d/S15pb-discover
+	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/kexec-restart \
+		$(TARGET_DIR)/usr/sbin/kexec-restart
 	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
 		$(TARGET_DIR)/etc/init.d/pb-console
 
-- 
2.39.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* [Buildroot] [PATCH v5 4/5] package/petitboot: run script when exiting to shell
  2024-02-07 17:51 [Buildroot] [PATCH v5 0/5] package/petitboot: misc fixes/enhancement Reza Arbab
                   ` (2 preceding siblings ...)
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown Reza Arbab
@ 2024-02-07 17:51 ` Reza Arbab
  2024-07-12 22:02   ` Arnout Vandecappelle via buildroot
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 5/5] package/petitboot: run UI as non-root user Reza Arbab
  4 siblings, 1 reply; 13+ messages in thread
From: Reza Arbab @ 2024-02-07 17:51 UTC (permalink / raw)
  To: buildroot, Arnout Vandecappelle, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier

When the user selects the shell escape option from the petitboot menu,
reset the terminal so output is raw rather than being confined to the
ncurses window set up for the petitboot menu, and print some helpful
text before running the shell.

To do this, override the default HOST_PROG_SH (/bin/sh) with a small
script. Doing so also enables someone to customize this behavior by
overlaying a different script.

Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
---
 package/petitboot/pb-shell     | 10 ++++++++++
 package/petitboot/petitboot.mk |  3 +++
 2 files changed, 13 insertions(+)
 create mode 100644 package/petitboot/pb-shell

diff --git a/package/petitboot/pb-shell b/package/petitboot/pb-shell
new file mode 100644
index 000000000000..99887c3f3b87
--- /dev/null
+++ b/package/petitboot/pb-shell
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+reset
+
+cat <<EOM
+Exiting petitboot. Type 'exit' to return.
+You may run 'pb-sos' to gather diagnostic data.
+EOM
+
+exec /bin/sh
diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
index 291083269ae9..e2f762842534 100644
--- a/package/petitboot/petitboot.mk
+++ b/package/petitboot/petitboot.mk
@@ -29,6 +29,7 @@ PETITBOOT_CONF_OPTS = \
 	--without-twin-x11 \
 	$(if $(BR2_PACKAGE_BUSYBOX),--enable-busybox,--disable-busybox) \
 	HOST_PROG_KEXEC=/usr/sbin/kexec \
+	HOST_PROG_SH=/usr/libexec/petitboot/pb-shell \
 	HOST_PROG_SHUTDOWN=/usr/sbin/kexec-restart
 
 # HPA and Busybox tftp are supported. HPA tftp is part of Buildroot's tftpd
@@ -81,6 +82,8 @@ define PETITBOOT_POST_INSTALL
 		$(TARGET_DIR)/usr/sbin/kexec-restart
 	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
 		$(TARGET_DIR)/etc/init.d/pb-console
+	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-shell \
+		$(TARGET_DIR)/usr/libexec/petitboot/pb-shell
 
 	mkdir -p $(TARGET_DIR)/etc/udev/rules.d
 	for port in $(PETITBOOT_GETTY_PORT); do \
-- 
2.39.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* [Buildroot] [PATCH v5 5/5] package/petitboot: run UI as non-root user
  2024-02-07 17:51 [Buildroot] [PATCH v5 0/5] package/petitboot: misc fixes/enhancement Reza Arbab
                   ` (3 preceding siblings ...)
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 4/5] package/petitboot: run script when exiting to shell Reza Arbab
@ 2024-02-07 17:51 ` Reza Arbab
  2024-07-12 22:03   ` Arnout Vandecappelle via buildroot
  4 siblings, 1 reply; 13+ messages in thread
From: Reza Arbab @ 2024-02-07 17:51 UTC (permalink / raw)
  To: buildroot, Arnout Vandecappelle, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier

Though the petitboot UI is a user application, it is currently being
run by root only because we use getty to display it on the console.

Create an unprivileged user to run the UI instead. The unix socket the
pb-discover daemon sets up is accessible to "petitgroup", so that should
be the gid, with arbitrary uid "petituser" to match.

This is currently the chain of processes leading to the UI:

1. /etc/init.d/pb-console start console
2. /usr/libexec/petitboot/pb-console --getty --detach -- -n -i 0 console linux
3. /sbin/getty -l/usr/libexec/petitboot/pb-console -n -i 0 console linux
4. /usr/libexec/petitboot/pb-console
5. /usr/sbin/petitboot-nc

Instead of (3) running the pb-console helper directly with "getty -l",
we can use "agetty -a" to autologin petituser, and run pb-console via
petituser's login shell:

1. /etc/init.d/pb-console start console
2. /usr/libexec/petitboot/pb-console --getty=/sbin/agetty --detach -- -a petituser -n -i console linux
3. /sbin/agetty -a petituser -n -i console linux
4. /home/petituser/.profile
5. /usr/libexec/petitboot/pb-console
6. /usr/sbin/petiboot-nc

Here, everything from (4) down is running as petituser. In (4), use
$PPID to determine if we're logging in via getty, so that logging in by
other means will give a normal shell.

Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
---
 package/petitboot/Config.in      | 1 +
 package/petitboot/S15pb-discover | 4 +++-
 package/petitboot/pb-console     | 6 ++++--
 package/petitboot/petitboot.mk   | 6 ++++++
 package/petitboot/shell_profile  | 3 +++
 5 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 package/petitboot/shell_profile

diff --git a/package/petitboot/Config.in b/package/petitboot/Config.in
index 4f3b1c1ea4d1..e561547c10c8 100644
--- a/package/petitboot/Config.in
+++ b/package/petitboot/Config.in
@@ -16,6 +16,7 @@ config BR2_PACKAGE_PETITBOOT
 	select BR2_PACKAGE_KEXEC_LITE if BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS && !BR2_PACKAGE_KEXEC
 	select BR2_PACKAGE_NVME if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
 	select BR2_PACKAGE_POWERPC_UTILS if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
+	select BR2_PACKAGE_UTIL_LINUX_AGETTY
 	help
 	  Petitboot is a small kexec-based bootloader
 
diff --git a/package/petitboot/S15pb-discover b/package/petitboot/S15pb-discover
index 71ab62d99859..9e8f6c87f8bb 100644
--- a/package/petitboot/S15pb-discover
+++ b/package/petitboot/S15pb-discover
@@ -12,7 +12,9 @@ fi
 
 start() {
 	printf 'Starting %s: ' "$DAEMON"
-	mkdir -p /var/log/petitboot
+	# shellcheck disable=SC2174 # only apply -m to deepest dir
+	mkdir -p -m 0775 /var/log/petitboot
+	chown petituser:petitgroup /var/log/petitboot
 
 	# shellcheck disable=SC2086 # we need the word splitting
 	start-stop-daemon -S -q -b -m -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
diff --git a/package/petitboot/pb-console b/package/petitboot/pb-console
index 407ff3b30232..8b23b2233dee 100644
--- a/package/petitboot/pb-console
+++ b/package/petitboot/pb-console
@@ -3,14 +3,16 @@
 DAEMON="pb-console"
 
 PB_CONSOLE_PORT=${2:-"console"}
-PB_CONSOLE_ARGS="--getty --detach -- -n -i 0 $PB_CONSOLE_PORT linux"
+PB_CONSOLE_ARGS="--getty=/sbin/agetty --detach -- -a petituser -n -i $PB_CONSOLE_PORT linux"
 
 # shellcheck source=/dev/null
 [ -r "/etc/default/petitboot" ] && . "/etc/default/petitboot"
 
 start() {
 	printf 'Starting %s on %s: ' "$DAEMON" "$PB_CONSOLE_PORT"
-	mkdir -p /var/log/petitboot
+	# shellcheck disable=SC2174 # only apply -m to deepest dir
+	mkdir -p -m 0775 /var/log/petitboot
+	chown petituser:petitgroup /var/log/petitboot
 
 	# shellcheck disable=SC2086 # we need the word splitting
 	start-stop-daemon -S -q -x "/usr/libexec/petitboot/$DAEMON" \
diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
index e2f762842534..8e02118f25f1 100644
--- a/package/petitboot/petitboot.mk
+++ b/package/petitboot/petitboot.mk
@@ -84,6 +84,8 @@ define PETITBOOT_POST_INSTALL
 		$(TARGET_DIR)/etc/init.d/pb-console
 	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-shell \
 		$(TARGET_DIR)/usr/libexec/petitboot/pb-shell
+	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/shell_profile \
+		$(TARGET_DIR)/home/petituser/.profile
 
 	mkdir -p $(TARGET_DIR)/etc/udev/rules.d
 	for port in $(PETITBOOT_GETTY_PORT); do \
@@ -97,4 +99,8 @@ endef
 
 PETITBOOT_POST_INSTALL_TARGET_HOOKS += PETITBOOT_POST_INSTALL
 
+define PETITBOOT_USERS
+	petituser -1 petitgroup -1 * /home/petituser /bin/sh - petitboot user
+endef
+
 $(eval $(autotools-package))
diff --git a/package/petitboot/shell_profile b/package/petitboot/shell_profile
new file mode 100644
index 000000000000..a958ca4402f2
--- /dev/null
+++ b/package/petitboot/shell_profile
@@ -0,0 +1,3 @@
+if [ "$PPID" = "1" ]; then
+	exec /usr/libexec/petitboot/pb-console
+fi
-- 
2.39.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup Reza Arbab
@ 2024-02-07 19:14   ` Yann E. MORIN
  2024-03-08 11:27   ` Peter Korsgaard
  1 sibling, 0 replies; 13+ messages in thread
From: Yann E. MORIN @ 2024-02-07 19:14 UTC (permalink / raw)
  To: Reza Arbab; +Cc: Fabrice Fontaine, Laurent Vivier, Joel Stanley, buildroot

Reza, All,

On 2024-02-07 11:51 -0600, Reza Arbab spake thusly:
> Normalize the order of arguments to $(INSTALL). Remove an unnecessary
> pair of parentheses.
> 
> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>

Applied to master, thanks.

Regards,
Yann E. MORIN.

> ---
>  package/petitboot/petitboot.mk | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
> index 2087f01b090c..4c8bc35adb38 100644
> --- a/package/petitboot/petitboot.mk
> +++ b/package/petitboot/petitboot.mk
> @@ -63,15 +63,15 @@ define PETITBOOT_POST_INSTALL
>  		$(TARGET_DIR)/etc/petitboot/boot.d/01-create-default-dtb
>  	$(INSTALL) -D -m 0755 $(@D)/utils/hooks/90-sort-dtb \
>  		$(TARGET_DIR)/etc/petitboot/boot.d/90-sort-dtb
> -	$(INSTALL) -m 0755 -D $(PETITBOOT_PKGDIR)/S15pb-discover \
> +	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/S15pb-discover \
>  		$(TARGET_DIR)/etc/init.d/S15pb-discover
>  	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
>  		$(TARGET_DIR)/etc/init.d/pb-console
>  
>  	mkdir -p $(TARGET_DIR)/etc/udev/rules.d
> -	(for port in $(PETITBOOT_GETTY_PORT); do \
> +	for port in $(PETITBOOT_GETTY_PORT); do \
>  		printf 'SUBSYSTEM=="tty", KERNEL=="%s", RUN+="/etc/init.d/pb-console start $$name"\n' "$$port"; \
> -	done) > $(TARGET_DIR)/etc/udev/rules.d/petitboot-console-ui.rules
> +	done > $(TARGET_DIR)/etc/udev/rules.d/petitboot-console-ui.rules
>  
>  	mkdir -p $(TARGET_DIR)/usr/share/udhcpc/default.script.d/
>  	ln -sf /usr/sbin/pb-udhcpc \
> -- 
> 2.39.3
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support Reza Arbab
@ 2024-02-07 19:43   ` Yann E. MORIN
  2024-03-08 11:27   ` Peter Korsgaard
  1 sibling, 0 replies; 13+ messages in thread
From: Yann E. MORIN @ 2024-02-07 19:43 UTC (permalink / raw)
  To: Reza Arbab; +Cc: Fabrice Fontaine, Laurent Vivier, Joel Stanley, buildroot

Reza, All,

On 2024-02-07 11:51 -0600, Reza Arbab spake thusly:
> The petitboot UI looks much nicer in a Unicode locale:
> 
> * Items in the language selection submenu use multibyte Unicode
>   characters. In other locales, they say "Unable to display text in this
>   locale".
> 
> * The combination of TERM=linux with a UTF-8 locale is required to
>   trigger a special-case workaround in ncurses code[1]. Without
>   this, line-drawing characters in the menu look like q's.
> 
> Turn on wchar support in ncurses, and add a reminder that a UTF-8 locale
> should be generated for things to look right.
> 
> [1] https://invisible-island.net/ncurses/ncurses.faq.html#no_line_drawing
> 
> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
> ---
>  package/petitboot/Config.in | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/package/petitboot/Config.in b/package/petitboot/Config.in
> index 6a3d476b11b3..4f3b1c1ea4d1 100644
> --- a/package/petitboot/Config.in
> +++ b/package/petitboot/Config.in
> @@ -10,6 +10,7 @@ config BR2_PACKAGE_PETITBOOT
>  	select BR2_PACKAGE_ELFUTILS
>  	select BR2_PACKAGE_LVM2 # devmapper
>  	select BR2_PACKAGE_NCURSES
> +	select BR2_PACKAGE_NCURSES_WCHAR
>  	# run-time dependencies
>  	select BR2_PACKAGE_KEXEC if !BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS
>  	select BR2_PACKAGE_KEXEC_LITE if BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS && !BR2_PACKAGE_KEXEC
> @@ -18,6 +19,8 @@ config BR2_PACKAGE_PETITBOOT
>  	help
>  	  Petitboot is a small kexec-based bootloader
>  
> +	  NOTE: petitboot looks best in a UTF-8 locale (BR2_GENERATE_LOCALE)

    $ ./utils/docker-run make check-package
    package/petitboot/Config.in:22: help text: <tab><2 spaces><62 chars> (http://nightly.buildroot.org/#writing-rules-config-in)

I slightly reworded that sentence to better fit.

Applied to master with the above fixed, thanks.

Regards,
Yann E. MORIN.

>  	  http://www.kernel.org/pub/linux/kernel/people/geoff/petitboot/petitboot.html
>  
>  if BR2_PACKAGE_PETITBOOT
> -- 
> 2.39.3
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup Reza Arbab
  2024-02-07 19:14   ` Yann E. MORIN
@ 2024-03-08 11:27   ` Peter Korsgaard
  1 sibling, 0 replies; 13+ messages in thread
From: Peter Korsgaard @ 2024-03-08 11:27 UTC (permalink / raw)
  To: Reza Arbab
  Cc: Laurent Vivier, Yann E . MORIN, Joel Stanley, buildroot,
	Fabrice Fontaine

>>>>> "Reza" == Reza Arbab <arbab@linux.ibm.com> writes:

 > Normalize the order of arguments to $(INSTALL). Remove an unnecessary
 > pair of parentheses.

 > Signed-off-by: Reza Arbab <arbab@linux.ibm.com>

Committed to 2023.11.x, thanks.

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support Reza Arbab
  2024-02-07 19:43   ` Yann E. MORIN
@ 2024-03-08 11:27   ` Peter Korsgaard
  1 sibling, 0 replies; 13+ messages in thread
From: Peter Korsgaard @ 2024-03-08 11:27 UTC (permalink / raw)
  To: Reza Arbab
  Cc: Laurent Vivier, Yann E . MORIN, Joel Stanley, buildroot,
	Fabrice Fontaine

>>>>> "Reza" == Reza Arbab <arbab@linux.ibm.com> writes:

 > The petitboot UI looks much nicer in a Unicode locale:
 > * Items in the language selection submenu use multibyte Unicode
 >   characters. In other locales, they say "Unable to display text in this
 >   locale".

 > * The combination of TERM=linux with a UTF-8 locale is required to
 >   trigger a special-case workaround in ncurses code[1]. Without
 >   this, line-drawing characters in the menu look like q's.

 > Turn on wchar support in ncurses, and add a reminder that a UTF-8 locale
 > should be generated for things to look right.

 > [1] https://invisible-island.net/ncurses/ncurses.faq.html#no_line_drawing

 > Signed-off-by: Reza Arbab <arbab@linux.ibm.com>

Committed to 2023.11.x, thanks.

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown Reza Arbab
@ 2024-07-12 22:02   ` Arnout Vandecappelle via buildroot
  0 siblings, 0 replies; 13+ messages in thread
From: Arnout Vandecappelle via buildroot @ 2024-07-12 22:02 UTC (permalink / raw)
  To: Reza Arbab, buildroot, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier



On 07/02/2024 18:51, Reza Arbab wrote:
> It's good practice to unmount filesystems and gracefully terminate
> running services before running "kexec -e". So when a boot option has
> been chosen from the petitboot menu, poke init to shut the system down
> and kexec the new kernel.
> 
> One benefit to us in particular is that when pb-console is killed, it
> notifies the user that we're booting:
> 
>    trap 'reset; echo "SIGTERM received, booting..."; sleep 2' SIGTERM
> 
> This terminal reset is also useful, exiting the ncurses visual mode so
> subsequent boot output is raw rather than being confined to the window
> set up for the petitboot menu.
> 
> Currently we assume busybox init, but do not add an accompanying entry
> in the inittab to run kexec, so things aren't working. Fix this and
> accomodate the other buildroot init systems as well.
> 
> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>

  Applied to master, thanks. I still modified it pretty heavily though, see 
below. You may want to re-test it on your side as well.

> ---
>   package/petitboot/kexec-restart | 26 ++++++++++++++++++++++++++
>   package/petitboot/petitboot.mk  | 20 +++++++++++++++++---
>   2 files changed, 43 insertions(+), 3 deletions(-)
>   create mode 100644 package/petitboot/kexec-restart
> 
> diff --git a/package/petitboot/kexec-restart b/package/petitboot/kexec-restart
> new file mode 100644
> index 000000000000..14e6899f70bb
> --- /dev/null
> +++ b/package/petitboot/kexec-restart
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +
> +case "$(/usr/bin/readlink -f /proc/1/exe)" in
> +	/bin/busybox)
> +		# inittab "restart" runlevel entry runs kexec
> +		/bin/kill -QUIT 1
> +		;;
> +	/sbin/init)
> +		# inittab runlevel 6 entry runs kexec
> +		/sbin/shutdown -r now
> +		;;
> +	/sbin/openrc-init)
> +		/sbin/openrc-shutdown --kexec now
> +		;;
> +	/usr/lib/systemd/systemd)
> +		/usr/bin/systemctl kexec
> +		;;
> +	*)
> +		/usr/sbin/kexec -f -e
> +		;;

  Rather than dynamically discovering the init system, I elected to do it 
statically based on the config, and sed-ing the appropriate command into a 
skeleton script.

> +esac
> +
> +while :
> +do
> +	sleep 1
> +done
> diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
> index 4c8bc35adb38..291083269ae9 100644
> --- a/package/petitboot/petitboot.mk
> +++ b/package/petitboot/petitboot.mk
> @@ -29,7 +29,7 @@ PETITBOOT_CONF_OPTS = \
>   	--without-twin-x11 \
>   	$(if $(BR2_PACKAGE_BUSYBOX),--enable-busybox,--disable-busybox) \
>   	HOST_PROG_KEXEC=/usr/sbin/kexec \
> -	HOST_PROG_SHUTDOWN=/usr/libexec/petitboot/bb-kexec-reboot
> +	HOST_PROG_SHUTDOWN=/usr/sbin/kexec-restart

  I kept this in /usr/libexec/petitboot.

>   
>   # HPA and Busybox tftp are supported. HPA tftp is part of Buildroot's tftpd
>   # package.
> @@ -54,17 +54,31 @@ else
>   PETITBOOT_CONF_OPTS += --without-fdt
>   endif
>   
> +ifeq ($(BR2_INIT_BUSYBOX),y)
> +define PETITBOOT_BUSYBOX_INITTAB
> +	grep -q kexec $(TARGET_DIR)/etc/inittab || \
> +		printf "\nnull::restart:/usr/sbin/kexec -f -e\n" >> $(TARGET_DIR)/etc/inittab
> +endef
> +PETITBOOT_TARGET_FINALIZE_HOOKS += PETITBOOT_BUSYBOX_INITTAB
> +else ifeq ($(BR2_INIT_SYSV),y)
> +define PETITBOOT_SYSV_INITTAB
> +	grep -q kexec $(TARGET_DIR)/etc/inittab || \
> +		$(SED) 's~^reb0:.*~reb0:6:wait:/usr/sbin/kexec -f -e~' $(TARGET_DIR)/etc/inittab
> +endef
> +PETITBOOT_TARGET_FINALIZE_HOOKS += PETITBOOT_SYSV_INITTAB
> +endif
> +
>   PETITBOOT_GETTY_PORT = $(patsubst %,'%',$(call qstrip,$(BR2_PACKAGE_PETITBOOT_GETTY_PORT)))
>   
>   define PETITBOOT_POST_INSTALL
> -	$(INSTALL) -D -m 0755 $(@D)/utils/bb-kexec-reboot \
> -		$(TARGET_DIR)/usr/libexec/petitboot/bb-kexec-reboot

  I kept the installation of kexec-restart in this location instead of at the 
end, that makes the diff more reasonable and I couldn't discern any particular 
reasoning behind the ordering.

  Regards,
  Arnout

>   	$(INSTALL) -D -m 0755 $(@D)/utils/hooks/01-create-default-dtb \
>   		$(TARGET_DIR)/etc/petitboot/boot.d/01-create-default-dtb
>   	$(INSTALL) -D -m 0755 $(@D)/utils/hooks/90-sort-dtb \
>   		$(TARGET_DIR)/etc/petitboot/boot.d/90-sort-dtb
>   	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/S15pb-discover \
>   		$(TARGET_DIR)/etc/init.d/S15pb-discover
> +	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/kexec-restart \
> +		$(TARGET_DIR)/usr/sbin/kexec-restart
>   	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
>   		$(TARGET_DIR)/etc/init.d/pb-console
>   
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH v5 4/5] package/petitboot: run script when exiting to shell
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 4/5] package/petitboot: run script when exiting to shell Reza Arbab
@ 2024-07-12 22:02   ` Arnout Vandecappelle via buildroot
  0 siblings, 0 replies; 13+ messages in thread
From: Arnout Vandecappelle via buildroot @ 2024-07-12 22:02 UTC (permalink / raw)
  To: Reza Arbab, buildroot, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier



On 07/02/2024 18:51, Reza Arbab wrote:
> When the user selects the shell escape option from the petitboot menu,
> reset the terminal so output is raw rather than being confined to the
> ncurses window set up for the petitboot menu, and print some helpful
> text before running the shell.
> 
> To do this, override the default HOST_PROG_SH (/bin/sh) with a small
> script. Doing so also enables someone to customize this behavior by
> overlaying a different script.
> 
> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>

  Applied to master, thanks.

  Regards,
  Arnout

> ---
>   package/petitboot/pb-shell     | 10 ++++++++++
>   package/petitboot/petitboot.mk |  3 +++
>   2 files changed, 13 insertions(+)
>   create mode 100644 package/petitboot/pb-shell
> 
> diff --git a/package/petitboot/pb-shell b/package/petitboot/pb-shell
> new file mode 100644
> index 000000000000..99887c3f3b87
> --- /dev/null
> +++ b/package/petitboot/pb-shell
> @@ -0,0 +1,10 @@
> +#!/bin/sh
> +
> +reset
> +
> +cat <<EOM
> +Exiting petitboot. Type 'exit' to return.
> +You may run 'pb-sos' to gather diagnostic data.
> +EOM
> +
> +exec /bin/sh
> diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
> index 291083269ae9..e2f762842534 100644
> --- a/package/petitboot/petitboot.mk
> +++ b/package/petitboot/petitboot.mk
> @@ -29,6 +29,7 @@ PETITBOOT_CONF_OPTS = \
>   	--without-twin-x11 \
>   	$(if $(BR2_PACKAGE_BUSYBOX),--enable-busybox,--disable-busybox) \
>   	HOST_PROG_KEXEC=/usr/sbin/kexec \
> +	HOST_PROG_SH=/usr/libexec/petitboot/pb-shell \
>   	HOST_PROG_SHUTDOWN=/usr/sbin/kexec-restart
>   
>   # HPA and Busybox tftp are supported. HPA tftp is part of Buildroot's tftpd
> @@ -81,6 +82,8 @@ define PETITBOOT_POST_INSTALL
>   		$(TARGET_DIR)/usr/sbin/kexec-restart
>   	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
>   		$(TARGET_DIR)/etc/init.d/pb-console
> +	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-shell \
> +		$(TARGET_DIR)/usr/libexec/petitboot/pb-shell
>   
>   	mkdir -p $(TARGET_DIR)/etc/udev/rules.d
>   	for port in $(PETITBOOT_GETTY_PORT); do \
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH v5 5/5] package/petitboot: run UI as non-root user
  2024-02-07 17:51 ` [Buildroot] [PATCH v5 5/5] package/petitboot: run UI as non-root user Reza Arbab
@ 2024-07-12 22:03   ` Arnout Vandecappelle via buildroot
  0 siblings, 0 replies; 13+ messages in thread
From: Arnout Vandecappelle via buildroot @ 2024-07-12 22:03 UTC (permalink / raw)
  To: Reza Arbab, buildroot, Yann E . MORIN
  Cc: Joel Stanley, Fabrice Fontaine, Laurent Vivier



On 07/02/2024 18:51, Reza Arbab wrote:
> Though the petitboot UI is a user application, it is currently being
> run by root only because we use getty to display it on the console.
> 
> Create an unprivileged user to run the UI instead. The unix socket the
> pb-discover daemon sets up is accessible to "petitgroup", so that should
> be the gid, with arbitrary uid "petituser" to match.
> 
> This is currently the chain of processes leading to the UI:
> 
> 1. /etc/init.d/pb-console start console
> 2. /usr/libexec/petitboot/pb-console --getty --detach -- -n -i 0 console linux
> 3. /sbin/getty -l/usr/libexec/petitboot/pb-console -n -i 0 console linux
> 4. /usr/libexec/petitboot/pb-console
> 5. /usr/sbin/petitboot-nc
> 
> Instead of (3) running the pb-console helper directly with "getty -l",
> we can use "agetty -a" to autologin petituser, and run pb-console via
> petituser's login shell:
> 
> 1. /etc/init.d/pb-console start console
> 2. /usr/libexec/petitboot/pb-console --getty=/sbin/agetty --detach -- -a petituser -n -i console linux
> 3. /sbin/agetty -a petituser -n -i console linux
> 4. /home/petituser/.profile
> 5. /usr/libexec/petitboot/pb-console
> 6. /usr/sbin/petiboot-nc
> 
> Here, everything from (4) down is running as petituser. In (4), use
> $PPID to determine if we're logging in via getty, so that logging in by
> other means will give a normal shell.
> 
> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
> ---
>   package/petitboot/Config.in      | 1 +
>   package/petitboot/S15pb-discover | 4 +++-
>   package/petitboot/pb-console     | 6 ++++--
>   package/petitboot/petitboot.mk   | 6 ++++++
>   package/petitboot/shell_profile  | 3 +++
>   5 files changed, 17 insertions(+), 3 deletions(-)
>   create mode 100644 package/petitboot/shell_profile
> 
> diff --git a/package/petitboot/Config.in b/package/petitboot/Config.in
> index 4f3b1c1ea4d1..e561547c10c8 100644
> --- a/package/petitboot/Config.in
> +++ b/package/petitboot/Config.in
> @@ -16,6 +16,7 @@ config BR2_PACKAGE_PETITBOOT
>   	select BR2_PACKAGE_KEXEC_LITE if BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS && !BR2_PACKAGE_KEXEC
>   	select BR2_PACKAGE_NVME if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
>   	select BR2_PACKAGE_POWERPC_UTILS if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
> +	select BR2_PACKAGE_UTIL_LINUX_AGETTY

  Although util-linux is selected indirectly through other dependencies (e.g. 
eudev/systemd), it's better to do it explicitly.

  Applied to master with that changed, thanks.

  Regards,
  Arnout

>   	help
>   	  Petitboot is a small kexec-based bootloader
>   
> diff --git a/package/petitboot/S15pb-discover b/package/petitboot/S15pb-discover
> index 71ab62d99859..9e8f6c87f8bb 100644
> --- a/package/petitboot/S15pb-discover
> +++ b/package/petitboot/S15pb-discover
> @@ -12,7 +12,9 @@ fi
>   
>   start() {
>   	printf 'Starting %s: ' "$DAEMON"
> -	mkdir -p /var/log/petitboot
> +	# shellcheck disable=SC2174 # only apply -m to deepest dir
> +	mkdir -p -m 0775 /var/log/petitboot
> +	chown petituser:petitgroup /var/log/petitboot
>   
>   	# shellcheck disable=SC2086 # we need the word splitting
>   	start-stop-daemon -S -q -b -m -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
> diff --git a/package/petitboot/pb-console b/package/petitboot/pb-console
> index 407ff3b30232..8b23b2233dee 100644
> --- a/package/petitboot/pb-console
> +++ b/package/petitboot/pb-console
> @@ -3,14 +3,16 @@
>   DAEMON="pb-console"
>   
>   PB_CONSOLE_PORT=${2:-"console"}
> -PB_CONSOLE_ARGS="--getty --detach -- -n -i 0 $PB_CONSOLE_PORT linux"
> +PB_CONSOLE_ARGS="--getty=/sbin/agetty --detach -- -a petituser -n -i $PB_CONSOLE_PORT linux"
>   
>   # shellcheck source=/dev/null
>   [ -r "/etc/default/petitboot" ] && . "/etc/default/petitboot"
>   
>   start() {
>   	printf 'Starting %s on %s: ' "$DAEMON" "$PB_CONSOLE_PORT"
> -	mkdir -p /var/log/petitboot
> +	# shellcheck disable=SC2174 # only apply -m to deepest dir
> +	mkdir -p -m 0775 /var/log/petitboot
> +	chown petituser:petitgroup /var/log/petitboot
>   
>   	# shellcheck disable=SC2086 # we need the word splitting
>   	start-stop-daemon -S -q -x "/usr/libexec/petitboot/$DAEMON" \
> diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
> index e2f762842534..8e02118f25f1 100644
> --- a/package/petitboot/petitboot.mk
> +++ b/package/petitboot/petitboot.mk
> @@ -84,6 +84,8 @@ define PETITBOOT_POST_INSTALL
>   		$(TARGET_DIR)/etc/init.d/pb-console
>   	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-shell \
>   		$(TARGET_DIR)/usr/libexec/petitboot/pb-shell
> +	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/shell_profile \
> +		$(TARGET_DIR)/home/petituser/.profile
>   
>   	mkdir -p $(TARGET_DIR)/etc/udev/rules.d
>   	for port in $(PETITBOOT_GETTY_PORT); do \
> @@ -97,4 +99,8 @@ endef
>   
>   PETITBOOT_POST_INSTALL_TARGET_HOOKS += PETITBOOT_POST_INSTALL
>   
> +define PETITBOOT_USERS
> +	petituser -1 petitgroup -1 * /home/petituser /bin/sh - petitboot user
> +endef
> +
>   $(eval $(autotools-package))
> diff --git a/package/petitboot/shell_profile b/package/petitboot/shell_profile
> new file mode 100644
> index 000000000000..a958ca4402f2
> --- /dev/null
> +++ b/package/petitboot/shell_profile
> @@ -0,0 +1,3 @@
> +if [ "$PPID" = "1" ]; then
> +	exec /usr/libexec/petitboot/pb-console
> +fi
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

end of thread, other threads:[~2024-07-12 22:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-07 17:51 [Buildroot] [PATCH v5 0/5] package/petitboot: misc fixes/enhancement Reza Arbab
2024-02-07 17:51 ` [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup Reza Arbab
2024-02-07 19:14   ` Yann E. MORIN
2024-03-08 11:27   ` Peter Korsgaard
2024-02-07 17:51 ` [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support Reza Arbab
2024-02-07 19:43   ` Yann E. MORIN
2024-03-08 11:27   ` Peter Korsgaard
2024-02-07 17:51 ` [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown Reza Arbab
2024-07-12 22:02   ` Arnout Vandecappelle via buildroot
2024-02-07 17:51 ` [Buildroot] [PATCH v5 4/5] package/petitboot: run script when exiting to shell Reza Arbab
2024-07-12 22:02   ` Arnout Vandecappelle via buildroot
2024-02-07 17:51 ` [Buildroot] [PATCH v5 5/5] package/petitboot: run UI as non-root user Reza Arbab
2024-07-12 22:03   ` Arnout Vandecappelle via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox