Skip to contentSkip to conversation

Allow customization of system default PATH

PATCH Superseded Markus Mayer 2 participants 11 messages Dec 19, 2018 – Dec 20, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Allow customization of system default PATH

This series introduces a common way of configuring the system's default PATH.

We introduce a Kconfig variable called BR2_SYSTEM_DEFAULT_PATH, which is being used in /etc/profile of the default skeleton and for dropbear and openssh sessions.

Changes since v1:
- only use a single default (independent of BR2_ROOTFS_MERGED_USR)
- add a guard to system/system.mk checking the default path isn't empty
- replace PATH in etc/profile with place-holder @PATH@ and update regex
- use BR2_SYSTEM_DEFAULT_PATH unconditionally for dropbear
- update commit messages that BR2_SYSTEM_DEFAULT_PATH is a Kconfig variable and already quoted (which is what we need)

Markus Mayer (4):
system cfg: introduce option BR2_SYSTEM_DEFAULT_PATH
skeleton: use BR2_SYSTEM_DEFAULT_PATH as default PATH
openssh: use BR2_SYSTEM_DEFAULT_PATH as default PATH
dropbear: use BR2_SYSTEM_DEFAULT_PATH as default PATH

 package/dropbear/dropbear.mk                         | 6 ++++++
 package/openssh/openssh.mk                           | 1 +
 package/skeleton-init-common/skeleton-init-common.mk | 1 +
 system/Config.in                                     | 9 +++++++++
 system/skeleton/etc/profile                          | 2 +-
 system/system.mk                                     | 4 ++++
 6 files changed, 22 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/4 system cfg: introduce option BR2_SYSTEM_DEFAULT_PATH

The configuration option BR2_SYSTEM_DEFAULT_PATH allows the user to override the default path, which can be used by /etc/profile and some system daemons.

It defaults to the value previously hard-coded in /etc/profile. This default should be suitable for most users.

---
 system/Config.in | 9 +++++++++
 system/system.mk | 4 ++++
 2 files changed, 13 insertions(+)
system/Config.in +9 -0
index 0f77b9b6721a..afae487a4bd5 100644
@@ -386,6 +386,15 @@ comment "automatic network configuration via DHCP needs ifupdown or busybox or n
 
 endif # BR2_ROOTFS_SKELETON_DEFAULT
 
+config BR2_SYSTEM_DEFAULT_PATH
+	string "Set the system's default PATH"
+	default "/bin:/sbin:/usr/bin:/usr/sbin"
+	help
+	  Sets the system's default PATH. It is being used in /etc/profile
+	  in the skeleton-init-common package and by some daemons.
+
+	  The default should work in most cases.
+
 config BR2_ENABLE_LOCALE_PURGE
 	bool "Purge unwanted locales"
 	default y
system/system.mk +4 -0
index ca6bf1388f39..8db87cb12930 100644
@@ -86,3 +86,7 @@ define SYSTEM_REMOUNT_ROOT_INITTAB
 	$(SED) '/^[^#].*-o remount,rw \/$$/s~^~#~' $(TARGET_DIR)/etc/inittab
 endef
 endif
