From owner-freebsd-standards@FreeBSD.ORG Mon Feb 14 11:01:59 2005 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1E71316A4E2 for ; Mon, 14 Feb 2005 11:01:59 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id ED77343D1F for ; Mon, 14 Feb 2005 11:01:58 +0000 (GMT) (envelope-from owner-bugmaster@freebsd.org) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.13.1/8.13.1) with ESMTP id j1EB1wmJ015233 for ; Mon, 14 Feb 2005 11:01:58 GMT (envelope-from owner-bugmaster@freebsd.org) Received: (from peter@localhost) by freefall.freebsd.org (8.13.1/8.13.1/Submit) id j1EB1wOj015227 for freebsd-standards@freebsd.org; Mon, 14 Feb 2005 11:01:58 GMT (envelope-from owner-bugmaster@freebsd.org) Date: Mon, 14 Feb 2005 11:01:58 GMT Message-Id: <200502141101.j1EB1wOj015227@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: peter set sender to owner-bugmaster@freebsd.org using -f From: FreeBSD bugmaster To: freebsd-standards@FreeBSD.org Subject: Current problem reports assigned to you X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Feb 2005 11:01:59 -0000 Current FreeBSD problem reports Critical problems Serious problems S Submitted Tracker Resp. Description ------------------------------------------------------------------------------- o [2001/03/05] bin/25542 standards /bin/sh: null char in quoted string p [2002/02/25] standards/35307standards standard include files are not standard c o [2002/12/13] kern/46239 standards posix semaphore implementation errors o [2003/04/21] standards/51209standards [PATCH] add a64l()/l64a/l64a_r functions p [2003/06/05] standards/52972standards /bin/sh arithmetic not POSIX compliant o [2003/06/18] kern/53447 standards poll(2) semantics differ from susV3/POSIX o [2003/07/12] standards/54410standards one-true-awk not POSIX compliant (no exte o [2004/01/01] standards/60772standards _Bool and bool should be unsigned o [2004/11/03] standards/73500standards 'set +o' in /bin/sh does not include unse 9 problems total. Non-critical problems S Submitted Tracker Resp. Description ------------------------------------------------------------------------------- o [2000/09/24] bin/21519 standards sys/dir.h should be deprecated some more o [2001/01/16] bin/24390 standards Replacing old dir-symlinks when using /bi s [2001/01/24] standards/24590standards timezone function not compatible witn Sin s [2001/06/18] kern/28260 standards UIO_MAXIOV needs to be made public p [2001/11/20] standards/32126standards getopt(3) not Unix-98 conformant o [2002/02/27] misc/35381 standards incorrect floating-point display of large s [2002/03/19] standards/36076standards Implementation of POSIX fuser command o [2002/06/14] standards/39256standards [v]snprintf aren't POSIX-conformant for s o [2002/07/09] kern/40378 standards stdlib.h gives needless warnings with -an p [2002/08/12] standards/41576standards POSIX compliance of ln(1) o [2002/10/23] standards/44425standards getcwd() succeeds even if current dir has o [2002/12/09] standards/46119standards Priority problems for SCHED_OTHER using p o [2002/12/23] standards/46504standards Warnings in headers o [2003/06/22] standards/53613standards FreeBSD doesn't define EPROTO o [2003/07/24] standards/54809standards pcvt deficits o [2003/07/25] standards/54833standards more pcvt deficits o [2003/07/25] standards/54839standards pcvt deficits o [2003/07/31] standards/55112standards glob.h, glob_t's gl_pathc should be "size o [2003/09/05] standards/56476standards cd9660 unicode support simple hack o [2003/10/29] standards/58676standards grantpt(3) alters storage used by ptsname p [2003/12/26] standards/60597standards FreeBSD's /usr/include lacks of cpio.h s [2004/02/14] standards/62858standards malloc(0) not C99 compliant p [2004/02/21] standards/63173standards Patch to add getopt_long_only(3) to libc o [2004/03/29] kern/64875 standards [patch] add a system call: fdatasync() o [2004/05/07] standards/66357standards make POSIX conformance problem ('sh -e' & o [2004/05/11] standards/66531standards _gettemp uses a far smaller set of filena o [2004/08/22] standards/70813standards [PATCH] ls not Posix compliant o [2004/08/26] docs/70985 standards [patch] sh(1): incomplete documentation o o [2004/09/22] standards/72006standards floating point formating in non-C locales 29 problems total. From owner-freebsd-standards@FreeBSD.ORG Mon Feb 14 16:12:33 2005 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EE6E516A4CE for ; Mon, 14 Feb 2005 16:12:32 +0000 (GMT) Received: from electra.cse.Buffalo.EDU (electra.cse.Buffalo.EDU [128.205.32.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 70CB343D39 for ; Mon, 14 Feb 2005 16:12:32 +0000 (GMT) (envelope-from kensmith@cse.Buffalo.EDU) Received: from electra.cse.Buffalo.EDU (kensmith@localhost [127.0.0.1]) j1EGCVu3013447 for ; Mon, 14 Feb 2005 11:12:31 -0500 (EST) Received: (from kensmith@localhost) by electra.cse.Buffalo.EDU (8.12.10/8.12.9/Submit) id j1EGCVQZ013446 for freebsd-standards@freebsd.org; Mon, 14 Feb 2005 11:12:31 -0500 (EST) Date: Mon, 14 Feb 2005 11:12:31 -0500 From: Ken Smith To: freebsd-standards@freebsd.org Message-ID: <20050214161231.GA10713@electra.cse.Buffalo.EDU> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Subject: Updating atime during exec, attempt #3... X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Feb 2005 16:12:33 -0000 Ok, here is attempt #3 at fixing the exec-should-update-atime problem. This one is similar to the one I sent a week or so ago in that it is using a special flag in the vattr structure and VOP_SETATTR() to do the work. But this one avoids locking the filesystem for a write (using vn_start_write()) by letting the filesystem defer the actual update of atime. The idea is for the filesystem to handle the update in roughly the same way as it would for a read, though it should try to minimize the impact. UFS is used here as an example - the IN_ATIME flag gets set (which will result in atime being updated next time the filesystem gets sync-ed) just like what would happen during a read but we don't actually do the I/O involved in doing a read. A filesystem can just totally ignore this extra flag. Some filesystems don't support storing something that represents atime. Other filesystems will have needed to do a read to support accessing the executable anyway (NFS appears to do that - execve is using mmap to access the executable files which is why this bug exists but the mechanism used by NFS to provide access to the file appears to use the same basic thing as reads). Does anyone see any problems with this one? Thanks... Index: sys/sys/vnode.h =================================================================== RCS file: /home/ncvs/src/sys/sys/vnode.h,v retrieving revision 1.280 diff -u -r1.280 vnode.h --- sys/sys/vnode.h 10 Feb 2005 12:28:58 -0000 1.280 +++ sys/sys/vnode.h 14 Feb 2005 15:30:40 -0000 @@ -255,6 +255,7 @@ */ #define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ #define VA_EXCLUSIVE 0x02 /* exclusive create request */ +#define VA_EXECVE_ATIME 0x04 /* setting atime for execve */ /* * Flags for ioflag. (high 16 bits used to ask for read-ahead and Index: sys/kern/kern_exec.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_exec.c,v retrieving revision 1.265 diff -u -r1.265 kern_exec.c --- sys/kern/kern_exec.c 29 Jan 2005 23:51:05 -0000 1.265 +++ sys/kern/kern_exec.c 14 Feb 2005 15:17:33 -0000 @@ -280,7 +280,7 @@ register_t *stack_base; int error, len, i; struct image_params image_params, *imgp; - struct vattr attr; + struct vattr atimeattr, attr; int (*img_first)(struct image_params *); struct pargs *oldargs = NULL, *newargs = NULL; struct sigacts *oldsigacts, *newsigacts; @@ -672,6 +672,18 @@ exec_setregs(td, imgp->entry_addr, (u_long)(uintptr_t)stack_base, imgp->ps_strings); + /* + * Here we should update the access time of the file. This must + * be handled by the underlying filesystem in the same way that + * the atime gets updated for a VOP_READ() because we have not + * called vn_start_write(). + */ + if (!(ndp->ni_vp->v_mount->mnt_flag & (MNT_NOATIME | MNT_RDONLY))) { + VATTR_NULL(&atimeattr); + atimeattr.va_vaflags |= VA_EXECVE_ATIME; + (void) VOP_SETATTR(ndp->ni_vp, &atimeattr, td->td_ucred, td); + } + done1: /* * Free any resources malloc'd earlier that we didn't use. Index: sys/ufs/ufs/ufs_vnops.c =================================================================== RCS file: /home/ncvs/src/sys/ufs/ufs/ufs_vnops.c,v retrieving revision 1.264 diff -u -r1.264 ufs_vnops.c --- sys/ufs/ufs/ufs_vnops.c 8 Feb 2005 21:31:10 -0000 1.264 +++ sys/ufs/ufs/ufs_vnops.c 14 Feb 2005 15:19:26 -0000 @@ -511,6 +511,17 @@ if (vap->va_flags & (IMMUTABLE | APPEND)) return (0); } + /* + * Update the file access time when it has been executed. We are + * doing this here to specifically avoid some of the checks done + * below -- this operation is done by request of the kernel and + * should bypass some security checks. Things like read-only + * checks get handled by lower levels (e.g., ffs_update()). + */ + if (vap->va_vaflags & VA_EXECVE_ATIME) { + ip->i_flag |= IN_ACCESS; + return (0); + } if (ip->i_flags & (IMMUTABLE | APPEND)) return (EPERM); /* -- Ken Smith - From there to here, from here to | kensmith@cse.buffalo.edu there, funny things are everywhere. | - Theodore Geisel | From owner-freebsd-standards@FreeBSD.ORG Fri Feb 18 20:30:56 2005 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D4EAB16A4CE; Fri, 18 Feb 2005 20:30:56 +0000 (GMT) Received: from rwcrmhc13.comcast.net (rwcrmhc13.comcast.net [204.127.198.39]) by mx1.FreeBSD.org (Postfix) with ESMTP id 76A4A43D2F; Fri, 18 Feb 2005 20:30:56 +0000 (GMT) (envelope-from rodrigc@crodrigues.org) Received: from h00609772adf0.ne.client2.attbi.com ([66.30.114.143]) by comcast.net (rwcrmhc13) with ESMTP id <2005021820305501500l3lk0e>; Fri, 18 Feb 2005 20:30:55 +0000 Received: from h00609772adf0.ne.client2.attbi.com (localhost [127.0.0.1]) j1IKUlm9012448; Fri, 18 Feb 2005 15:30:55 -0500 (EST) (envelope-from rodrigc@h00609772adf0.ne.client2.attbi.com) Received: (from rodrigc@localhost)j1IKUk22012447; Fri, 18 Feb 2005 15:30:46 -0500 (EST) (envelope-from rodrigc) Date: Fri, 18 Feb 2005 15:30:45 -0500 From: Craig Rodrigues To: freebsd-gnats-submit@freebsd.org Message-ID: <20050218203045.GA12436@crodrigues.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i cc: tmclaugh@sdf.lonestar.org cc: freebsd-standards@freebsd.org Subject: Re: threads/76938: include/unistd.h: ttyname_r prototype missing X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Feb 2005 20:30:57 -0000 The following patch exports ttyname_r() from and makes it conform to the Single Unix Specification: http://www.opengroup.org/onlinepubs/009695399/functions/ttyname.html Can someone with a commit bit take a look at it? -- Craig Rodrigues rodrigc@crodrigues.org --- lib/libc/gen/ttyname.3.orig Thu Feb 17 17:10:20 2005 +++ lib/libc/gen/ttyname.3 Fri Feb 18 15:10:31 2005 @@ -37,6 +37,7 @@ .Os .Sh NAME .Nm ttyname , +.Nm ttyname_r , .Nm isatty , .Nm ttyslot .Nd get name of associated terminal (tty) from file descriptor @@ -47,6 +48,8 @@ .Ft char * .Fn ttyname "int fd" .Ft int +.Fn ttyname_r "int fd" "char *buf" "size_t bufsize" +.Ft int .Fn isatty "int fd" .Ft int .Fn ttyslot void @@ -80,7 +83,13 @@ gets the related device name of a file descriptor for which .Fn isatty -is true +is true. +.Pp +.Fn ttyname +returns the name stored in a static buffer which will be overwritten +on subsequent calls. +.Fn ttyname_r +takes a buffer and length as arguments to avoid this problem. .Pp The .Fn ttyslot @@ -98,12 +107,25 @@ a .Dv NULL pointer is returned. +The +.Fn ttyname_r +function returns 0 if successful. Otherwise an error number is returned. .Pp The .Fn ttyslot function returns the unit number of the device file if found; otherwise the value zero is returned. +.Sh ERRORS +.Fn ttyname_r +may return the following error codes: +.Bl -tag -width Er +.It Bq Er ENOTTY +.Fa fd +is not a valid file descriptor. +.It Bq Er ERANGE +.Fa bufsize +is smaller than the length of the string to be returned. .Sh FILES .Bl -tag -width /etc/ttys -compact .It Pa /dev/\(** @@ -121,11 +143,6 @@ function appeared in .At v7 . -.Sh BUGS -The -.Fn ttyname -function leaves its result in an internal static object and returns -a pointer to that object. -Subsequent calls to -.Fn ttyname -will modify the same object. +.Fn ttyname_r +appeared in +.Fx 6.0 . --- lib/libc/gen/ttyname.c.orig Thu Feb 17 17:14:32 2005 +++ lib/libc/gen/ttyname.c Fri Feb 18 15:20:09 2005 @@ -48,12 +48,13 @@ #include #include #include +#include #include "un-namespace.h" #include "libc_private.h" static char buf[sizeof(_PATH_DEV) + MAXNAMLEN]; -static char *ttyname_threaded(int fd); +static void ttyname_threaded(int fd, char **b); static char *ttyname_unthreaded(int fd); static pthread_mutex_t ttyname_lock = PTHREAD_MUTEX_INITIALIZER; @@ -68,45 +69,41 @@ if (__isthreaded == 0) ret = ttyname_unthreaded(fd); else - ret = ttyname_threaded(fd); + ttyname_threaded(fd, &ret); return (ret); } -char * +int ttyname_r(int fd, char *buf, size_t len) { struct stat sb; - char *rval; - - rval = NULL; /* Must be a terminal. */ if (!isatty(fd)) - return (rval); + return ENOTTY; /* Must be a character device. */ if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) - return (rval); + return ENOTTY; /* Must have enough room */ if (len <= sizeof(_PATH_DEV)) - return (rval); + return ERANGE; strcpy(buf, _PATH_DEV); devname_r(sb.st_rdev, S_IFCHR, - buf + strlen(buf), sizeof(buf) - strlen(buf)); - return (buf); + buf + strlen(buf), len - strlen(buf)); + return 0; } -static char * -ttyname_threaded(int fd) +static void +ttyname_threaded(int fd, char **b) { - char *buf; - if (ttyname_init == 0) { _pthread_mutex_lock(&ttyname_lock); if (ttyname_init == 0) { if (_pthread_key_create(&ttyname_key, free)) { _pthread_mutex_unlock(&ttyname_lock); - return (NULL); + *b = NULL; + return; } ttyname_init = 1; } @@ -114,17 +111,19 @@ } /* Must have thread specific data field to put data */ - if ((buf = _pthread_getspecific(ttyname_key)) == NULL) { - if ((buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN)) != NULL) { - if (_pthread_setspecific(ttyname_key, buf) != 0) { - free(buf); - return (NULL); + if ((*b = _pthread_getspecific(ttyname_key)) == NULL) { + if ((*b = malloc(sizeof(_PATH_DEV) + MAXNAMLEN)) != NULL) { + if (_pthread_setspecific(ttyname_key, *b) != 0) { + free(*b); + *b = NULL; + return; } } else { - return (NULL); + *b = NULL; + return; } } - return (ttyname_r(fd, buf, sizeof(_PATH_DEV) + MAXNAMLEN)); + ttyname_r(fd, *b, sizeof(_PATH_DEV) + MAXNAMLEN); } static char * --- include/unistd.h.orig Thu Feb 17 17:37:41 2005 +++ include/unistd.h Thu Feb 17 17:38:19 2005 @@ -365,6 +365,7 @@ pid_t tcgetpgrp(int); int tcsetpgrp(int, pid_t); char *ttyname(int); +int ttyname_r(int, char *, size_t); int unlink(const char *); ssize_t write(int, const void *, size_t);