Skip to contentSkip to conversation

Add verbose setup to creat08, creat09 and open10

PATCH New Martin Doucha 2 participants 3 messages Aug 30, 2021 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add verbose setup to creat08, creat09 and open10

These tests are sensitive to proper UID/GID configuration so print the detected values for debugging purposes in case of test failure.

---
 lib/tst_uid.c                             | 5 ++++-
 testcases/kernel/syscalls/creat/creat08.c | 2 ++
 testcases/kernel/syscalls/creat/creat09.c | 2 ++
 testcases/kernel/syscalls/open/open10.c   | 2 ++
 4 files changed, 10 insertions(+), 1 deletion(-)
lib/tst_uid.c +4 -1
index a73cafa46..2163b1494 100644
@@ -23,8 +23,11 @@ gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip)
 		if (ret == skip || getgrgid(ret))
 			continue;
 
-		if (errno == 0 || errno == ENOENT || errno == ESRCH)
+		if (errno == 0 || errno == ENOENT || errno == ESRCH) {
+			tst_res_(file, lineno, TINFO | TERRNO,
+				"Found unused GID %d", (int)ret);
 			return ret;
+		}
 
 		tst_brk_(file, lineno, TBROK|TERRNO, "Group ID lookup failed");
 		return (gid_t)-1;
testcases/kernel/syscalls/creat/creat08.c +2 -0
index 4392f198a..91581dbf8 100644
@@ -41,6 +41,8 @@ static void setup(void)
 	orig_uid = getuid();
 	nobody_uid = ltpuser->pw_uid;
 	nobody_gid = ltpuser->pw_gid;
+	tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)nobody_uid,
+		(int)nobody_gid);
 	free_gid = tst_get_free_gid(nobody_gid);
 	tmpdir = tst_get_tmpdir();
 }
testcases/kernel/syscalls/creat/creat09.c +2 -0
index 1de16d636..53ab202c1 100644
@@ -41,6 +41,8 @@ static void setup(void)
 	struct stat buf;
 	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 
+	tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)ltpuser->pw_uid,
+		(int)ltpuser->pw_gid);
 	free_gid = tst_get_free_gid(ltpuser->pw_gid);
 
 	/* Create directories and set permissions */
testcases/kernel/syscalls/open/open10.c +2 -0
index e3804c74f..d2d3729d2 100644
@@ -39,6 +39,8 @@ static void setup(void)
 	orig_uid = getuid();
 	nobody_uid = ltpuser->pw_uid;
 	nobody_gid = ltpuser->pw_gid;
+	tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)nobody_uid,
+		(int)nobody_gid);
 	free_gid = tst_get_free_gid(nobody_gid);
 	tmpdir = tst_get_tmpdir();
 }
Signature · 1 line
2.32.0
#1 lore raw

PATCH 2/2 tst_get_free_gid(): Skip GID 0

tst_get_free_gid() may return GID 0 on systems where /etc/group (or another database of user groups) does not exist. But GID 0 exists implicitly and it may stay after setgid() as a supplemental group of the test process if it was executed with root privileges. Skip GID 0 to avoid unexpected test failures.

---
 lib/tst_uid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_uid.c +1 -1
index 2163b1494..dd719d312 100644
@@ -19,7 +19,7 @@ gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip)
 
 	errno = 0;
 
-	for (ret = 0; ret < MAX_GID; ret++) {
+	for (ret = 1; ret < MAX_GID; ret++) {
 		if (ret == skip || getgrgid(ret))
 			continue;
 
Signature · 1 line
2.32.0