diff options
author | Scott Garman <scott.a.garman@intel.com> | 2012-03-22 21:43:42 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-03-23 12:13:08 +0000 |
commit | c9537c52f4a7faef9aa2d23b33bc452aa872068d (patch) | |
tree | 4b05a4611821466b0cfd5c01a4e8eb7bf3ac2f09 | |
parent | c65d82a88ad8dbd27287e94fb62b98017941fb91 (diff) | |
download | poky-c9537c52f4a7faef9aa2d23b33bc452aa872068d.tar.gz |
useradd.bbclass: retry useradd/groupadd commands to avoid lock race issues
A race condition can occur when adding users and groups to the
passwd and group files, causing errors like the following:
ERROR: Function 'useradd_sysroot' failed
Tried to access "/etc/group" but this was locked.
This fix will cause the useradd code to retry the useradd and
groupadd commands up to 10 times (with a 1s sleep in between
attempts) before failing.
This fixes [YOCTO #1794]
(From OE-Core rev: 68c589f1b5ee36f0aff151b728447ffdae14622c)
Signed-off-by: Scott Garman <scott.a.garman@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/useradd.bbclass | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass index 7981a68dff..0bbb371b2a 100644 --- a/meta/classes/useradd.bbclass +++ b/meta/classes/useradd.bbclass | |||
@@ -45,7 +45,23 @@ if test "x$GROUPADD_PARAM" != "x"; then | |||
45 | groupname=`echo "$opts" | awk '{ print $NF }'` | 45 | groupname=`echo "$opts" | awk '{ print $NF }'` |
46 | group_exists=`grep "^$groupname:" $SYSROOT/etc/group || true` | 46 | group_exists=`grep "^$groupname:" $SYSROOT/etc/group || true` |
47 | if test "x$group_exists" = "x"; then | 47 | if test "x$group_exists" = "x"; then |
48 | eval $PSEUDO groupadd $OPT $opts | 48 | count=1 |
49 | while true; do | ||
50 | eval $PSEUDO groupadd $OPT $opts || true | ||
51 | group_exists=`grep "^$groupname:" $SYSROOT/etc/group || true` | ||
52 | if test "x$group_exists" = "x"; then | ||
53 | # File locking issues can require us to retry the command | ||
54 | echo "WARNING: groupadd command did not succeed. Retrying..." | ||
55 | sleep 1 | ||
56 | else | ||
57 | break | ||
58 | fi | ||
59 | count=`expr $count + 1` | ||
60 | if test $count = 11; then | ||
61 | echo "ERROR: tried running groupadd command 10 times without success, giving up" | ||
62 | exit 1 | ||
63 | fi | ||
64 | done | ||
49 | else | 65 | else |
50 | echo "Note: group $groupname already exists, not re-creating it" | 66 | echo "Note: group $groupname already exists, not re-creating it" |
51 | fi | 67 | fi |
@@ -70,7 +86,23 @@ if test "x$USERADD_PARAM" != "x"; then | |||
70 | username=`echo "$opts" | awk '{ print $NF }'` | 86 | username=`echo "$opts" | awk '{ print $NF }'` |
71 | user_exists=`grep "^$username:" $SYSROOT/etc/passwd || true` | 87 | user_exists=`grep "^$username:" $SYSROOT/etc/passwd || true` |
72 | if test "x$user_exists" = "x"; then | 88 | if test "x$user_exists" = "x"; then |
73 | eval $PSEUDO useradd $OPT $opts | 89 | count=1 |
90 | while true; do | ||
91 | eval $PSEUDO useradd $OPT $opts || true | ||
92 | user_exists=`grep "^$username:" $SYSROOT/etc/passwd || true` | ||
93 | if test "x$user_exists" = "x"; then | ||
94 | # File locking issues can require us to retry the command | ||
95 | echo "WARNING: useradd command did not succeed. Retrying..." | ||
96 | sleep 1 | ||
97 | else | ||
98 | break | ||
99 | fi | ||
100 | count=`expr $count + 1` | ||
101 | if test $count = 11; then | ||
102 | echo "ERROR: tried running useradd command 10 times without success, giving up" | ||
103 | exit 1 | ||
104 | fi | ||
105 | done | ||
74 | else | 106 | else |
75 | echo "Note: username $username already exists, not re-creating it" | 107 | echo "Note: username $username already exists, not re-creating it" |
76 | fi | 108 | fi |