[Toybox] [PATCH] roadmap update: Android switched to toybox ls today.

José Bollo jobol at nonadev.net
Mon May 18 01:08:26 PDT 2015


Le samedi 16 mai 2015 à 12:26 -0500, Rob Landley a écrit :
(snip)

> But meanwhile, I'm back looking at the smack-10 branch starting from
> the new lib files, which is another message...

Hello,

Great news.

I think that it is mature. Obviously, you will have to rebase it a
little to align it on top of your last changes.

I just found that I didn't pushed that interesting commit for ls:

    ls: Improve reading of security context
    
    The previous version had issues:
     - context of sockets wasn't handled
     - there was no rescue if openat failed
     - style wasn't very good
    
    This commit fixes all of this.

diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index 0f7080b..0278a33 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -148,21 +148,25 @@ static int numlen(long long ll)
 static unsigned seclabel(struct dirtree *dt, int pad)
 {
   char *context = NULL;
-  int len = 0, sts, fd, oflags = O_RDONLY|O_NONBLOCK/*|O_NOATIME*/;
+  int len = 0, sts;
 
-  if (S_ISSOCK(dt->st.st_mode)
-  || (S_ISLNK(dt->st.st_mode) && !(toys.optflags & FLAG_L))
-  || ((fd = openat(dirtree_parentfd(dt), dt->name, oflags)) == -1))
-  {
+  if (S_ISLNK(dt->st.st_mode) && !(toys.optflags & FLAG_L)) {
+    // Here a link. It isn't possible to read attributes of links by
using
+    // neither open(O_NOFOLLOW|O_READ) nor open(O_NOFOLLOW|O_PATH) thus
+    // retrieves the path to read it!
     char *path = dirtree_path(dt, 0);
-    if (toys.optflags & FLAG_L) sts = security_get_context(path,
&context);
-    else sts = security_lget_context(path, &context);
+    sts = security_lget_context(path, &context);
     free(path);
+    if (0 <= sts) len = sts;
   } else {
-    sts = security_fget_context(fd, &context);
-    close(fd);
+    int dirfd = dirtree_parentfd(dt);
+    int fd = openat(dirfd, dt->name, O_RDONLY|O_NONBLOCK/*|
O_NOATIME*/);
+    if (fd != -1) {
+      sts = security_fget_context(fd, &context);
+      close(fd);
+      if (0 <= sts) len = sts;
+    }
   }
-  if (0 <= sts) len = sts;
   if (pad) printf("%*s ", pad, len ? context : "?");
   security_free_context(context);
   return len + !len;


=============================================
Also please remember that bug fix:

diff --git a/toys/other/stat.c b/toys/other/stat.c
index d6db44d..a96c1de 100644
--- a/toys/other/stat.c
+++ b/toys/other/stat.c
@@ -82,7 +82,7 @@ static void print_stat(char type)
     if (!stat->st_size && filetype == S_IFREG) t = "regular empty
file";
     xprintf("%s", t);
   } else if (type == 'g') xprintf("%lu", stat->st_gid);
-  else if (type == 'G') xprintf("%8s", TT.group_name->gr_name);
+  else if (type == 'G') xprintf("%8s", TT.user_name->pw_name);
   else if (type == 'h') xprintf("%lu", stat->st_nlink);
   else if (type == 'i') xprintf("%llu", stat->st_ino);
   else if (type == 'N') {

=============================================
Have a good trip in Japan.
Best regards
José Bollo



More information about the Toybox mailing list