+
+ifeq ($(BR_BUILDING)$(BR2_SYSTEM_DEFAULT_PATH),y"")
+$(error BR2_SYSTEM_DEFAULT_PATH can't be empty)
+endif
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 2/4 skeleton: use BR2_SYSTEM_DEFAULT_PATH as default PATH

In reply to Markus Mayer

We substitute the path specified in system/skeleton/etc/profile with the path specified in the configuration variable $(BR2_SYSTEM_DEFAULT_PATH).

$(BR2_SYSTEM_DEFAULT_PATH) is a Kconfig string. So it is already quoted, which is exactly what we want.

---
 package/skeleton-init-common/skeleton-init-common.mk | 1 +
 system/skeleton/etc/profile                          | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
package/skeleton-init-common/skeleton-init-common.mk +1 -0
index e8a052205268..866273bbd7ee 100644
@@ -22,6 +22,7 @@ define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS
 	$(call SYSTEM_LIB_SYMLINK,$(TARGET_DIR))
 	$(INSTALL) -m 0644 support/misc/target-dir-warning.txt \
 		$(TARGET_DIR_WARNING_FILE)
+	$(SED) 's, at PATH@,$(BR2_SYSTEM_DEFAULT_PATH),' $(TARGET_DIR)/etc/profile
 endef
 
 # We don't care much about what goes in staging, as long as it is
system/skeleton/etc/profile +1 -1
index 1255d23ff40d..db29e44920e8 100644
@@ -1,4 +1,4 @@
-export PATH=/bin:/sbin:/usr/bin:/usr/sbin
+export PATH=@PATH@
 
 if [ "$PS1" ]; then
 	if [ "`id -u`" -eq 0 ]; then
Signature · 1 line
2.17.1
#7 lore raw

PATCH v2 3/4 openssh: use BR2_SYSTEM_DEFAULT_PATH as default PATH

In reply to Markus Mayer

We use the configuration option $(BR2_SYSTEM_DEFAULT_PATH) to set the default PATH in OpenSSH sessions.

$(BR2_SYSTEM_DEFAULT_PATH) is a Kconfig string. So it is already quoted, which is exactly what we want.

---
 package/openssh/openssh.mk | 1 +
 1 file changed, 1 insertion(+)
package/openssh/openssh.mk +1 -0
index 07f3e0d663f6..4ee7727fb9e8 100644
@@ -11,6 +11,7 @@ OPENSSH_LICENSE_FILES = LICENCE
 OPENSSH_CONF_ENV = LD="$(TARGET_CC)" LDFLAGS="$(TARGET_CFLAGS)"
 OPENSSH_CONF_OPTS = \
 	--sysconfdir=/etc/ssh \
+	--with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
 	--disable-lastlog \
 	--disable-utmp \
 	--disable-utmpx \
Signature · 1 line
2.17.1
#9 lore raw

PATCH v2 4/4 dropbear: use BR2_SYSTEM_DEFAULT_PATH as default PATH

In reply to Markus Mayer

We use the configuration option $(BR2_SYSTEM_DEFAULT_PATH) to set the default PATH in dropbear sessions.

$(BR2_SYSTEM_DEFAULT_PATH) is a Kconfig string. So it is already quoted, which is exactly what we want.

---
 package/dropbear/dropbear.mk | 6 ++++++
 1 file changed, 6 insertions(+)
package/dropbear/dropbear.mk +6 -0
index 7b1468cfb100..a5a8243bd431 100644
@@ -81,6 +81,12 @@ define DROPBEAR_DISABLE_STANDALONE
 	echo '#define NON_INETD_MODE 0'                 >> $(@D)/localoptions.h
 endef
 
+define DROPBEAR_CUSTOM_PATH
+	echo '#define DEFAULT_PATH $(BR2_SYSTEM_DEFAULT_PATH)' >>$(@D)/localoptions.h
+endef
+
+DROPBEAR_POST_EXTRACT_HOOKS += DROPBEAR_CUSTOM_PATH
+
 define DROPBEAR_INSTALL_INIT_SYSTEMD
 	$(INSTALL) -D -m 644 package/dropbear/dropbear.service \
 		$(TARGET_DIR)/usr/lib/systemd/system/dropbear.service
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 1/4 system cfg: introduce option BR2_SYSTEM_DEFAULT_PATH

In reply to Markus Mayer

Markus, All,

On 2018-12-19 13:04 -0800, Markus Mayer spake thusly:

Quoted 18 lines

The configuration option BR2_SYSTEM_DEFAULT_PATH allows the user to override the default path, which can be used by /etc/profile and some system daemons.

It defaults to the value previously hard-coded in /etc/profile. This default should be suitable for most users.

---
 system/Config.in | 9 +++++++++
 system/system.mk | 4 ++++
 2 files changed, 13 insertions(+)
system/Config.in +0 -0
index 0f77b9b6721a..afae487a4bd5 100644

system/Config.in comment "automatic network configuration via DHCP needs ifupdown or busybox or n · line 393

Quoted 8 lines
system/Config.in +5 -0
@@ -386,6 +386,15 @@ comment "automatic network configuration via DHCP needs ifupdown or busybox or n
 
 endif # BR2_ROOTFS_SKELETON_DEFAULT
 
+config BR2_SYSTEM_DEFAULT_PATH
+	string "Set the system's default PATH"
+	default "/bin:/sbin:/usr/bin:/usr/sbin"
+	help
+	  Sets the system's default PATH. It is being used in /etc/profile

Slight formatting issue here, check-package conplains:

    system/Config.in:393: help text: <tab><2 spaces><62 chars> (http://nightly.buildroot.org/#writing-rules-config-in)

Otherwise (no need to respin, that can be fixed when applying I hope):

Regards,
Yann E. MORIN.

Quoted 22 lines
system/Config.in +4 -0
+	  in the skeleton-init-common package and by some daemons.
+
+	  The default should work in most cases.
+
 config BR2_ENABLE_LOCALE_PURGE
 	bool "Purge unwanted locales"
 	default y
system/system.mk +4 -0
index ca6bf1388f39..8db87cb12930 100644
@@ -86,3 +86,7 @@ define SYSTEM_REMOUNT_ROOT_INITTAB
 	$(SED) '/^[^#].*-o remount,rw \/$$/s~^~#~' $(TARGET_DIR)/etc/inittab
 endef
 endif
+
+ifeq ($(BR_BUILDING)$(BR2_SYSTEM_DEFAULT_PATH),y"")
+$(error BR2_SYSTEM_DEFAULT_PATH can't be empty)
+endif
Signature · 1 line
2.17.1
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#4 lore raw

PATCH v2 2/4 skeleton: use BR2_SYSTEM_DEFAULT_PATH as default PATH

In reply to Markus Mayer

Markus, All,

On 2018-12-19 13:04 -0800, Markus Mayer spake thusly:

Quoted 18 lines

We substitute the path specified in system/skeleton/etc/profile with the path specified in the configuration variable $(BR2_SYSTEM_DEFAULT_PATH).

$(BR2_SYSTEM_DEFAULT_PATH) is a Kconfig string. So it is already quoted, which is exactly what we want.

---
 package/skeleton-init-common/skeleton-init-common.mk | 1 +
 system/skeleton/etc/profile                          | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
package/skeleton-init-common/skeleton-init-common.mk +0 -0
index e8a052205268..866273bbd7ee 100644

package/skeleton-init-common/skeleton-init-common.mk define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS · line 25

Quoted 4 lines
package/skeleton-init-common/skeleton-init-common.mk +1 -0
@@ -22,6 +22,7 @@ define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS
 	$(call SYSTEM_LIB_SYMLINK,$(TARGET_DIR))
 	$(INSTALL) -m 0644 support/misc/target-dir-warning.txt \
 		$(TARGET_DIR_WARNING_FILE)
+	$(SED) 's, at PATH@,$(BR2_SYSTEM_DEFAULT_PATH),' $(TARGET_DIR)/etc/profile

I think we should keep the warning file the last command executed.

Otherwise:

Regards,
Yann E. MORIN.

Quoted 16 lines
package/skeleton-init-common/skeleton-init-common.mk +0 -0
 endef
 
 # We don't care much about what goes in staging, as long as it is
system/skeleton/etc/profile +1 -1
index 1255d23ff40d..db29e44920e8 100644
@@ -1,4 +1,4 @@
-export PATH=/bin:/sbin:/usr/bin:/usr/sbin
+export PATH=@PATH@
 
 if [ "$PS1" ]; then
 	if [ "`id -u`" -eq 0 ]; then
Signature · 1 line
2.17.1
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#8 lore raw

PATCH v2 3/4 openssh: use BR2_SYSTEM_DEFAULT_PATH as default PATH

In reply to Markus Mayer

Markus, All,

On 2018-12-19 13:04 -0800, Markus Mayer spake thusly:

Quoted 7 lines

We use the configuration option $(BR2_SYSTEM_DEFAULT_PATH) to set the default PATH in OpenSSH sessions.

$(BR2_SYSTEM_DEFAULT_PATH) is a Kconfig string. So it is already quoted, which is exactly what we want.

Regards,
Yann E. MORIN.

Quoted 19 lines
---
 package/openssh/openssh.mk | 1 +
 1 file changed, 1 insertion(+)
package/openssh/openssh.mk +1 -0
index 07f3e0d663f6..4ee7727fb9e8 100644
@@ -11,6 +11,7 @@ OPENSSH_LICENSE_FILES = LICENCE
 OPENSSH_CONF_ENV = LD="$(TARGET_CC)" LDFLAGS="$(TARGET_CFLAGS)"
 OPENSSH_CONF_OPTS = \
 	--sysconfdir=/etc/ssh \
+	--with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
 	--disable-lastlog \
 	--disable-utmp \
 	--disable-utmpx \
Signature · 1 line
2.17.1
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#10 lore raw

PATCH v2 4/4 dropbear: use BR2_SYSTEM_DEFAULT_PATH as default PATH

In reply to Markus Mayer

Markus, All,

On 2018-12-19 13:04 -0800, Markus Mayer spake thusly:

Quoted 7 lines

We use the configuration option $(BR2_SYSTEM_DEFAULT_PATH) to set the default PATH in dropbear sessions.

$(BR2_SYSTEM_DEFAULT_PATH) is a Kconfig string. So it is already quoted, which is exactly what we want.

Regards,
Yann E. MORIN.

Quoted 24 lines
---
 package/dropbear/dropbear.mk | 6 ++++++
 1 file changed, 6 insertions(+)
package/dropbear/dropbear.mk +6 -0
index 7b1468cfb100..a5a8243bd431 100644
@@ -81,6 +81,12 @@ define DROPBEAR_DISABLE_STANDALONE
 	echo '#define NON_INETD_MODE 0'                 >> $(@D)/localoptions.h
 endef
 
+define DROPBEAR_CUSTOM_PATH
+	echo '#define DEFAULT_PATH $(BR2_SYSTEM_DEFAULT_PATH)' >>$(@D)/localoptions.h
+endef
+
+DROPBEAR_POST_EXTRACT_HOOKS += DROPBEAR_CUSTOM_PATH
+
 define DROPBEAR_INSTALL_INIT_SYSTEMD
 	$(INSTALL) -D -m 644 package/dropbear/dropbear.service \
 		$(TARGET_DIR)/usr/lib/systemd/system/dropbear.service
Signature · 1 line
2.17.1
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

PATCH v2 2/4 skeleton: use BR2_SYSTEM_DEFAULT_PATH as default PATH

In reply to Yann E. MORIN

Hi Yann,

Quoted 14 lines · Yann E. MORIN

Markus, All,

package/skeleton-init-common/skeleton-init-common.mk define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS · line 25

Quoted 9 lines
package/skeleton-init-common/skeleton-init-common.mk +1 -0
index e8a052205268..866273bbd7ee 100644
@@ -22,6 +22,7 @@ define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS
      $(call SYSTEM_LIB_SYMLINK,$(TARGET_DIR))
      $(INSTALL) -m 0644 support/misc/target-dir-warning.txt \
              $(TARGET_DIR_WARNING_FILE)
+     $(SED) 's, at PATH@,$(BR2_SYSTEM_DEFAULT_PATH),' $(TARGET_DIR)/etc/profile

I think we should keep the warning file the last command executed.

I am not sure I am following. I am not doing anything to target-dir-warning.txt.

Quoted 6 lines

Otherwise:

Regards,
Yann E. MORIN.

Thanks,
-Markus

#6 lore raw

PATCH v2 2/4 skeleton: use BR2_SYSTEM_DEFAULT_PATH as default PATH

Markus, All,

On 2018-12-19 15:24 -0800, Markus Mayer spake thusly:

Quoted 11 lines · Yann E. MORIN
Quoted 10 lines

package/skeleton-init-common/skeleton-init-common.mk define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS · line 25

Quoted 9 lines
package/skeleton-init-common/skeleton-init-common.mk +1 -0
index e8a052205268..866273bbd7ee 100644
@@ -22,6 +22,7 @@ define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS
      $(call SYSTEM_LIB_SYMLINK,$(TARGET_DIR))
      $(INSTALL) -m 0644 support/misc/target-dir-warning.txt \
              $(TARGET_DIR_WARNING_FILE)
+     $(SED) 's, at PATH@,$(BR2_SYSTEM_DEFAULT_PATH),' $(TARGET_DIR)/etc/profile

I think we should keep the warning file the last command executed.

Quoted 1 line

I am not sure I am following. I am not doing anything to target-dir-warning.txt.

Just put your sed command before the warning file:

    $(SED) 's, at PATH@,$(BR2_SYSTEM_DEFAULT_PATH),' $(TARGET_DIR)/etc/profile
    $(INSTALL) -m 0644 support/misc/target-dir-warning.txt \
            $(TARGET_DIR_WARNING_FILE)

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'