Skip to contentSkip to conversation

initramfs: fix symlink test

PATCH New Mike Frysinger 4 participants 5 messages Nov 16, 2010 – Nov 17, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 initramfs: fix symlink test

We want to see if the symlink exists which means -L, not if the target of the symlink exists.

---
 fs/initramfs/initramfs.mk |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/initramfs/initramfs.mk +2 -2
index dd6aa94..594cc34 100644
@@ -7,7 +7,7 @@
 #############################################################
 
 define ROOTFS_INITRAMFS_INIT_SYMLINK
-	if [ ! -e $(TARGET_DIR)/init ]; then \
+	if [ ! -L $(TARGET_DIR)/init ]; then \
 		ln -s sbin/init $(TARGET_DIR)/init; \
 	fi
 endef
@@ -20,4 +20,4 @@ endef
 
 ROOTFS_INITRAMFS_POST_TARGETS += linux26-rebuild-with-initramfs
 
-$(eval $(call ROOTFS_TARGET,initramfs))
\ No newline at end of file
+$(eval $(call ROOTFS_TARGET,initramfs))
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH 1/1 initramfs: fix symlink test

Quoted 4 lines · On Tue, 16 Nov 2010 09:58:46 -0500 Mike Frysinger <[email protected]> wrote:

We want to see if the symlink exists which means -L, not if the target of the symlink exists.

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#2 lore raw

PATCH 1/1 initramfs: fix symlink test

In reply to Mike Frysinger

Am Dienstag, 16. November 2010, 15:58:46 schrieb Mike Frysinger:

Quoted 22 lines

We want to see if the symlink exists which means -L, not if the target of the symlink exists.

---
 fs/initramfs/initramfs.mk |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/initramfs/initramfs.mk +1 -1
index dd6aa94..594cc34 100644
@@ -7,7 +7,7 @@
 #############################################################
 
 define ROOTFS_INITRAMFS_INIT_SYMLINK
-	if [ ! -e $(TARGET_DIR)/init ]; then \
+	if [ ! -L $(TARGET_DIR)/init ]; then \
 		ln -s sbin/init $(TARGET_DIR)/init; \
 	fi
 endef

fs/initramfs/initramfs.mk endef · line 23

Quoted 6 lines
fs/initramfs/initramfs.mk +1 -1
@@ -20,4 +20,4 @@ endef
 
 ROOTFS_INITRAMFS_POST_TARGETS += linux26-rebuild-with-initramfs
 
-$(eval $(call ROOTFS_TARGET,initramfs))
\ No newline at end of file
+$(eval $(call ROOTFS_TARGET,initramfs))

Ack for not testing if the link target exists, but what if $(TARGET_DIR)/init exists but is not a symlink? My custom skeleton contains an /init shell script? or is that considered unsupported?
Maybe something along the lines of
[ ! -e $(TARGET_DIR)/init -a ! -L $(TARGET_DIR)/init ]
?

Regards,
Malte

#3 lore raw

PATCH v2 1/1 initramfs: fix init symlink creation

In reply to Mike Frysinger

The -e test will dereference the symlink, so if there is no /bin/init, we will constantly try to create the symlink. So rather than error on subsequent runs when the link exists, use the force flag to ln.

---
v2
- drop the -L change and just recreate the symlink for people who install their own file at /init

 fs/initramfs/initramfs.mk |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/initramfs/initramfs.mk +2 -2
index dd6aa94..73122a8 100644
@@ -8,7 +8,7 @@
 
 define ROOTFS_INITRAMFS_INIT_SYMLINK
 	if [ ! -e $(TARGET_DIR)/init ]; then \
-		ln -s sbin/init $(TARGET_DIR)/init; \
+		ln -sf sbin/init $(TARGET_DIR)/init; \
 	fi
 endef
 
@@ -20,4 +20,4 @@ endef
 
 ROOTFS_INITRAMFS_POST_TARGETS += linux26-rebuild-with-initramfs
 
-$(eval $(call ROOTFS_TARGET,initramfs))
\ No newline at end of file
+$(eval $(call ROOTFS_TARGET,initramfs))
Signature · 1 line
1.7.3.2
#4 lore raw

PATCH v2 1/1 initramfs: fix init symlink creation

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Mike" == Mike Frysinger <[email protected]> writes:

Mike> The -e test will dereference the symlink, so if there is no /bin/init, Mike> we will constantly try to create the symlink. So rather than error on Mike> subsequent runs when the link exists, use the force flag to ln.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard