From owner-svn-src-head@FreeBSD.ORG Sat Feb 4 13:37:32 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 18542106567B; Sat, 4 Feb 2012 13:37:32 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EFBA58FC1B; Sat, 4 Feb 2012 13:37:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q14DbVZt037488; Sat, 4 Feb 2012 13:37:31 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q14DbVTn037485; Sat, 4 Feb 2012 13:37:31 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201202041337.q14DbVTn037485@svn.freebsd.org> From: Jaakko Heinonen Date: Sat, 4 Feb 2012 13:37:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r230979 - head/usr.bin/touch X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Feb 2012 13:37:32 -0000 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 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 #include -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); }