Date: Sun, 5 Feb 2012 10:46:03 +0300 From: Sergey Kandaurov <pluknet@freebsd.org> To: Jaakko Heinonen <jh@freebsd.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r230979 - head/usr.bin/touch Message-ID: <CAE-mSOLcOo3zzKxRJvkW%2BOe_-cPBoPXGGMKmNByvtSRggLJHig@mail.gmail.com> In-Reply-To: <201202041337.q14DbVTn037485@svn.freebsd.org> References: <201202041337.q14DbVTn037485@svn.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 4 February 2012 17:37, Jaakko Heinonen <jh@freebsd.org> wrote: > Author: jh > Date: Sat Feb 4 13:37:31 2012 > New Revision: 230979 > URL: http://svn.freebsd.org/changeset/base/230979 > > Log: > Remove useless and potentially dangerous rw() function which tries to > update access and modification times by reading and writing the file. > chmod(2) in rw() doesn't help because utimes(2) allow owner and the > super-user to change times. Using just utimes(2) should be sufficient. > > The -f option becomes no-op. > > Reviewed by: jilles > > Modified: > head/usr.bin/touch/touch.1 > head/usr.bin/touch/touch.c Thank you. FYI, this code was written before utimes(2) was born (yes, before 4.2BSD), so it was technically correct to remove it for more than 20 years ago. > > Modified: head/usr.bin/touch/touch.1 > ============================================================================== > --- head/usr.bin/touch/touch.1 Sat Feb 4 13:12:52 2012 (r230978) > +++ head/usr.bin/touch/touch.1 Sat Feb 4 13:37:31 2012 (r230979) > @@ -31,7 +31,7 @@ > .\" @(#)touch.1 8.3 (Berkeley) 4/28/95 > .\" $FreeBSD$ > .\" > -.Dd April 28, 1995 > +.Dd February 4, 2012 > .Dt TOUCH 1 > .Os > .Sh NAME > @@ -40,7 +40,7 @@ > .Sh SYNOPSIS > .Nm > .Op Fl A Ar [-][[hh]mm]SS > -.Op Fl acfhm > +.Op Fl achm > .Op Fl r Ar file > .Op Fl t Ar [[CC]YY]MMDDhhmm[.SS] > .Ar > @@ -109,9 +109,6 @@ The > .Nm > utility does not treat this as an error. > No error messages are displayed and the exit value is not affected. > -.It Fl f > -Attempt to force the update, even if the file permissions do not > -currently permit it. > .It Fl h > If the file is a symbolic link, change the times of the link > itself rather than the file that the link points to. > > Modified: head/usr.bin/touch/touch.c > ============================================================================== > --- head/usr.bin/touch/touch.c Sat Feb 4 13:12:52 2012 (r230978) > +++ head/usr.bin/touch/touch.c Sat Feb 4 13:37:31 2012 (r230979) > @@ -55,7 +55,6 @@ static const char sccsid[] = "@(#)touch. > #include <time.h> > #include <unistd.h> > > -int rw(char *, struct stat *, int); > void stime_arg1(char *, struct timeval *); > void stime_arg2(char *, int, struct timeval *); > void stime_file(char *, struct timeval *); > @@ -69,12 +68,12 @@ main(int argc, char *argv[]) > struct timeval tv[2]; > int (*stat_f)(const char *, struct stat *); > int (*utimes_f)(const char *, const struct timeval *); > - int Aflag, aflag, cflag, fflag, mflag, ch, fd, len, rval, timeset; > + int Aflag, aflag, cflag, mflag, ch, fd, len, rval, timeset; > char *p; > char *myname; > > myname = basename(argv[0]); > - Aflag = aflag = cflag = fflag = mflag = timeset = 0; > + Aflag = aflag = cflag = mflag = timeset = 0; > stat_f = stat; > utimes_f = utimes; > if (gettimeofday(&tv[0], NULL)) > @@ -92,7 +91,7 @@ main(int argc, char *argv[]) > cflag = 1; > break; > case 'f': > - fflag = 1; > + /* No-op for compatibility. */ > break; > case 'h': > cflag = 1; > @@ -222,14 +221,8 @@ main(int argc, char *argv[]) > if (!utimes_f(*argv, NULL)) > continue; > > - /* Try reading/writing. */ > - if (!S_ISLNK(sb.st_mode) && !S_ISDIR(sb.st_mode)) { > - if (rw(*argv, &sb, fflag)) > - rval = 1; > - } else { > - rval = 1; > - warn("%s", *argv); > - } > + rval = 1; > + warn("%s", *argv); > } > exit(rval); > } > @@ -368,59 +361,10 @@ stime_file(char *fname, struct timeval * > TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtim); > } > > -int > -rw(char *fname, struct stat *sbp, int force) > -{ > - int fd, needed_chmod, rval; > - u_char byte; > - > - /* Try regular files. */ > - if (!S_ISREG(sbp->st_mode)) { > - warnx("%s: %s", fname, strerror(EFTYPE)); > - return (1); > - } > - > - needed_chmod = rval = 0; > - if ((fd = open(fname, O_RDWR, 0)) == -1) { > - if (!force || chmod(fname, DEFFILEMODE)) > - goto err; > - if ((fd = open(fname, O_RDWR, 0)) == -1) > - goto err; > - needed_chmod = 1; > - } > - > - if (sbp->st_size != 0) { > - if (read(fd, &byte, sizeof(byte)) != sizeof(byte)) > - goto err; > - if (lseek(fd, (off_t)0, SEEK_SET) == -1) > - goto err; > - if (write(fd, &byte, sizeof(byte)) != sizeof(byte)) > - goto err; > - } else { > - if (write(fd, &byte, sizeof(byte)) != sizeof(byte)) { > -err: rval = 1; > - warn("%s", fname); > - } else if (ftruncate(fd, (off_t)0)) { > - rval = 1; > - warn("%s: file modified", fname); > - } > - } > - > - if (close(fd) && rval != 1) { > - rval = 1; > - warn("%s", fname); > - } > - if (needed_chmod && chmod(fname, sbp->st_mode) && rval != 1) { > - rval = 1; > - warn("%s: permissions modified", fname); > - } > - return (rval); > -} > - > void > usage(char *myname) > { > - fprintf(stderr, "usage:\n" "%s [-A [-][[hh]mm]SS] [-acfhm] [-r file] " > + fprintf(stderr, "usage:\n" "%s [-A [-][[hh]mm]SS] [-achm] [-r file] " > "[-t [[CC]YY]MMDDhhmm[.SS]] file ...\n", myname); > exit(1); > } -- wbr, pluknet
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAE-mSOLcOo3zzKxRJvkW%2BOe_-cPBoPXGGMKmNByvtSRggLJHig>
