Patchwork [V2,4/5] populate-volatile.sh: improve the handling of link config items

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date Feb. 20, 2013, 5:55 a.m.
Message ID <5ef28960f6e00cda4b04bbe53399053704921d2d.1361338900.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/44895/
State New
Headers show

Comments

Qi.Chen@windriver.com - Feb. 20, 2013, 5:55 a.m.
From: Chen Qi <Qi.Chen@windriver.com>

Previously, if there's a link config item in the config file like

	    l root root 1777 /tmp /var/tmp

and /tmp has existed, the symlink will not be created correctly.

Another example is the /run directory. If /run directory has been
created by some recipe or script before populate-volatile.sh runs,
the symlink of /run to /var/run will not be created correctly.

This patch ensures that the system creates symlinks exactly as the
config file tells it.

[YOCTO #3404]
[YOCTO #3406]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 .../initscripts-1.0/populate-volatile.sh           |   37 +++++++++++---------
 1 file changed, 21 insertions(+), 16 deletions(-)
Bernhard Reutner-Fischer - Feb. 20, 2013, 7:10 a.m.
On 20 February 2013 06:55:33 <Qi.Chen@windriver.com> wrote:
> From: Chen Qi <Qi.Chen@windriver.com>
>
> Previously, if there's a link config item in the config file like
>
> 	    l root root 1777 /tmp /var/tmp
>
> and /tmp has existed, the symlink will not be created correctly.
>
> Another example is the /run directory. If /run directory has been
> created by some recipe or script before populate-volatile.sh runs,
> the symlink of /run to /var/run will not be created correctly.
>
> This patch ensures that the system creates symlinks exactly as the
> config file tells it.

This one also has bugs in background handling, it seems.
Can't you massage stderr redirection when setting EXIT instead?
>
> [YOCTO #3404]
> [YOCTO #3406]
>


Sent with AquaMail for Android
http://www.aqua-mail.com
Qi.Chen@windriver.com - Feb. 20, 2013, 7:16 a.m.
On 02/20/2013 03:10 PM, Bernhard Reutner-Fischer wrote:
> On 20 February 2013 06:55:33 <Qi.Chen@windriver.com> wrote:
>> From: Chen Qi <Qi.Chen@windriver.com>
>>
>> Previously, if there's a link config item in the config file like
>>
>>         l root root 1777 /tmp /var/tmp
>>
>> and /tmp has existed, the symlink will not be created correctly.
>>
>> Another example is the /run directory. If /run directory has been
>> created by some recipe or script before populate-volatile.sh runs,
>> the symlink of /run to /var/run will not be created correctly.
>>
>> This patch ensures that the system creates symlinks exactly as the
>> config file tells it.
>
> This one also has bugs in background handling, it seems.

What's the bug?

> Can't you massage stderr redirection when setting EXIT instead?

Could you please be more specific?

>>
>> [YOCTO #3404]
>> [YOCTO #3406]
>>
>
>
> Sent with AquaMail for Android
> http://www.aqua-mail.com
>
>
>
>
Bernhard Reutner-Fischer - Feb. 20, 2013, 9:18 a.m.
On 20 February 2013 08:16, ChenQi <Qi.Chen@windriver.com> wrote:
> On 02/20/2013 03:10 PM, Bernhard Reutner-Fischer wrote:
>>
>> On 20 February 2013 06:55:33 <Qi.Chen@windriver.com> wrote:
>>>
>>> From: Chen Qi <Qi.Chen@windriver.com>
>>>
>>> Previously, if there's a link config item in the config file like
>>>
>>>         l root root 1777 /tmp /var/tmp
>>>
>>> and /tmp has existed, the symlink will not be created correctly.
>>>
>>> Another example is the /run directory. If /run directory has been
>>> created by some recipe or script before populate-volatile.sh runs,
>>> the symlink of /run to /var/run will not be created correctly.
>>>
>>> This patch ensures that the system creates symlinks exactly as the
>>> config file tells it.
>>
>>
>> This one also has bugs in background handling, it seems.
>
>
> What's the bug?

-                               link_file "${TSOURCE}" "${TNAME}" &
-                       }
+                       [ "${VERBOSE}" != "no" ] && echo "Creating
link -${TNAME}- pointing to -${TSOURCE}-."
+                       link_file "${TSOURCE}" "${TNAME}"

missing '&' after the link_file.
>
>
>> Can't you massage stderr redirection when setting EXIT instead?
>
>
> Could you please be more specific?
I meant EXEC.
Can't you put the > /dev/null 2>&1 into the relevant parts of _all_
the EXEC instead, in the whole series?


>>> [YOCTO #3404]
>>> [YOCTO #3406]
Qi.Chen@windriver.com - Feb. 20, 2013, 9:28 a.m.
On 02/20/2013 05:18 PM, Bernhard Reutner-Fischer wrote:
> On 20 February 2013 08:16, ChenQi <Qi.Chen@windriver.com> wrote:
>> On 02/20/2013 03:10 PM, Bernhard Reutner-Fischer wrote:
>>> On 20 February 2013 06:55:33 <Qi.Chen@windriver.com> wrote:
>>>> From: Chen Qi <Qi.Chen@windriver.com>
>>>>
>>>> Previously, if there's a link config item in the config file like
>>>>
>>>>          l root root 1777 /tmp /var/tmp
>>>>
>>>> and /tmp has existed, the symlink will not be created correctly.
>>>>
>>>> Another example is the /run directory. If /run directory has been
>>>> created by some recipe or script before populate-volatile.sh runs,
>>>> the symlink of /run to /var/run will not be created correctly.
>>>>
>>>> This patch ensures that the system creates symlinks exactly as the
>>>> config file tells it.
>>>
>>> This one also has bugs in background handling, it seems.
>>
>> What's the bug?
> -                               link_file "${TSOURCE}" "${TNAME}" &
> -                       }
> +                       [ "${VERBOSE}" != "no" ] && echo "Creating
> link -${TNAME}- pointing to -${TSOURCE}-."
> +                       link_file "${TSOURCE}" "${TNAME}"
>
> missing '&' after the link_file.
Thanks. I'll resend out this patch.

>>
>>> Can't you massage stderr redirection when setting EXIT instead?
>>
>> Could you please be more specific?
> I meant EXEC.
> Can't you put the > /dev/null 2>&1 into the relevant parts of _all_
> the EXEC instead, in the whole series?
>
I don't think so :(
Only in case of running at rootfs time can we ignore the errors.

Best Regards,
Chen Qi

>>>> [YOCTO #3404]
>>>> [YOCTO #3406]
>

Patch

diff --git a/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh b/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh
index c4bf70e..24daeb4 100755
--- a/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh
+++ b/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh
@@ -68,20 +68,27 @@  mk_dir() {
 }
 
 link_file() {
-	EXEC="test -e \"$2\" -o -L $2 || ln -s \"$1\" \"$2\" >/dev/tty0 2>&1" 
+	EXEC="
+	if [ -L \"$2\" ]; then
+		[ \"\$(readlink -f \"$2\")\" != \"\$(readlink -f \"$1\")\" ] && { rm -f \"$2\"; ln -sf \"$1\" \"$2\"; };
+	elif [ -d \"$2\" ]; then
+		for f in $2/* $2/.[^.]*; do [ -e \$f ] && cp -rf \$f $1; done;
+		rm -rf \"$2\";
+		ln -sf \"$1\" \"$2\";
+	else
+		ln -sf \"$1\" \"$2\";
+	fi
+        "
 
 	test "$VOLATILE_ENABLE_CACHE" = yes && echo "	$EXEC" >> /etc/volatile.cache.build
-	[ -e "$2" ] && {
-		echo "Cannot create link over existing -${TNAME}-." >&2
-	} || {
-		if [ "$ROOT_DIR" = "/" ]; then
-			eval $EXEC &
-		else
-			# For the same reason with create_file(), failures should
-			# not be logged.
-			eval $EXEC > /dev/null 2>&1 &
-		fi
-	}
+
+	if [ "$ROOT_DIR" = "/" ]; then
+		eval $EXEC &
+	else
+		# For the same reason with create_file(), failures should
+		# not be logged.
+		eval $EXEC > /dev/null 2>&1 &
+	fi
 }
 
 check_requirements() {
@@ -148,10 +155,8 @@  apply_cfgfile() {
 
 		[ "${TTYPE}" = "l" ] && {
 			TSOURCE="$TLTARGET"
-			[ -L "${TNAME}" ] || {
-				[ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
-				link_file "${TSOURCE}" "${TNAME}" &
-			}
+			[ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
+			link_file "${TSOURCE}" "${TNAME}"
 			continue
 		}