[v2,04/13] package/openrc: add support forspawning getty
diff mbox series

Message ID 20190512195550.24457-4-michal.lyszczek@bofc.pl
State Superseded
Headers show
Series
  • [v2,01/13] package/openrc: new package (v0.41.2)
Related show

Commit Message

Michał Łyszczek May 12, 2019, 7:55 p.m. UTC
* package/openrc/openrc.mk
  add code that monitors BR2_TARGET_GENERIC_GETTY and if set,
  creates configuration file (with SYSTEM_GETTY_*) for port in
  /etc/conf.d/getty.$(SYSTEM_GETTY_PORT) and links so openrc
  starts service.

* package/skeleton-init-openrc/skeleton/etc/init.d/getty
  openrc service that spawns getty on configured port.

* system/Config.in
  change dependency of BR2_TARGET_GENERIC_GETTY_TERM and
  BR2_TARGET_GENERIC_GETTY_OPTIONS so openrc can make use
  of these fields too.

Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>

---
Changes v1 -> v2
  None
---
 package/openrc/openrc.mk                      | 13 ++++++++
 .../skeleton/etc/conf.d/.empty                |  0
 .../skeleton/etc/init.d/getty                 | 31 +++++++++++++++++++
 .../skeleton/etc/runlevels/default/.empty     |  0
 system/Config.in                              |  8 ++---
 5 files changed, 48 insertions(+), 4 deletions(-)
 create mode 100644 package/skeleton-init-openrc/skeleton/etc/conf.d/.empty
 create mode 100755 package/skeleton-init-openrc/skeleton/etc/init.d/getty
 create mode 100644 package/skeleton-init-openrc/skeleton/etc/runlevels/default/.empty

Comments

Thomas Petazzoni May 18, 2019, 9:20 p.m. UTC | #1
Hello,

On Sun, 12 May 2019 21:55:41 +0200
Michał Łyszczek <michal.lyszczek@bofc.pl> wrote:

> diff --git a/package/openrc/openrc.mk b/package/openrc/openrc.mk
> index 53f2947dcc..0feea22818 100644
> --- a/package/openrc/openrc.mk
> +++ b/package/openrc/openrc.mk
> @@ -42,4 +42,17 @@ define OPENRC_REMOVE_UNNEEDED
>  endef
>  OPENRC_TARGET_FINALIZE_HOOKS += OPENRC_REMOVE_UNNEEDED
>  
> +ifeq ($(BR2_TARGET_GENERIC_GETTY),y)
> +GETTY_SVCNAME = getty.$(SYSTEM_GETTY_PORT)
> +GETTY_CONF_D = $(TARGET_DIR)/etc/conf.d/$(GETTY_SVCNAME)

The namespace of variables is global, so all variables defined by a
package must be prefixed by the package name, here OPENRC_.

> +define OPENRC_SET_GETTY
> +	echo "baud=\"$(SYSTEM_GETTY_BAUDRATE)\"" > $(GETTY_CONF_D)
> +	echo "term_type=\"$(SYSTEM_GETTY_TERM)\"" >> $(GETTY_CONF_D)
> +	echo "getty_options=\"-L $(SYSTEM_GETTY_OPTIONS)\"" >> $(GETTY_CONF_D)
> +	ln -sf getty $(TARGET_DIR)/etc/init.d/$(GETTY_SVCNAME)
> +	ln -sf /etc/init.d/$(GETTY_SVCNAME) $(TARGET_DIR)/etc/runlevels/default/$(GETTY_SVCNAME)
> +endef
> +OPENRC_TARGET_FINALIZE_HOOKS += OPENRC_SET_GETTY
> +endif # BR2_TARGET_GENERIC_GETTY
> +
>  $(eval $(generic-package))
> diff --git a/package/skeleton-init-openrc/skeleton/etc/conf.d/.empty b/package/skeleton-init-openrc/skeleton/etc/conf.d/.empty
> new file mode 100644
> index 0000000000..e69de29bb2
> diff --git a/package/skeleton-init-openrc/skeleton/etc/init.d/getty b/package/skeleton-init-openrc/skeleton/etc/init.d/getty
> new file mode 100755
> index 0000000000..acae1b218b
> --- /dev/null
> +++ b/package/skeleton-init-openrc/skeleton/etc/init.d/getty

