[LTP] [PATCH] syscalls/add_key05: Add userdel and groupdel before useradd
Zhao Gongyi
zhaogongyi@huawei.com
Sun Oct 9 04:59:18 CEST 2022
If the test exit abnormal, some user/group will be left, and the
next running of the test will fail and report:
tst_buffers.c:55: TINFO: Test is using guarded buffers
tst_test.c:1526: TINFO: Timeout per run is 0h 00m 30s
useradd: group ltp_add_key05_0 exists - if you want to add this user to that group, use -g.
add_key05.c:41: TBROK: useradd failed (9)
userdel: user 'ltp_add_key05_0' does not exist
add_key05.c:56: TWARN: 'userdel -r ltp_add_key05_0' failed: ENOENT (2)
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
testcases/kernel/syscalls/add_key/add_key05.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/testcases/kernel/syscalls/add_key/add_key05.c b/testcases/kernel/syscalls/add_key/add_key05.c
index 71a88d1a8..42ad04eec 100644
--- a/testcases/kernel/syscalls/add_key/add_key05.c
+++ b/testcases/kernel/syscalls/add_key/add_key05.c
@@ -34,8 +34,13 @@ static void add_user(char n)
{
char username[] = "ltp_add_key05_n";
const char *const cmd_useradd[] = {"useradd", username, NULL};
+ const char *const cmd_userdel[] = {"userdel", "-r", username, NULL};
+ const char *const cmd_groupdel[] = {"groupdel", username, NULL};
struct passwd *pw;
+ tst_cmd(cmd_userdel, NULL, NULL, TST_CMD_PASS_RETVAL);
+ tst_cmd(cmd_groupdel, NULL, NULL, TST_CMD_PASS_RETVAL);
+
username[sizeof(username) - 2] = '0' + n;
SAFE_CMD(cmd_useradd, NULL, NULL);
--
2.17.1
More information about the ltp
mailing list