Date: Sat, 20 Apr 2013 07:57:08 +0000 (UTC) From: Mikolaj Golub <trociny@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r249672 - head/lib/libprocstat Message-ID: <201304200757.r3K7v84N096689@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trociny Date: Sat Apr 20 07:57:08 2013 New Revision: 249672 URL: http://svnweb.freebsd.org/changeset/base/249672 Log: Add procstat_getumask function to retrieve a process umask. MFC after: 1 month Modified: head/lib/libprocstat/Symbol.map head/lib/libprocstat/core.c head/lib/libprocstat/core.h head/lib/libprocstat/libprocstat.3 head/lib/libprocstat/libprocstat.c head/lib/libprocstat/libprocstat.h Modified: head/lib/libprocstat/Symbol.map ============================================================================== --- head/lib/libprocstat/Symbol.map Sat Apr 20 07:55:31 2013 (r249671) +++ head/lib/libprocstat/Symbol.map Sat Apr 20 07:57:08 2013 (r249672) @@ -20,6 +20,7 @@ FBSD_1.3 { procstat_freevmmap; procstat_get_shm_info; procstat_getgroups; + procstat_getumask; procstat_getvmmap; procstat_open_core; }; Modified: head/lib/libprocstat/core.c ============================================================================== --- head/lib/libprocstat/core.c Sat Apr 20 07:55:31 2013 (r249671) +++ head/lib/libprocstat/core.c Sat Apr 20 07:57:08 2013 (r249672) @@ -171,6 +171,10 @@ procstat_core_get(struct procstat_core * n_type = NT_PROCSTAT_GROUPS; structsize = sizeof(gid_t); break; + case PSC_TYPE_UMASK: + n_type = NT_PROCSTAT_UMASK; + structsize = sizeof(u_short); + break; default: warnx("unknown core stat type: %d", type); return (NULL); Modified: head/lib/libprocstat/core.h ============================================================================== --- head/lib/libprocstat/core.h Sat Apr 20 07:55:31 2013 (r249671) +++ head/lib/libprocstat/core.h Sat Apr 20 07:57:08 2013 (r249672) @@ -34,6 +34,7 @@ enum psc_type { PSC_TYPE_FILES, PSC_TYPE_VMMAP, PSC_TYPE_GROUPS, + PSC_TYPE_UMASK, }; struct procstat_core; Modified: head/lib/libprocstat/libprocstat.3 ============================================================================== --- head/lib/libprocstat/libprocstat.3 Sat Apr 20 07:55:31 2013 (r249671) +++ head/lib/libprocstat/libprocstat.3 Sat Apr 20 07:57:08 2013 (r249672) @@ -35,6 +35,7 @@ .Nm procstat_getfiles , .Nm procstat_getgroups , .Nm procstat_getprocs , +.Nm procstat_getumask , .Nm procstat_getvmmap , .Nm procstat_freefiles , .Nm procstat_freegroups , @@ -126,6 +127,12 @@ .Fa "int arg" .Fa "unsigned int *count" .Fc +.Ft "int" +.Fo procstat_getumask +.Fa "struct procstat *procstat" +.Fa "struct kinfo_proc *kp" +.Fa "unsigned short *maskp" +.Fc .Ft "struct kinfo_vmentry *" .Fo procstat_getvmmap .Fa "struct procstat *procstat" @@ -254,6 +261,14 @@ The caller is responsible to free the al function call. .Pp The +.Fn procstat_getumask +function gets a pointer to the +.Vt procstat +structure, a pointer to +.Vt kinfo_proc +structure, and returns the process umask in the 3rd reference parameter. +.Pp +The .Fn procstat_getvmmap function gets a pointer to the .Vt procstat Modified: head/lib/libprocstat/libprocstat.c ============================================================================== --- head/lib/libprocstat/libprocstat.c Sat Apr 20 07:55:31 2013 (r249671) +++ head/lib/libprocstat/libprocstat.c Sat Apr 20 07:57:08 2013 (r249672) @@ -135,6 +135,9 @@ static int procstat_get_vnode_info_sysct static gid_t *procstat_getgroups_core(struct procstat_core *core, unsigned int *count); static gid_t *procstat_getgroups_sysctl(pid_t pid, unsigned int *count); +static int procstat_getumask_core(struct procstat_core *core, + unsigned short *maskp); +static int procstat_getumask_sysctl(pid_t pid, unsigned short *maskp); static int vntype2psfsttype(int type); void @@ -1655,3 +1658,57 @@ procstat_freegroups(struct procstat *pro free(groups); } + +static int +procstat_getumask_sysctl(pid_t pid, unsigned short *maskp) +{ + int error; + int mib[4]; + size_t len; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_UMASK; + mib[3] = pid; + len = sizeof(*maskp); + error = sysctl(mib, 4, maskp, &len, NULL, 0); + if (error != 0 && errno != ESRCH) + warn("sysctl: kern.proc.umask: %d", pid); + return (error); +} + +static int +procstat_getumask_core(struct procstat_core *core, unsigned short *maskp) +{ + size_t len; + unsigned short *buf; + + buf = procstat_core_get(core, PSC_TYPE_UMASK, NULL, &len); + if (buf == NULL) + return (-1); + if (len < sizeof(*maskp)) { + free(buf); + return (-1); + } + *maskp = *buf; + free(buf); + return (0); +} + +int +procstat_getumask(struct procstat *procstat, struct kinfo_proc *kp, + unsigned short *maskp) +{ + switch(procstat->type) { + case PROCSTAT_KVM: + warnx("kvm method is not supported"); + return (-1); + case PROCSTAT_SYSCTL: + return (procstat_getumask_sysctl(kp->ki_pid, maskp)); + case PROCSTAT_CORE: + return (procstat_getumask_core(procstat->core, maskp)); + default: + warnx("unknown access method: %d", procstat->type); + return (-1); + } +} Modified: head/lib/libprocstat/libprocstat.h ============================================================================== --- head/lib/libprocstat/libprocstat.h Sat Apr 20 07:55:31 2013 (r249671) +++ head/lib/libprocstat/libprocstat.h Sat Apr 20 07:57:08 2013 (r249672) @@ -168,6 +168,8 @@ int procstat_get_vnode_info(struct procs struct vnstat *vn, char *errbuf); gid_t *procstat_getgroups(struct procstat *procstat, struct kinfo_proc *kp, unsigned int *count); +int procstat_getumask(struct procstat *procstat, struct kinfo_proc *kp, + unsigned short* umask); struct kinfo_vmentry *procstat_getvmmap(struct procstat *procstat, struct kinfo_proc *kp, unsigned int *count); struct procstat *procstat_open_core(const char *filename);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201304200757.r3K7v84N096689>