Skip to contentSkip to conversation

Replace retry logic in useradd with flock

PATCH In review [email protected] 2 participants 4 messages Feb 15, 2016 – Feb 16, 2016

lore
Share & tools
lore
#0 lore raw

cover Replace retry logic in useradd with flock

From: Kai Kang <[email protected]>

Hi Ross,

We met problems that useradd fails to add users. I found it a simultaneous issue, so created this patch.

As a comparison of build time:

Without flock:
1

$ time bitbake core-image-minimal
real    38m8.625s
user    318m43.262s
sys     62m47.710s

2

$ time bitbake core-image-sato
real    54m13.065s
user    587m1.386s
sys     122m16.949s

With flock:
1

$ time bitbake core-image-minimal
real    40m55.178s
user    316m26.576s
sys     58m53.322s

2

$ time bitbake core-image-sato
real    55m11.312s
user    580m16.787s
sys     118m16.385s

The following changes since commit 36b43b233c841b3c09fc17e04686b4b758780963:

lib/oe/terminal: set workdir for konsole terminal (2016-02-14 11:42:19 +0000)

are available in the git repository at:

git://git.pokylinux.org/poky-contrib kangkai/flock
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=kangkai/flock

Kai Kang (1):
useradd_base.bbclass: fix simultaneous with flock

 meta/classes/useradd.bbclass      |   8 +-
 meta/classes/useradd_base.bbclass | 165 ++++++++++----------------------------
 2 files changed, 48 insertions(+), 125 deletions(-)
Signature · 1 line
2.6.1
#1 lore raw

PATCH 1/1 useradd_base.bbclass: fix simultaneous with flock

From: Kai Kang <[email protected]>

When perform useradd during populate sysroot, it locks files passwd.lock and group.lock at same time. And then it meets a dead lock issue.

Use flock to reslove it by using an universal lock file for all the user and group related operations. The lock file is put in image dir /tmp. /tmp will be mounted as a tmpfs, so the lock file will not be visible when boot the target.

[YOCTO #9022]

---
 meta/classes/useradd.bbclass      |   8 +-
 meta/classes/useradd_base.bbclass | 165 ++++++++++----------------------------
 2 files changed, 48 insertions(+), 125 deletions(-)
meta/classes/useradd.bbclass +5 -3
index c960656..db74123 100644
@@ -48,6 +48,8 @@ if test "x$UA_SYSROOT" = "x"; then
 	GROUPMEMS_PARAM="${GROUPMEMS_PARAM}"
 fi
 
+mkdir -p $SYSROOT/tmp
+
 # Perform group additions first, since user additions may depend
 # on these groups existing
 if test "x`echo $GROUPADD_PARAM | tr -d '[:space:]'`" != "x"; then
@@ -57,7 +59,7 @@ if test "x`echo $GROUPADD_PARAM | tr -d '[:space:]'`" != "x"; then
 	opts=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1`
 	remaining=`echo "$GROUPADD_PARAM" | cut -d ';' -f 2-`
 	while test "x$opts" != "x"; do
-		perform_groupadd "$SYSROOT" "$OPT $opts" 10
+		perform_groupadd "$SYSROOT" "$OPT $opts"
 		if test "x$opts" = "x$remaining"; then
 			break
 		fi
@@ -73,7 +75,7 @@ if test "x`echo $USERADD_PARAM | tr -d '[:space:]'`" != "x"; then
 	opts=`echo "$USERADD_PARAM" | cut -d ';' -f 1`
 	remaining=`echo "$USERADD_PARAM" | cut -d ';' -f 2-`
 	while test "x$opts" != "x"; do
-		perform_useradd "$SYSROOT" "$OPT $opts" 10
+		perform_useradd "$SYSROOT" "$OPT $opts"
 		if test "x$opts" = "x$remaining"; then
 			break
 		fi
@@ -89,7 +91,7 @@ if test "x`echo $GROUPMEMS_PARAM | tr -d '[:space:]'`" != "x"; then
 	opts=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 1`
 	remaining=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 2-`
 	while test "x$opts" != "x"; do
-		perform_groupmems "$SYSROOT" "$OPT $opts" 10
+		perform_groupmems "$SYSROOT" "$OPT $opts"
 		if test "x$opts" = "x$remaining"; then
 			break
 		fi
meta/classes/useradd_base.bbclass +43 -122

237 lines not on this page · raw message

Signature · 1 line
2.6.1
#2 lore raw

Re: [PATCH 1/1] useradd_base.bbclass: fix simultaneous with flock

Review

Quoted 3 lines · On 15 February 2016 at 01:59, <[email protected]> wrote:
(quoted diff) +1 -1
+               eval flock -x -w 100 $rootdir/tmp/user-and-group-ops.flock
-c  \'$PSEUDO useradd $opts\' || true

This is a great patch, but why not just flock $rootdir/etc instead of new
file in tmp? Surely images end up being created with
/tmp/user-and-group-ops.flock in them?

Ross

author
#3 lore raw

Re: [PATCH 1/1] useradd_base.bbclass: fix simultaneous with flock

Quoted 9 lines · Ross

On 15 February 2016 at 01:59, <[email protected] <mailto:[email protected]>> wrote:

+ eval flock -x -w 100
$rootdir/tmp/user-and-group-ops.flock -c \'$PSEUDO useradd $opts\' || true

This is a great patch, but why not just flock $rootdir/etc instead of new file in tmp? Surely images end up being created with /tmp/user-and-group-ops.flock in them?

I didn't try to think take a directory as a lock and I'll try it. For the lock file in $rootdir/tmp/, it is ok that /tmp will be remounted and user won't see the lock file.

Thanks,
Kai

Quoted 2 lines

Ross

Signature · 2 lines
Regards,
Neil | Kai Kang