From owner-svn-src-all@FreeBSD.ORG Fri Nov 15 19:55:37 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 551F497A; Fri, 15 Nov 2013 19:55:37 +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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 441F1219B; Fri, 15 Nov 2013 19:55:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rAFJtbo1055270; Fri, 15 Nov 2013 19:55:37 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rAFJtanx055262; Fri, 15 Nov 2013 19:55:36 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201311151955.rAFJtanx055262@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Fri, 15 Nov 2013 19:55:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r258181 - in head: sys/kern sys/sys usr.bin/procstat 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.16 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: Fri, 15 Nov 2013 19:55:37 -0000 Author: pjd Date: Fri Nov 15 19:55:35 2013 New Revision: 258181 URL: http://svnweb.freebsd.org/changeset/base/258181 Log: Replace CAP_POLL_EVENT and CAP_POST_EVENT capability rights (which I had a very hard time to fully understand) with much more intuitive rights: CAP_EVENT - when set on descriptor, the descriptor can be monitored with syscalls like select(2), poll(2), kevent(2). CAP_KQUEUE_EVENT - When set on a kqueue descriptor, the kevent(2) syscall can be called on this kqueue to with the eventlist argument set to non-NULL value; in other words the given kqueue descriptor can be used to monitor other descriptors. CAP_KQUEUE_CHANGE - When set on a kqueue descriptor, the kevent(2) syscall can be called on this kqueue to with the changelist argument set to non-NULL value; in other words it allows to modify events monitored with the given kqueue descriptor. Add alias CAP_KQUEUE, which allows for both CAP_KQUEUE_EVENT and CAP_KQUEUE_CHANGE. Add backward compatibility define CAP_POLL_EVENT which is equal to CAP_EVENT. Sponsored by: The FreeBSD Foundation MFC after: 3 days Modified: head/sys/kern/kern_event.c head/sys/kern/sys_generic.c head/sys/kern/uipc_mqueue.c head/sys/sys/capability.h head/usr.bin/procstat/procstat_files.c Modified: head/sys/kern/kern_event.c ============================================================================== --- head/sys/kern/kern_event.c Fri Nov 15 19:01:29 2013 (r258180) +++ head/sys/kern/kern_event.c Fri Nov 15 19:55:35 2013 (r258181) @@ -855,10 +855,17 @@ kern_kevent(struct thread *td, int fd, i cap_rights_t rights; int i, n, nerrors, error; - error = fget(td, fd, cap_rights_init(&rights, CAP_POST_EVENT), &fp); + cap_rights_init(&rights); + if (nchanges > 0) + cap_rights_set(&rights, CAP_KQUEUE_CHANGE); + if (nevents > 0) + cap_rights_set(&rights, CAP_KQUEUE_EVENT); + error = fget(td, fd, &rights, &fp); if (error != 0) return (error); - if ((error = kqueue_acquire(fp, &kq)) != 0) + + error = kqueue_acquire(fp, &kq); + if (error != 0) goto done_norel; nerrors = 0; @@ -1015,7 +1022,7 @@ findkn: if (fops->f_isfd) { KASSERT(td != NULL, ("td is NULL")); error = fget(td, kev->ident, - cap_rights_init(&rights, CAP_POLL_EVENT), &fp); + cap_rights_init(&rights, CAP_EVENT), &fp); if (error) goto done; @@ -2301,7 +2308,7 @@ kqfd_register(int fd, struct kevent *kev cap_rights_t rights; int error; - error = fget(td, fd, cap_rights_init(&rights, CAP_POST_EVENT), &fp); + error = fget(td, fd, cap_rights_init(&rights, CAP_KQUEUE_CHANGE), &fp); if (error != 0) return (error); if ((error = kqueue_acquire(fp, &kq)) != 0) Modified: head/sys/kern/sys_generic.c ============================================================================== --- head/sys/kern/sys_generic.c Fri Nov 15 19:01:29 2013 (r258180) +++ head/sys/kern/sys_generic.c Fri Nov 15 19:55:35 2013 (r258181) @@ -1195,8 +1195,9 @@ getselfd_cap(struct filedesc *fdp, int f { cap_rights_t rights; - return (fget_unlocked(fdp, fd, cap_rights_init(&rights, CAP_POLL_EVENT), - 0, fpp, NULL)); + cap_rights_init(&rights, CAP_EVENT); + + return (fget_unlocked(fdp, fd, &rights, 0, fpp, NULL)); } /* @@ -1392,7 +1393,7 @@ pollrescan(struct thread *td) #ifdef CAPABILITIES if (fp == NULL || cap_check(cap_rights(fdp, fd->fd), - cap_rights_init(&rights, CAP_POLL_EVENT)) != 0) + cap_rights_init(&rights, CAP_EVENT)) != 0) #else if (fp == NULL) #endif @@ -1467,7 +1468,7 @@ pollscan(td, fds, nfd) #ifdef CAPABILITIES if (fp == NULL || cap_check(cap_rights(fdp, fds->fd), - cap_rights_init(&rights, CAP_POLL_EVENT)) != 0) + cap_rights_init(&rights, CAP_EVENT)) != 0) #else if (fp == NULL) #endif Modified: head/sys/kern/uipc_mqueue.c ============================================================================== --- head/sys/kern/uipc_mqueue.c Fri Nov 15 19:01:29 2013 (r258180) +++ head/sys/kern/uipc_mqueue.c Fri Nov 15 19:55:35 2013 (r258181) @@ -2119,7 +2119,7 @@ getmq(struct thread *td, int fd, struct { cap_rights_t rights; - return _getmq(td, fd, cap_rights_init(&rights, CAP_POLL_EVENT), fget, + return _getmq(td, fd, cap_rights_init(&rights, CAP_EVENT), fget, fpp, ppn, pmq); } @@ -2282,7 +2282,7 @@ again: } #ifdef CAPABILITIES error = cap_check(cap_rights(fdp, mqd), - cap_rights_init(&rights, CAP_POLL_EVENT)); + cap_rights_init(&rights, CAP_EVENT)); if (error) { FILEDESC_SUNLOCK(fdp); goto out; Modified: head/sys/sys/capability.h ============================================================================== --- head/sys/sys/capability.h Fri Nov 15 19:01:29 2013 (r258180) +++ head/sys/sys/capability.h Fri Nov 15 19:55:35 2013 (r258181) @@ -226,9 +226,10 @@ #define CAP_SEM_POST CAPRIGHT(1, 0x0000000000000008ULL) #define CAP_SEM_WAIT CAPRIGHT(1, 0x0000000000000010ULL) -/* kqueue events. */ -#define CAP_POLL_EVENT CAPRIGHT(1, 0x0000000000000020ULL) -#define CAP_POST_EVENT CAPRIGHT(1, 0x0000000000000040ULL) +/* Allows select(2) and poll(2) on descriptor. */ +#define CAP_EVENT CAPRIGHT(1, 0x0000000000000020ULL) +/* Allows for kevent(2) on kqueue descriptor with eventlist != NULL. */ +#define CAP_KQUEUE_EVENT CAPRIGHT(1, 0x0000000000000040ULL) /* Strange and powerful rights that should not be given lightly. */ /* Allows for ioctl(2). */ @@ -263,14 +264,22 @@ /* Allows for acl_set_fd(3) and acl_set_fd_np(3). */ #define CAP_ACL_SET CAPRIGHT(1, 0x0000000000080000ULL) +/* Allows for kevent(2) on kqueue descriptor with changelist != NULL. */ +#define CAP_KQUEUE_CHANGE CAPRIGHT(1, 0x0000000000100000ULL) + +#define CAP_KQUEUE (CAP_KQUEUE_EVENT | CAP_KQUEUE_CHANGE) + /* All used bits for index 1. */ -#define CAP_ALL1 CAPRIGHT(1, 0x00000000000FFFFFULL) +#define CAP_ALL1 CAPRIGHT(1, 0x00000000001FFFFFULL) /* Available bits for index 1. */ -#define CAP_UNUSED1_21 CAPRIGHT(1, 0x0000000000100000ULL) +#define CAP_UNUSED1_22 CAPRIGHT(1, 0x0000000000200000ULL) /* ... */ #define CAP_UNUSED1_57 CAPRIGHT(1, 0x0100000000000000ULL) +/* Backward compatibility. */ +#define CAP_POLL_EVENT CAP_EVENT + #define CAP_ALL(rights) do { \ (rights)->cr_rights[0] = \ ((uint64_t)CAP_RIGHTS_VERSION << 62) | CAP_ALL0; \ Modified: head/usr.bin/procstat/procstat_files.c ============================================================================== --- head/usr.bin/procstat/procstat_files.c Fri Nov 15 19:01:29 2013 (r258180) +++ head/usr.bin/procstat/procstat_files.c Fri Nov 15 19:55:35 2013 (r258181) @@ -203,8 +203,9 @@ static struct cap_desc { { CAP_SEM_WAIT, "sw" }, /* Event monitoring and posting. */ - { CAP_POLL_EVENT, "po" }, - { CAP_POST_EVENT, "ev" }, + { CAP_EVENT, "ev" }, + { CAP_KQUEUE_EVENT, "ke" }, + { CAP_KQUEUE_CHANGE, "kc" }, /* Strange and powerful rights that should not be given lightly. */ { CAP_IOCTL, "io" },