glibc doesn't set errno when getpw* fails, so the perror_exit() looked
fine. bionic sets ENOENT and the trailing "No such file or directory"
looks silly, so switch to error_exit().

Additionally, the default format tests fail on Android because of
SELinux (but for a different reason than usual!). There's no id
--no-context flag, so use sed to just throw away any SELinux context.
---
 tests/id.test   | 8 +++++---
 toys/posix/id.c | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)
From c3fd6fdc2e17f66941a72f73128fbc2082d07970 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Mon, 4 Nov 2019 21:24:42 -0800
Subject: [PATCH] id: fix Android issues.

glibc doesn't set errno when getpw* fails, so the perror_exit() looked
fine. bionic sets ENOENT and the trailing "No such file or directory"
looks silly, so switch to error_exit().

Additionally, the default format tests fail on Android because of
SELinux (but for a different reason than usual!). There's no id
--no-context flag, so use sed to just throw away any SELinux context.
---
 tests/id.test   | 8 +++++---
 toys/posix/id.c | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/id.test b/tests/id.test
index 05c5378c..32f26191 100755
--- a/tests/id.test
+++ b/tests/id.test
@@ -4,8 +4,10 @@
 
 #testing "name" "command" "result" "infile" "stdin"
 
-testing "id 0" "id 0" "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
-testing "id root" "id root" "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
+testing "id 0" "id 0 | sed 's/ context=.*//g'" \
+  "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
+testing "id root" "id root | sed 's/ context=.*//g'" \
+  "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
 testing "id -G root" "id -G root" "0\n" "" ""
 testing "id -nG root" "id -nG root" "root\n" "" ""
 testing "id -g root" "id -g root" "0\n" "" ""
@@ -13,4 +15,4 @@ testing "id -ng root" "id -ng root" "root\n" "" ""
 testing "id -u root" "id -u root" "0\n" "" ""
 testing "id -nu root" "id -nu root" "root\n" "" ""
 testing "id no-such-user" "id no-such-user 2>/dev/null ; echo \$?" "1\n" "" ""
-testing "id 9999999" "id 9999999 2>/dev/null ; echo \$?" "1\n" "" ""
+testing "id 2147483647" "id 2147483647 2>/dev/null ; echo \$?" "1\n" "" ""
diff --git a/toys/posix/id.c b/toys/posix/id.c
index ac29990b..6f71891b 100644
--- a/toys/posix/id.c
+++ b/toys/posix/id.c
@@ -98,7 +98,7 @@ static void do_id(char *username)
       uid = atolx_range(username, 0, INT_MAX);
       if ((pw = getpwuid(uid))) username = pw->pw_name;
     }
-    if (!pw) perror_exit("no such user '%s'", username);
+    if (!pw) error_exit("no such user '%s'", username);
     uid = euid = pw->pw_uid;
     gid = egid = pw->pw_gid;
     if (TT.is_groups) printf("%s : ", pw->pw_name);
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to