V2: Replace retry logic in useradd with flock
cover V2: Replace retry logic in useradd with flock
From: Kai Kang <[email protected]>
V2:
* Use $SYSROOT/etc as flock file
The following changes since commit da13f0bce5d1b3c52f5716ae8d104372a820e5f9:
buildhistory.bbclass: remove out-dated information on request (2016-02-15 17:47:08 +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.7.0
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 randomly.
Use flock to reslove it by using an universal lock file for all the user and group related operations.
[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
@@ -38,6 +38,8 @@ if test "x$D" != "x"; then export PSEUDO_PASSWD="$SYSROOT:${STAGING_DIR_NATIVE}" fi +FLOCK_FILE=$SYSROOT/etc + # If we're not doing a special SSTATE/SYSROOT install # then set the values, otherwise use the environment if test "x$UA_SYSROOT" = "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.7.0
Re: [PATCH 1/1] useradd_base.bbclass: fix simultaneous with flock
Quoted 2 lines · On 16 February 2016 at 07:14, <[email protected]> wrote:
+FLOCK_FILE=$SYSROOT/etc
useradd_base is also used by extrausers.bbclass, so it would be best if useradd_base decided where to use as a lock ($rootdir/${sysconfdir} sounds sensible) instead of expecting that the caller sets FLOCK_FILE and mysteriously failing if it wasn't set.
Also if we're locking and waiting properly instead of using timeouts and loops, can we remove the "does it exist?" check before the operation (eg groupadd -f will exit 0 if the group exists) and after (with proper locking that shouldn't be happening).
Ross
Re: [PATCH 1/1] useradd_base.bbclass: fix simultaneous with flock
Quoted 7 lines · Ross
On 16 February 2016 at 07:14, <[email protected] <mailto:[email protected]>> wrote:
+FLOCK_FILE=$SYSROOT/etc
useradd_baseis also used by extrausers.bbclass, so it would be best ifuseradd_basedecided where to use as a lock ($rootdir/${sysconfdir} sounds sensible) instead of expecting that the caller setsFLOCK_FILEand mysteriously failing if it wasn't set.
OK. Sounds good.
Quoted 2 lines
Also if we're locking and waiting properly instead of using timeouts and loops, can we remove the "does it exist?" check before the operation (eg groupadd -f will exit 0 if the group exists) and after (with proper locking that shouldn't be happening).
I prefer to keep such check. There is more than one case that causes operation error such as pass wrong parameters. The messages are helpful for developers.
Thanks,
Kai
Quoted 2 lines
Ross
Signature · 2 lines
Regards, Neil | Kai Kang
Re: [PATCH 1/1] useradd_base.bbclass: fix simultaneous with flock
Quoted 4 lines · Kang Kai
I prefer to keep such check. There is more than one case that causes operation error such as pass wrong parameters. The messages are helpful for developers.
In that case the groupadd will return an error code. What situations with proper locking will result in groupadd running successfully but the group not being added?
Ross
Re: [PATCH 1/1] useradd_base.bbclass: fix simultaneous with flock
Quoted 9 lines · Ross
On 17 February 2016 at 05:40, Kang Kai <[email protected] <mailto:[email protected]>> wrote:
I prefer to keep such check. There is more than one case that causes operation error such as pass wrong parameters. The messages are helpful for developers.
In that case the groupadd will return an error code. What situations with proper locking will result in groupadd running successfully but the group not being added?
Sorry for late reply.
I think I understand your meanings. V3 will be sent.
--Kai
Quoted 2 lines
Ross
Signature · 2 lines
Regards, Neil | Kai Kang