OSDN Git Service

Merge remote-tracking branch 'toybox/master' into HEAD
authorElliott Hughes <enh@google.com>
Thu, 3 Sep 2015 21:41:43 +0000 (14:41 -0700)
committerElliott Hughes <enh@google.com>
Thu, 3 Sep 2015 21:41:43 +0000 (14:41 -0700)
kconfig/zconf.hash.c_shipped
toys/lsb/seq.c
toys/other/vmstat.c
toys/posix/ls.c

index 0287aa3..1fffcbb 100644 (file)
@@ -159,9 +159,6 @@ static struct kconf_id_strings_t kconf_id_strings_contents =
     "enable"
   };
 #define kconf_id_strings ((const char *) &kconf_id_strings_contents)
-#if defined(__GNUC__) && __STDC_VERSION__ < 199901L
-__inline
-#endif
 struct kconf_id *
 kconf_id_lookup (register const char *str, register unsigned int len)
 {
index bf5cab1..322940b 100644 (file)
@@ -29,6 +29,27 @@ GLOBALS(
   char *fmt;
 )
 
+// Ensure there's one %f escape with correct attributes
+static void insanitize(char *f)
+{
+  char *s;
+  int found = 0;
+
+  for (s = f; *s; s++) {
+    if (*s != '%') continue;
+    if (*++s == '%') continue;
+    if (found++) break;
+    while (0 <= stridx("0'#-+ ", *s)) s++;
+    while (isdigit(*s)) s++;
+    if (*s == '.') s++;
+    while (isdigit(*s)) s++;
+    if (-1 == stridx("aAeEfFgG", *s)) break;
+  }
+
+  // The @ is a byte offset, not utf8 chars. Waiting for somebody to complain...
+  if (*s) error_exit("bad -f '%s'@%d", f, s-f+1);
+}
+
 void seq_main(void)
 {
   double first, increment, last, dd;
@@ -45,7 +66,7 @@ void seq_main(void)
     default: last = atof(toys.optargs[toys.optc-1]);
   }
 
-  if (toys.optflags & FLAG_f) fmt_str = TT.fmt;
+  if (toys.optflags & FLAG_f) insanitize(fmt_str = TT.fmt);
   if (toys.optflags & FLAG_s) sep_str = TT.sep;
 
   // Yes, we're looping on a double.  Yes rounding errors can accumulate if
index 9a38e45..df35db1 100644 (file)
@@ -2,7 +2,7 @@
  *
  * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
  *
- * TODO: I have no idea how the "io" and "system" categories are calculated.
+ * TODO: I have no idea how "system" category is calculated.
  * whatever we're doing isn't matching what other implementations are doing.
 
 USE_VMSTAT(NEWTOY(vmstat, ">2n", TOYFLAG_BIN))
@@ -33,8 +33,10 @@ struct vmstat_proc {
   uint64_t user, nice, sys, idle, wait, irq, sirq, intr, ctxt, running, blocked;
   // From /proc/meminfo (units are kb)
   uint64_t memfree, buffers, cached, swapfree, swaptotal;
+  // From /proc/vmstat (units are kb)
+  uint64_t io_in, io_out;
   // From /proc/vmstat (units are pages)
-  uint64_t io_in, io_out, swap_in, swap_out;
+  uint64_t swap_in, swap_out;
 };
 
 // All the elements of vmstat_proc are the same size, so we can populate it as
@@ -96,14 +98,15 @@ void vmstat_main(void)
 
     // Print headers
     if (rows>3 && !(loop % (rows-3))) {
+      char *header = headers;
+
       if (isatty(1)) terminal_size(0, &rows);
       else rows = 0;
 
       printf("procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n");
-
       for (i=0; i<sizeof(lengths); i++) {
-        printf(" %*s"+!i, lengths[i], headers);
-        headers += strlen(headers)+1;
+        printf(" %*s"+!i, lengths[i], header);
+        header += strlen(header)+1;
       }
       xputc('\n');
     }
@@ -141,7 +144,8 @@ void vmstat_main(void)
       // Adjust rate and units
       if (i>5) out -= oldptr[order[i]];
       if (order[i]<7) out = ((out*100) + (total_hz/2)) / total_hz;
-      else if (order[i]>15) out = ((out * page_kb)+(units-1))/units;
+      else if (order[i]>17) out = ((out * page_kb)+(units-1))/units;
+      else if (order[i]>15) out = ((out)+(units-1))/units;
       else if (order[i]<9) out = (out+(units-1)) / units;
 
       // If a field was too big to fit in its slot, try to compensate later
index f951198..e46a576 100644 (file)
@@ -426,18 +426,18 @@ static void listfiles(int dirfd, struct dirtree *indir)
       if (!(flags&FLAG_g)) {
         if (flags&FLAG_n) sprintf(ss = thyme, "%u", (unsigned)st->st_uid);
         else strwidth(ss = getusername(st->st_uid));
-        printf(" %*s", (int)totals[3], ss);
+        printf(" %-*s", (int)totals[3], ss);
       }
 
       // print group
       if (!(flags&FLAG_o)) {
         if (flags&FLAG_n) sprintf(ss = thyme, "%u", (unsigned)st->st_gid);
         else strwidth(ss = getgroupname(st->st_gid));
-        printf(" %*s", (int)totals[4], ss);
+        printf(" %-*s", (int)totals[4], ss);
       }
 
       if (flags & FLAG_Z)
-        printf(" %*s", -(int)totals[7], (char *)sort[next]->extra);
+        printf(" %-*s", -(int)totals[7], (char *)sort[next]->extra);
 
       // print major/minor
       if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
@@ -449,7 +449,7 @@ static void listfiles(int dirfd, struct dirtree *indir)
       strftime(thyme, sizeof(thyme), "%F %H:%M", tm);
       xprintf(" %s ", thyme);
     } else if (flags & FLAG_Z)
-      printf("%*s ", (int)totals[7], (char *)sort[next]->extra);
+      printf("%-*s ", (int)totals[7], (char *)sort[next]->extra);
 
     if (flags & FLAG_color) {
       color = color_from_mode(st->st_mode);