All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] Add verbose setup to creat08, creat09 and open10
@ 2021-08-30 13:17 Martin Doucha
  2021-08-30 13:17 ` [LTP] [PATCH 2/2] tst_get_free_gid(): Skip GID 0 Martin Doucha
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Doucha @ 2021-08-30 13:17 UTC (permalink / raw)
  To: ltp

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

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 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(-)

diff --git a/lib/tst_uid.c b/lib/tst_uid.c
index a73cafa46..2163b1494 100644
--- a/lib/tst_uid.c
+++ b/lib/tst_uid.c
@@ -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;
diff --git a/testcases/kernel/syscalls/creat/creat08.c b/testcases/kernel/syscalls/creat/creat08.c
index 4392f198a..91581dbf8 100644
--- a/testcases/kernel/syscalls/creat/creat08.c
+++ b/testcases/kernel/syscalls/creat/creat08.c
@@ -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();
 }
diff --git a/testcases/kernel/syscalls/creat/creat09.c b/testcases/kernel/syscalls/creat/creat09.c
index 1de16d636..53ab202c1 100644
--- a/testcases/kernel/syscalls/creat/creat09.c
+++ b/testcases/kernel/syscalls/creat/creat09.c
@@ -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 */
diff --git a/testcases/kernel/syscalls/open/open10.c b/testcases/kernel/syscalls/open/open10.c
index e3804c74f..d2d3729d2 100644
--- a/testcases/kernel/syscalls/open/open10.c
+++ b/testcases/kernel/syscalls/open/open10.c
@@ -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();
 }
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH 2/2] tst_get_free_gid(): Skip GID 0
  2021-08-30 13:17 [LTP] [PATCH 1/2] Add verbose setup to creat08, creat09 and open10 Martin Doucha
@ 2021-08-30 13:17 ` Martin Doucha
  2021-08-30 13:47   ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Doucha @ 2021-08-30 13:17 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 lib/tst_uid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/tst_uid.c b/lib/tst_uid.c
index 2163b1494..dd719d312 100644
--- a/lib/tst_uid.c
+++ b/lib/tst_uid.c
@@ -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;
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH 2/2] tst_get_free_gid(): Skip GID 0
  2021-08-30 13:17 ` [LTP] [PATCH 2/2] tst_get_free_gid(): Skip GID 0 Martin Doucha
@ 2021-08-30 13:47   ` Cyril Hrubis
  0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2021-08-30 13:47 UTC (permalink / raw)
  To: ltp

Hi!
Good catch, both patches pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-30 13:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 13:17 [LTP] [PATCH 1/2] Add verbose setup to creat08, creat09 and open10 Martin Doucha
2021-08-30 13:17 ` [LTP] [PATCH 2/2] tst_get_free_gid(): Skip GID 0 Martin Doucha
2021-08-30 13:47   ` Cyril Hrubis

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.