I am not sure: should this be part of the OpenRC skeleton package ? Or
the OpenRC package itself ?

Thomas
Michał Łyszczek May 19, 2019, 8:32 a.m. UTC | #2
Hello Thomas
On 2019-05-18 23:20:16, Thomas Petazzoni wrote:
> Hello,
> 
> On Sun, 12 May 2019 21:55:41 +0200
> Michał Łyszczek <michal.lyszczek@bofc.pl> wrote:
> 
> > diff --git a/package/openrc/openrc.mk b/package/openrc/openrc.mk
> > index 53f2947dcc..0feea22818 100644
> > --- a/package/openrc/openrc.mk
> > +++ b/package/openrc/openrc.mk
> > @@ -42,4 +42,17 @@ define OPENRC_REMOVE_UNNEEDED
> >  endef
> >  OPENRC_TARGET_FINALIZE_HOOKS += OPENRC_REMOVE_UNNEEDED
> >  
> > +ifeq ($(BR2_TARGET_GENERIC_GETTY),y)
> > +GETTY_SVCNAME = getty.$(SYSTEM_GETTY_PORT)
> > +GETTY_CONF_D = $(TARGET_DIR)/etc/conf.d/$(GETTY_SVCNAME)
> 
> The namespace of variables is global, so all variables defined by a
> package must be prefixed by the package name, here OPENRC_.

Right, didn't know that, thanks. Will fix.

> > +define OPENRC_SET_GETTY
> > +	echo "baud=\"$(SYSTEM_GETTY_BAUDRATE)\"" > $(GETTY_CONF_D)
> > +	echo "term_type=\"$(SYSTEM_GETTY_TERM)\"" >> $(GETTY_CONF_D)
> > +	echo "getty_options=\"-L $(SYSTEM_GETTY_OPTIONS)\"" >> $(GETTY_CONF_D)
> > +	ln -sf getty $(TARGET_DIR)/etc/init.d/$(GETTY_SVCNAME)
> > +	ln -sf /etc/init.d/$(GETTY_SVCNAME) $(TARGET_DIR)/etc/runlevels/default/$(GETTY_SVCNAME)
> > +endef
> > +OPENRC_TARGET_FINALIZE_HOOKS += OPENRC_SET_GETTY
> > +endif # BR2_TARGET_GENERIC_GETTY
> > +
> >  $(eval $(generic-package))
> > diff --git a/package/skeleton-init-openrc/skeleton/etc/conf.d/.empty b/package/skeleton-init-openrc/skeleton/etc/conf.d/.empty
> > new file mode 100644
> > index 0000000000..e69de29bb2
> > diff --git a/package/skeleton-init-openrc/skeleton/etc/init.d/getty b/package/skeleton-init-openrc/skeleton/etc/init.d/getty
> > new file mode 100755
> > index 0000000000..acae1b218b
> > --- /dev/null
> > +++ b/package/skeleton-init-openrc/skeleton/etc/init.d/getty
> 
> I am not sure: should this be part of the OpenRC skeleton package ? Or
> the OpenRC package itself ?

All init sysvinit/sysvinit.mk, busybox/busybox.mk systemd/systemd.mk has
BR2_TARGET_GENERIC_GETTY defined in their packages makefile and not
skeleton. It seemed consistent for me.

Patch
diff mbox series

diff --git a/package/openrc/openrc.mk b/package/openrc/openrc.mk
index 53f2947dcc..0feea22818 100644
--- a/package/openrc/openrc.mk
+++ b/package/openrc/openrc.mk
@@ -42,4 +42,17 @@  define OPENRC_REMOVE_UNNEEDED
 endef
 OPENRC_TARGET_FINALIZE_HOOKS += OPENRC_REMOVE_UNNEEDED
 
