From owner-svn-src-all@FreeBSD.ORG Sun Feb 15 21:28:01 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BC51FD25; Sun, 15 Feb 2015 21:28:01 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9C732A59; Sun, 15 Feb 2015 21:28:01 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1FLS175065507; Sun, 15 Feb 2015 21:28:01 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1FLS1VY065506; Sun, 15 Feb 2015 21:28:01 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201502152128.t1FLS1VY065506@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sun, 15 Feb 2015 21:28:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278817 - head/usr.bin/touch X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Feb 2015 21:28:01 -0000 Author: jilles Date: Sun Feb 15 21:28:00 2015 New Revision: 278817 URL: https://svnweb.freebsd.org/changeset/base/278817 Log: touch: Fix some subtle bugs related to NULL times fallback: * Do not subvert vfs.timestamp_precision by reading the time and passing that to utimensat(). Instead, pass UTIME_NOW. A fallback to a NULL times pointer is no longer used. * Do not ignore -a/-m if the user has write access but does not own the file. Leave timestamps unchanged using UTIME_OMIT and do not fall back to a NULL times pointer (which would set both timestamps) if that fails. Reviewed by: bde Modified: head/usr.bin/touch/touch.c Modified: head/usr.bin/touch/touch.c ============================================================================== --- head/usr.bin/touch/touch.c Sun Feb 15 21:15:09 2015 (r278816) +++ head/usr.bin/touch/touch.c Sun Feb 15 21:28:00 2015 (r278817) @@ -76,8 +76,8 @@ main(int argc, char *argv[]) myname = basename(argv[0]); Aflag = aflag = cflag = mflag = timeset = 0; atflag = 0; - if (clock_gettime(CLOCK_REALTIME, &ts[0]) == -1) - err(1, "clock_gettime(CLOCK_REALTIME)"); + ts[0].tv_sec = ts[1].tv_sec = 0; + ts[0].tv_nsec = ts[1].tv_nsec = UTIME_NOW; while ((ch = getopt(argc, argv, "A:acd:fhmr:t:")) != -1) switch(ch) { @@ -152,6 +152,11 @@ main(int argc, char *argv[]) ts[1] = ts[0]; } + if (!aflag) + ts[0].tv_nsec = UTIME_OMIT; + if (!mflag) + ts[1].tv_nsec = UTIME_OMIT; + if (*argv == NULL) usage(myname); @@ -183,11 +188,6 @@ main(int argc, char *argv[]) continue; } - if (!aflag) - ts[0] = sb.st_atim; - if (!mflag) - ts[1] = sb.st_mtim; - /* * We're adjusting the times based on the file times, not a * specified time (that gets handled above). @@ -203,26 +203,9 @@ main(int argc, char *argv[]) } } - /* Try utimensat(2). */ if (!utimensat(AT_FDCWD, *argv, ts, atflag)) continue; - /* If the user specified a time, nothing else we can do. */ - if (timeset || Aflag) { - rval = 1; - warn("%s", *argv); - continue; - } - - /* - * System V and POSIX 1003.1 require that a NULL argument - * set the access/modification times to the current time. - * The permission checks are different, too, in that the - * ability to write the file is sufficient. Take a shot. - */ - if (!utimensat(AT_FDCWD, *argv, NULL, atflag)) - continue; - rval = 1; warn("%s", *argv); } @@ -238,8 +221,8 @@ stime_arg1(const char *arg, struct times struct tm *t; int yearset; char *p; - /* Start with the current time. */ - now = tvp[0].tv_sec; + + now = time(NULL); if ((t = localtime(&now)) == NULL) err(1, "localtime"); /* [[CC]YY]MMDDhhmm[.SS] */ @@ -300,8 +283,8 @@ stime_arg2(const char *arg, int year, st { time_t now; struct tm *t; - /* Start with the current time. */ - now = tvp[0].tv_sec; + + now = time(NULL); if ((t = localtime(&now)) == NULL) err(1, "localtime");