Date: Mon, 2 Apr 2012 19:15:32 +0000 (UTC) From: Mikolaj Golub <trociny@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r233806 - in stable/9/sys: kern sys Message-ID: <201204021915.q32JFWKL012857@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <me ubique spb ru> 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 <sys/sched.h> #include <sys/smp.h> #include <sys/stack.h> +#include <sys/stat.h> #include <sys/sysctl.h> #include <sys/filedesc.h> #include <sys/tty.h> @@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204021915.q32JFWKL012857>