From owner-svn-src-all@FreeBSD.ORG Mon Apr 2 19:15:32 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DCD20106566C; Mon, 2 Apr 2012 19:15:32 +0000 (UTC) (envelope-from trociny@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AF59F8FC0C; Mon, 2 Apr 2012 19:15:32 +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 q32JFW8P012860; Mon, 2 Apr 2012 19:15:32 GMT (envelope-from trociny@svn.freebsd.org) Received: (from trociny@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q32JFWKL012857; Mon, 2 Apr 2012 19:15:32 GMT (envelope-from trociny@svn.freebsd.org) Message-Id: <201204021915.q32JFWKL012857@svn.freebsd.org> From: Mikolaj Golub Date: Mon, 2 Apr 2012 19:15:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233806 - in stable/9/sys: kern sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Mon, 02 Apr 2012 19:15:33 -0000 Author: trociny Date: Mon Apr 2 19:15:32 2012 New Revision: 233806 URL: http://svn.freebsd.org/changeset/base/233806 Log: MFC r232181, r232455: r232181: Add sysctl to retrieve or set umask of another process. Submitted by: Dmitry Banschikov Discussed with: kib, rwatson Reviewed by: kib r232455: Make kern.proc.umask sysctl readonly. Requested by: src Modified: stable/9/sys/kern/kern_proc.c stable/9/sys/sys/sysctl.h Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/kern_proc.c ============================================================================== --- stable/9/sys/kern/kern_proc.c Mon Apr 2 19:13:02 2012 (r233805) +++ stable/9/sys/kern/kern_proc.c Mon Apr 2 19:15:32 2012 (r233806) @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -2471,6 +2472,33 @@ sysctl_kern_proc_ps_strings(SYSCTL_HANDL return (error); } +/* + * This sysctl allows a process to retrieve umask of another process. + */ +static int +sysctl_kern_proc_umask(SYSCTL_HANDLER_ARGS) +{ + int *name = (int *)arg1; + u_int namelen = arg2; + struct proc *p; + int error; + u_short fd_cmask; + + if (namelen != 1) + return (EINVAL); + + error = pget((pid_t)name[0], PGET_WANTREAD, &p); + if (error != 0) + return (error); + + FILEDESC_SLOCK(p->p_fd); + fd_cmask = p->p_fd->fd_cmask; + FILEDESC_SUNLOCK(p->p_fd); + PRELE(p); + error = SYSCTL_OUT(req, &fd_cmask, sizeof(fd_cmask)); + return (error); +} + SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD, 0, "Process table"); SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT| @@ -2572,3 +2600,6 @@ static SYSCTL_NODE(_kern_proc, KERN_PROC static SYSCTL_NODE(_kern_proc, KERN_PROC_PS_STRINGS, ps_strings, CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc_ps_strings, "Process ps_strings location"); + +static SYSCTL_NODE(_kern_proc, KERN_PROC_UMASK, umask, CTLFLAG_RD | + CTLFLAG_MPSAFE, sysctl_kern_proc_umask, "Process umask"); Modified: stable/9/sys/sys/sysctl.h ============================================================================== --- stable/9/sys/sys/sysctl.h Mon Apr 2 19:13:02 2012 (r233805) +++ stable/9/sys/sys/sysctl.h Mon Apr 2 19:15:32 2012 (r233806) @@ -563,6 +563,7 @@ SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a #define KERN_PROC_AUXV 36 /* get ELF auxiliary vector */ #define KERN_PROC_RLIMIT 37 /* process resource limits */ #define KERN_PROC_PS_STRINGS 38 /* get ps_strings location */ +#define KERN_PROC_UMASK 39 /* process umask */ /* * KERN_IPC identifiers