+ifeq ($(BR2_TARGET_GENERIC_GETTY),y)
+GETTY_SVCNAME = getty.$(SYSTEM_GETTY_PORT)
+GETTY_CONF_D = $(TARGET_DIR)/etc/conf.d/$(GETTY_SVCNAME)
+define OPENRC_SET_GETTY
+	echo "baud=\"$(SYSTEM_GETTY_BAUDRATE)\"" > $(GETTY_CONF_D)
+	echo "term_type=\"$(SYSTEM_GETTY_TERM)\"" >> $(GETTY_CONF_D)
+	echo "getty_options=\"-L $(SYSTEM_GETTY_OPTIONS)\"" >> $(GETTY_CONF_D)
+	ln -sf getty $(TARGET_DIR)/etc/init.d/$(GETTY_SVCNAME)
+	ln -sf /etc/init.d/$(GETTY_SVCNAME) $(TARGET_DIR)/etc/runlevels/default/$(GETTY_SVCNAME)
+endef
+OPENRC_TARGET_FINALIZE_HOOKS += OPENRC_SET_GETTY
+endif # BR2_TARGET_GENERIC_GETTY
+
 $(eval $(generic-package))
diff --git a/package/skeleton-init-openrc/skeleton/etc/conf.d/.empty b/package/skeleton-init-openrc/skeleton/etc/conf.d/.empty
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/package/skeleton-init-openrc/skeleton/etc/init.d/getty b/package/skeleton-init-openrc/skeleton/etc/init.d/getty
new file mode 100755
index 0000000000..acae1b218b
--- /dev/null
+++ b/package/skeleton-init-openrc/skeleton/etc/init.d/getty
@@ -0,0 +1,31 @@ 
+#!/sbin/openrc-run
+# based on agetty service from OpenRC package
+
+description="start getty on terminal"
+supervisor=supervise-daemon
+port="${RC_SVCNAME#*.}"
+term_type="${term_type:-linux}"
+command=/sbin/getty
+command_args_foreground="${getty_options} ${baud} ${port} ${term_type}"
+pidfile="/run/${RC_SVCNAME}.pid"
+
+depend() {
+	# start getty at the very end of init
+	after *
+	keyword -prefix
+}
+
+start_pre() {
+	if [ -z "$port" ]; then
+		eerror "${RC_SVCNAME} cannot be started directly. You must create"
+		eerror "symbolic links to it for the ports you want to start"
+		eerror "agetty on and add those to the appropriate runlevels."
+		return 1
+	else
+		export EINFO_QUIET="${quiet:-yes}"
+	fi
+}
+
+stop_pre() {
+	export EINFO_QUIET="${quiet:-yes}"
+}
diff --git a/package/skeleton-init-openrc/skeleton/etc/runlevels/default/.empty b/package/skeleton-init-openrc/skeleton/etc/runlevels/default/.empty
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/system/Config.in b/system/Config.in
index 808fc070f3..90aa0e52b9 100644
--- a/system/Config.in
+++ b/system/Config.in
@@ -343,16 +343,16 @@  config BR2_TARGET_GENERIC_GETTY_BAUDRATE
 config BR2_TARGET_GENERIC_GETTY_TERM
 	string "TERM environment variable"
 	default "vt100"
-	# currently observed only by busybox and sysvinit
-	depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV
+	# currently observed by all but systemd
+	depends on !BR2_INIT_SYSTEMD
 	help
 	  Specify a TERM type.
 
 config BR2_TARGET_GENERIC_GETTY_OPTIONS
 	string "other options to pass to getty"
 	default ""
-	# currently observed only by busybox and sysvinit
-	depends on BR2_INIT_BUSYBOX || BR2_INIT_SYSV
+	# currently observed by all but systemd
+	depends on !BR2_INIT_SYSTEMD
 	help
 	  Any other flags you want to pass to getty,
 	  Refer to getty --help for details.