[Toybox] [Patch] - touch, kill and umount fixes

Rob Landley rob at landley.net
Thu Sep 18 12:03:53 PDT 2014


On 09/18/14 05:38, Ashwini Sharma wrote:
> Hi Rob,

Hi. Your last round of fixes (which I've applied a little over half of)
touched some of the files needing cleanup outside of the pending
directory. (I.E. command contributions that predated "pending".) I
updated the toys/pedning/README file listing them (so it's not just my
private list), and have been looking at a few. (Yesterday it was "touch"
and "cut" I think.)

> Attached are the patches. This has fixes for
> 
> touch:
> 1.  while setting access or modify times of a file, this was causing a
> hang due to non-increment of ss.

I actually have more fixes to touch pending: the logic is wrong for file
create. I think if you combine "touch -a -d" when creating a file, it
should set the access time to what you specified with -d but leave the
modification time at the current (creation) time? I need to read the
spec and test what the ubuntu version does.

Query: this patch replaces the stanza I just took _out_ that tries to
work around a libc bug. Which libc is having the problem?

Does the for loop not work?

> 2.  handling the time format for __-d__ option as per the spec
> (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html).

The majority of this patch affects the -t case, not the -d case?

-      strcpy(toybuf, "%Y%m%d%H%M");
       date = TT.time;
-      for (i=0;i<3;i++) {
-        s = strptime(date, toybuf+(i&2), &tm);
-        if (s) break;
-        toybuf[1]='y';
-      }
+      i = ((s = strchr(date, '.'))) ? s-date : strlen(date);
+      if (i == 8) strcpy(toybuf, "%m%d%H%M");
+      else if (i == 10) strcpy(toybuf, "%y%m%d%H%M");
+      else if (i == 12) strcpy(toybuf, "%Y%m%d%H%M");
+      else perror_exit("bad '%s'", date);
+
       if (s && *s=='.') {
-        int count = sscanf(s, ".%2d%u%n", &(tm.tm_sec), &i, &len);
-
-        if (count==2) tv->tv_usec = i;
-        s += len;
+        if ((sscanf(s+1, "%2u%n", &(tm.tm_sec), &i) != 1) || *(s+i+1))
+          error_exit("bad '%s'", date);
+        s += (i+1);

Where did the call to strptime go? This new code seems to set up toybuf
(using three separate strings instead of three cases on one string), and
then... not call strptime? I'm confused...

(Yesterday I was looking at whether or not I could combine the date
parsing logic there with the stuff in "date". The answer is currently
"no", but I want to give it another look...)

Have to answer the rest later, errand...

Rob

 1411067033.0


More information about the Toybox mailing list