From: Han Ning <ningx.han@intel.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH ltp] su01: do pre-checking to avoid annoying warnings
Date: Mon, 5 Dec 2016 08:56:09 +0800 [thread overview]
Message-ID: <20161205005609.GA6550@ninghanx> (raw)
In-Reply-To: <20161202074508.7rmxhvuezm5aqyze@x230>
On Fri, Dec 02, 2016 at 03:45:08PM +0800, Petr Vorel wrote:
Hi,
> Hi,
>
> > do pre-checking of file/directory/user to avoid warnings like:
> > mkdir: cannot create directory '/home/su_usr1': File exists
>
> > Signed-off-by: Ning Han <ningx.han@intel.com>
> > ---
> > testcases/commands/su/su01 | 12 ++++++------
> > 1 file changed, 6 insertions(+), 6 deletions(-)
>
> > diff --git a/testcases/commands/su/su01 b/testcases/commands/su/su01
> > index dd1517f..9510f29 100755
> > --- a/testcases/commands/su/su01
> > +++ b/testcases/commands/su/su01
> > @@ -85,8 +85,8 @@ rm -f $TEST_ENV_FILE > /dev/null 2>&1
> > #Create 1st test user
> > #erase user if he may exist , so we can have a clean en
> > - rm -rf /home/$TEST_USER1
> > - userdel $TEST_USER1
> > + [ -e /home/$TEST_USER1 ] && rm -rf /home/$TEST_USER1
> -f parameter doesn't produce any error message (ignore nonexistent files).
Thanks. With -p parameter it never prompts. Checking is not necessary.
Let's remove it.
>
> > + getent passwd $TEST_USER1 && userdel $TEST_USER1
> > sleep 1
> > useradd -m -g users $TEST_USER1
> > @@ -105,7 +105,7 @@ rm -f $TEST_ENV_FILE > /dev/null 2>&1
> > then {
> > USER_UID=`id -u $TEST_USER1`
> > USER_GID=`id -g $TEST_USER1`
> > - mkdir $TEST_USER1_HOMEDIR
> > + [ -e $TEST_USER1_HOMEDIR ] || mkdir $TEST_USER1_HOMEDIR
> Use -p parameter?
'useradd -m' has created user's home directory in our environment.
>
> > chown -R $USER_UID.$USER_GID $TEST_USER1_HOMEDIR
> > }
> > fi
> > @@ -120,8 +120,8 @@ rm -f $TEST_ENV_FILE > /dev/null 2>&1
> > #Create 2nd test user
> > #erase user if he may exist , so we can have a clean en
> > - rm -rf /home/$TEST_USER2
> > - userdel $TEST_USER2
> > + [ -e /home/$TEST_USER2 ] && rm -rf /home/$TEST_USER2
> > + getent passwd $TEST_USER2 && userdel $TEST_USER2
> > sleep 1
> > useradd -m -g users $TEST_USER2
> > @@ -141,7 +141,7 @@ rm -f $TEST_ENV_FILE > /dev/null 2>&1
> > then {
> > USER_UID=`id -u $TEST_USER2`
> > USER_GID=`id -g $TEST_USER2`
> > - mkdir $TEST_USER2_HOMEDIR
> > + [ -e $TEST_USER2_HOMEDIR ] || mkdir $TEST_USER2_HOMEDIR
> > chown -R $USER_UID.$USER_GID $TEST_USER2_HOMEDIR
> > }
> > fi
>
>
> Kind regards,
> Petr
next prev parent reply other threads:[~2016-12-05 0:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-02 3:03 [LTP] [PATCH ltp] su01: do pre-checking to avoid annoying warnings Han, NingX
2016-12-02 7:45 ` Petr Vorel
2016-12-05 0:56 ` Han Ning [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-12-12 0:56 Ning, Han
2016-12-15 12:12 ` Cyril Hrubis
2016-12-16 0:31 ` Han Ning
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=20161205005609.GA6550@ninghanx \
--to=ningx.han@intel.com \
--cc=ltp@lists.linux.it \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox