Skip to contentSkip to conversation

Allow customization of system default PATH

PATCH New Markus Mayer 2 participants 8 messages Dec 20, 2018 – Dec 31, 2018

lore
Share & tools
lore
#0 lore raw

v3 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 v2:
- Reformat the help section in system/Config.in to stay within the line length limit
- Swap SED and INSTALL commands in skeleton-init-common.mk
- Add Yann's Reviewed-by

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                                     | 10 ++++++++++
 system/skeleton/etc/profile                          |  2 +-
 system/system.mk                                     |  4 ++++
 6 files changed, 23 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 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 | 10 ++++++++++
 system/system.mk |  4 ++++
 2 files changed, 14 insertions(+)
system/Config.in +10 -0
index 0f77b9b6721a..9941807e5d9b 100644
@@ -386,6 +386,16 @@ 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
#2 lore raw

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

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..7d2c68ada308 100644
@@ -20,6 +20,7 @@ define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS
 	$(call SYSTEM_RSYNC,$(SKELETON_INIT_COMMON_PATH),$(TARGET_DIR))
 	$(call SYSTEM_USR_SYMLINKS_OR_DIRS,$(TARGET_DIR))
 	$(call SYSTEM_LIB_SYMLINK,$(TARGET_DIR))
+	$(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)
 endef
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
#5 lore raw

PATCH v3 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
#6 lore raw

PATCH v3 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
#3 lore raw

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

In reply to Markus Mayer

Hello,

Quoted 6 lines · 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.

I am curious about this sentence: why is it "exactly what we want" ?

system/skeleton/etc/profile line 1

Quoted 7 lines
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@

Indeed, the variable assignment was not double quoted before, and now it becomes double quoted:

export PATH="/bin:/sbin:/usr/bin:/usr/sbin"

is what I have in the resulting /etc/profile.

So does "exactly what we want" means "preserves the existing behavior" or means "is better than the existing behavior" for some reason ?

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw

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

Quoted 24 lines · Thomas Petazzoni

Hello,

Quoted 6 lines · 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.

I am curious about this sentence: why is it "exactly what we want" ?

system/skeleton/etc/profile line 1

Quoted 7 lines
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@

Indeed, the variable assignment was not double quoted before, and now it becomes double quoted:

Quoted 6 lines

export PATH="/bin:/sbin:/usr/bin:/usr/sbin"

is what I have in the resulting /etc/profile.

So does "exactly what we want" means "preserves the existing behavior" or means "is better than the existing behavior" for some reason ?

I hadn't actually noticed this difference in quoting, but it does seem like a good idea to have them.

"Exactly what we want" was just meant to indicate that we get a quoted string out of Kconfig, and we can use that quoted string in our code unchanged (explaining why there are no quotes being added in the code and why they aren't being stripped, either).

This can be reworded if you think it is too confusing.

Regards,
-Markus

Quoted 7 lines

Best regards,

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#7 lore raw

v3 cover Allow customization of system default PATH

In reply to Markus Mayer

Hello Markus,

Quoted 5 lines · Markus Mayer

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

Thanks, series applied with minor tweaks to the commit titles, and a minor tweak to the commit log of PATCH 2/4 related to the double quotes addition. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com