All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kang Kai <Kai.Kang@windriver.com>
To: Khem Raj <raj.khem@gmail.com>
Cc: Patches and discussions about the oe-core layer
	<openembedded-core@lists.openembedded.org>
Subject: Re: [PATCH 1/1] useradd_base.bbclass: fix simultaneous with flock
Date: Tue, 23 Feb 2016 11:35:10 +0800	[thread overview]
Message-ID: <56CBD36E.8020908@windriver.com> (raw)
In-Reply-To: <CAMKF1spcmUmc-FA1e9wdwki4=Dm14xY5Dw=+thvZAAkZe10fsA@mail.gmail.com>

On 2016年02月23日 11:05, Khem Raj wrote:
> Patch subject is unclear. Patch itself looks ok

How about use the  title of Yocto #9022:

useradd_base.bbclass: replace retry logic with flock


Thanks,
Kai



>
> On Mon, Feb 22, 2016 at 9:45 PM,  <kai.kang@windriver.com> wrote:
>> From: Kai Kang <kai.kang@windriver.com>
>>
>> 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]
>>
>> Signed-off-by: Kai Kang <kai.kang@windriver.com>
>> ---
>>   meta/classes/useradd.bbclass      |   6 +-
>>   meta/classes/useradd_base.bbclass | 186 ++++++++------------------------------
>>   2 files changed, 40 insertions(+), 152 deletions(-)
>>
>> diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
>> index c960656..0a6f2be 100644
>> --- a/meta/classes/useradd.bbclass
>> +++ b/meta/classes/useradd.bbclass
>> @@ -57,7 +57,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 +73,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 +89,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
>> diff --git a/meta/classes/useradd_base.bbclass b/meta/classes/useradd_base.bbclass
>> index ab3cd35..7c1cc13 100644
>> --- a/meta/classes/useradd_base.bbclass
>> +++ b/meta/classes/useradd_base.bbclass
>> @@ -4,7 +4,7 @@
>>
>>   # The following functions basically have similar logic.
>>   # *) Perform necessary checks before invoking the actual command
>> -# *) Invoke the actual command, make retries if necessary
>> +# *) Invoke the actual command with flock
>>   # *) Error out if an error occurs.
>>
>>   # Note that before invoking these functions, make sure the global variable
>> @@ -12,65 +12,32 @@
>>
>>   perform_groupadd () {
>>          local rootdir="$1"
>> -       local opts="$2"
>> -       local retries="$3"
>> -       bbnote "${PN}: Performing groupadd with [$opts] and $retries times of retry"
>> +       local opts=`echo $2 | sed s/\'/\"/g`
>> +       bbnote "${PN}: Performing groupadd with [$opts]"
>> +       eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO groupadd $opts\' || true
>>          local groupname=`echo "$opts" | awk '{ print $NF }'`
>> -       local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
>> +       local group_exists=`grep "^$groupname:" $rootdir/etc/group`
>>          if test "x$group_exists" = "x"; then
>> -               local count=0
>> -               while true; do
>> -                       eval $PSEUDO groupadd $opts || true
>> -                       group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
>> -                       if test "x$group_exists" = "x"; then
>> -                               bbwarn "${PN}: groupadd command did not succeed. Retrying..."
>> -                       else
>> -                               break
>> -                       fi
>> -                       count=`expr $count + 1`
>> -                       if test $count = $retries; then
>> -                               bbfatal "${PN}: Tried running groupadd command $retries times without success, giving up"
>> -                       fi
>> -                        sleep $count
>> -               done
>> -       else
>> -               bbnote "${PN}: group $groupname already exists, not re-creating it"
>> +               bbfatal "${PN}: groupadd command did not succeed."
>>          fi
>>   }
>>
>>   perform_useradd () {
>>          local rootdir="$1"
>> -       local opts="$2"
>> -       local retries="$3"
>> -       bbnote "${PN}: Performing useradd with [$opts] and $retries times of retry"
>> +       local opts=`echo $2 | sed s/\'/\"/g`
>> +       bbnote "${PN}: Performing useradd with [$opts]"
>> +       eval flock -x -w 100 $rootdir${sysconfdir} -c  \'$PSEUDO useradd $opts\' || true
>>          local username=`echo "$opts" | awk '{ print $NF }'`
>> -       local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
>> +       local user_exists=`grep "^$username:" $rootdir/etc/passwd`
>>          if test "x$user_exists" = "x"; then
>> -              local count=0
>> -              while true; do
>> -                      eval $PSEUDO useradd $opts || true
>> -                      user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
>> -                      if test "x$user_exists" = "x"; then
>> -                              bbwarn "${PN}: useradd command did not succeed. Retrying..."
>> -                      else
>> -                              break
>> -                      fi
>> -                      count=`expr $count + 1`
>> -                      if test $count = $retries; then
>> -                               bbfatal "${PN}: Tried running useradd command $retries times without success, giving up"
>> -                      fi
>> -                      sleep $count
>> -              done
>> -       else
>> -               bbnote "${PN}: user $username already exists, not re-creating it"
>> +               bbfatal "${PN}: useradd command did not succeed."
>>          fi
>>   }
>>
>>   perform_groupmems () {
>>          local rootdir="$1"
>>          local opts="$2"
>> -       local retries="$3"
>> -       bbnote "${PN}: Performing groupmems with [$opts] and $retries times of retry"
>> +       bbnote "${PN}: Performing groupmems with [$opts]"
>>          local groupname=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-g" || $i == "--group") print $(i+1) }'`
>>          local username=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-a" || $i == "--add") print $(i+1) }'`
>>          bbnote "${PN}: Running groupmems command with group $groupname and user $username"
>> @@ -82,30 +49,13 @@ perform_groupmems () {
>>                  gshadow="no"
>>                  touch $rootdir${sysconfdir}/gshadow
>>          fi
>> -       local mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`"
>> +
>> +       eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO groupmems $opts\' || true
>> +       local mem_exists=`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group`
>>          if test "x$mem_exists" = "x"; then
>> -               local count=0
>> -               while true; do
>> -                       eval $PSEUDO groupmems $opts || true
>> -                       mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`"
>> -                       if test "x$mem_exists" = "x"; then
>> -                               bbwarn "${PN}: groupmems command did not succeed. Retrying..."
>> -                       else
>> -                               break
>> -                       fi
>> -                       count=`expr $count + 1`
>> -                       if test $count = $retries; then
>> -                               if test "x$gshadow" = "xno"; then
>> -                                       rm -f $rootdir${sysconfdir}/gshadow
>> -                                       rm -f $rootdir${sysconfdir}/gshadow-
>> -                               fi
>> -                               bbfatal "${PN}: Tried running groupmems command $retries times without success, giving up"
>> -                       fi
>> -                       sleep $count
>> -               done
>> -       else
>> -               bbnote "${PN}: group $groupname already contains $username, not re-adding it"
>> +               bbfatal "${PN}: groupmems command did not succeed."
>>          fi
>> +
>>          if test "x$gshadow" = "xno"; then
>>                  rm -f $rootdir${sysconfdir}/gshadow
>>                  rm -f $rootdir${sysconfdir}/gshadow-
>> @@ -115,56 +65,24 @@ perform_groupmems () {
>>   perform_groupdel () {
>>          local rootdir="$1"
>>          local opts="$2"
>> -       local retries="$3"
>> -       bbnote "${PN}: Performing groupdel with [$opts] and $retries times of retry"
>> +       bbnote "${PN}: Performing groupdel with [$opts]"
>> +       eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO groupdel $opts\' || true
>>          local groupname=`echo "$opts" | awk '{ print $NF }'`
>> -       local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
>> +       local group_exists=`grep "^$groupname:" $rootdir/etc/group`
>>          if test "x$group_exists" != "x"; then
>> -               local count=0
>> -               while true; do
>> -                       eval $PSEUDO groupdel $opts || true
>> -                       group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
>> -                       if test "x$group_exists" != "x"; then
>> -                               bbwarn "${PN}: groupdel command did not succeed. Retrying..."
>> -                       else
>> -                               break
>> -                       fi
>> -                       count=`expr $count + 1`
>> -                       if test $count = $retries; then
>> -                               bbfatal "${PN}: Tried running groupdel command $retries times without success, giving up"
>> -                       fi
>> -                       sleep $count
>> -               done
>> -       else
>> -               bbnote "${PN}: group $groupname doesn't exist, not removing it"
>> +               bbfatal "${PN}: groupdel command did not succeed."
>>          fi
>>   }
>>
>>   perform_userdel () {
>>          local rootdir="$1"
>>          local opts="$2"
>> -       local retries="$3"
>> -       bbnote "${PN}: Performing userdel with [$opts] and $retries times of retry"
>> +       bbnote "${PN}: Performing userdel with [$opts]"
>> +       eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO userdel $opts\' || true
>>          local username=`echo "$opts" | awk '{ print $NF }'`
>> -       local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
>> +       local user_exists=`grep "^$username:" $rootdir/etc/passwd`
>>          if test "x$user_exists" != "x"; then
>> -              local count=0
>> -              while true; do
>> -                      eval $PSEUDO userdel $opts || true
>> -                      user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
>> -                      if test "x$user_exists" != "x"; then
>> -                              bbwarn "${PN}: userdel command did not succeed. Retrying..."
>> -                      else
>> -                              break
>> -                      fi
>> -                      count=`expr $count + 1`
>> -                      if test $count = $retries; then
>> -                               bbfatal "${PN}: Tried running userdel command $retries times without success, giving up"
>> -                      fi
>> -                      sleep $count
>> -              done
>> -       else
>> -               bbnote "${PN}: user $username doesn't exist, not removing it"
>> +               bbfatal "${PN}: userdel command did not succeed."
>>          fi
>>   }
>>
>> @@ -172,59 +90,29 @@ perform_groupmod () {
>>          # Other than the return value of groupmod, there's no simple way to judge whether the command
>>          # succeeds, so we disable -e option temporarily
>>          set +e
>> +
>>          local rootdir="$1"
>>          local opts="$2"
>> -       local retries="$3"
>> -       bbnote "${PN}: Performing groupmod with [$opts] and $retries times of retry"
>> -       local groupname=`echo "$opts" | awk '{ print $NF }'`
>> -       local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
>> -       if test "x$group_exists" != "x"; then
>> -               local count=0
>> -               while true; do
>> -                       eval $PSEUDO groupmod $opts
>> -                       if test $? != 0; then
>> -                               bbwarn "${PN}: groupmod command did not succeed. Retrying..."
>> -                       else
>> -                               break
>> -                       fi
>> -                       count=`expr $count + 1`
>> -                       if test $count = $retries; then
>> -                               bbfatal "${PN}: Tried running groupmod command $retries times without success, giving up"
>> -                       fi
>> -                       sleep $count
>> -               done
>> -       else
>> -               bbwarn "${PN}: group $groupname doesn't exist, unable to modify it"
>> +       bbnote "${PN}: Performing groupmod with [$opts]"
>> +       eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO groupmod $opts\'
>> +       if test $? != 0; then
>> +               bbwarn "${PN}: groupmod command did not succeed."
>>          fi
>> +
>>          set -e
>>   }
>>
>>   perform_usermod () {
>>          # Same reason with groupmod, temporarily disable -e option
>>          set +e
>> +
>>          local rootdir="$1"
>>          local opts="$2"
>> -       local retries="$3"
>> -       bbnote "${PN}: Performing usermod with [$opts] and $retries times of retry"
>> -       local username=`echo "$opts" | awk '{ print $NF }'`
>> -       local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
>> -       if test "x$user_exists" != "x"; then
>> -              local count=0
>> -              while true; do
>> -                      eval $PSEUDO usermod $opts
>> -                      if test $? != 0; then
>> -                              bbwarn "${PN}: usermod command did not succeed. Retrying..."
>> -                      else
>> -                              break
>> -                      fi
>> -                      count=`expr $count + 1`
>> -                      if test $count = $retries; then
>> -                               bbfatal "${PN}: Tried running usermod command $retries times without success, giving up"
>> -                      fi
>> -                      sleep $count
>> -              done
>> -       else
>> -               bbwarn "${PN}: user $username doesn't exist, unable to modify it"
>> +       bbnote "${PN}: Performing usermod with [$opts]"
>> +       eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO usermod $opts\'
>> +       if test $? != 0; then
>> +               bbfatal "${PN}: usermod command did not succeed."
>>          fi
>> +
>>          set -e
>>   }
>> --
>> 2.6.1
>>
>> --
>> _______________________________________________
>> Openembedded-core mailing list
>> Openembedded-core@lists.openembedded.org
>> http://lists.openembedded.org/mailman/listinfo/openembedded-core


-- 
Regards,
Neil | Kai Kang



  reply	other threads:[~2016-02-23  3:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-23  2:45 [PATCH 0/1] V3: Replace retry logic in useradd with flock kai.kang
2016-02-23  2:45 ` [PATCH 1/1] useradd_base.bbclass: fix simultaneous " kai.kang
2016-02-23  3:05   ` Khem Raj
2016-02-23  3:35     ` Kang Kai [this message]
2016-02-23  7:25       ` Richard Purdie
2016-02-23  7:31         ` Kang Kai
2016-02-23 16:29   ` Burton, Ross
2016-02-23 17:01     ` Burton, Ross
2016-02-23 17:10       ` Burton, Ross
2016-02-24  8:51         ` Kang Kai
  -- strict thread matches above, loose matches on Subject: below --
2016-02-16  7:14 [PATCH 0/1] V2: Replace retry logic in useradd " kai.kang
2016-02-16  7:14 ` [PATCH 1/1] useradd_base.bbclass: fix simultaneous " kai.kang
2016-02-16 12:09   ` Burton, Ross
2016-02-17  5:40     ` Kang Kai
2016-02-17 23:49       ` Burton, Ross
2016-02-22  8:41         ` Kang Kai
2016-02-15  1:59 [PATCH 0/1] Replace retry logic in useradd " kai.kang
2016-02-15  1:59 ` [PATCH 1/1] useradd_base.bbclass: fix simultaneous " kai.kang
2016-02-15 12:31   ` Burton, Ross
2016-02-16  2:14     ` Kang Kai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56CBD36E.8020908@windriver.com \
    --to=kai.kang@windriver.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=raj.khem@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.