Skip to contentSkip to conversation

generic/317: use id to get user id

PATCH In review Eryu Guan 3 participants 4 messages Sep 23, 2016 – Sep 26, 2016

lore
Share & tools
lore

Eryu Guan

author
#0 lore raw

PATCH 1/1 generic/317: use id to get user id

Greping username "fsgqa" in passwd file to get user id doesn't always work, because the given username could match multiple entries, e.g. when we have user "123456-fsgqa" (used by other tests) in passwd file.

Fix it by using "id -u $qa_user" to get the user id directly.

---
 tests/generic/317 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/317 +1 -1
index 9d9499b..7e40b1f 100755
@@ -61,7 +61,7 @@ _require_scratch
 _require_user
 _require_ugid_map
 _require_userns
-qa_user_id=`grep $qa_user /etc/passwd |awk -F: '{print $3}'`
+qa_user_id=`id -u $qa_user`
 
 _filter_output()
 {
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Eryu Guan

Greping username "fsgqa" in passwd file to get user id doesn't always work, because the given username could match multiple entries, e.g. when we have user "123456-fsgqa" (used by other tests) in passwd file.

Fix it by using "id -u $qa_user" to get the user id directly.

---
 tests/generic/317 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/317 +0 -0
index 9d9499b..7e40b1f 100755

tests/generic/317 _require_scratch · line 64

Quoted 5 lines
tests/generic/317 +1 -1
@@ -61,7 +61,7 @@ _require_scratch
 _require_user
 _require_ugid_map
 _require_userns
-qa_user_id=`grep $qa_user /etc/passwd |awk -F: '{print $3}'`
+qa_user_id=`id -u $qa_user`

Looks good to me.

Quoted 10 lines
tests/generic/317 +0 -0
 _filter_output()
 {
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to Eryu Guan
Quoted 18 lines · Eryu Guan

Greping username "fsgqa" in passwd file to get user id doesn't always work, because the given username could match multiple entries, e.g. when we have user "123456-fsgqa" (used by other tests) in passwd file.

Fix it by using "id -u $qa_user" to get the user id directly.

---
 tests/generic/317 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/317 +0 -0
index 9d9499b..7e40b1f 100755

tests/generic/317 _require_scratch · line 64

Quoted 5 lines
tests/generic/317 +1 -1
@@ -61,7 +61,7 @@ _require_scratch
 _require_user
 _require_ugid_map
 _require_userns
-qa_user_id=`grep $qa_user /etc/passwd |awk -F: '{print $3}'`
+qa_user_id=`id -u $qa_user`

shouldn't it use _cat_passwd() from common/rc ?

author
#3 lore raw
Quoted 14 lines · Anatoly Pugachev
Quoted 13 lines · Eryu Guan

Greping username "fsgqa" in passwd file to get user id doesn't always work, because the given username could match multiple entries, e.g. when we have user "123456-fsgqa" (used by other tests) in passwd file.

Fix it by using "id -u $qa_user" to get the user id directly.

---
 tests/generic/317 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tests/generic/317 _require_scratch · line 64

Quoted 10 lines
tests/generic/317 +1 -1
index 9d9499b..7e40b1f 100755
@@ -61,7 +61,7 @@ _require_scratch
 _require_user
 _require_ugid_map
 _require_userns
-qa_user_id=`grep $qa_user /etc/passwd |awk -F: '{print $3}'`
+qa_user_id=`id -u $qa_user`

shouldn't it use _cat_passwd() from common/rc ?

I thought about it too, but _cat_passwd has the same problem as grep /etc/passwd directly, and "id -u $qa_user" just works fine too in NIS env. So I think this fix is fine.

Thanks,
Eryu