Add procstat_getumask function to retrieve a process umask.

MFC after:	1 month
This commit is contained in:
Mikolaj Golub 2013-04-20 07:57:08 +00:00
parent e40d6078cd
commit 5b9bcba971
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=249672
6 changed files with 80 additions and 0 deletions

View File

@ -20,6 +20,7 @@ FBSD_1.3 {
procstat_freevmmap;
procstat_get_shm_info;
procstat_getgroups;
procstat_getumask;
procstat_getvmmap;
procstat_open_core;
};

View File

@ -171,6 +171,10 @@ procstat_core_get(struct procstat_core *core, enum psc_type type, void *buf,
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);

View File

@ -34,6 +34,7 @@ enum psc_type {
PSC_TYPE_FILES,
PSC_TYPE_VMMAP,
PSC_TYPE_GROUPS,
PSC_TYPE_UMASK,
};
struct procstat_core;

View File

@ -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 allocated memory with a subsequent
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

View File

@ -135,6 +135,9 @@ static int procstat_get_vnode_info_sysctl(struct filestat *fst,
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 *procstat __unused, gid_t *groups)
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);
}
}

View File

@ -168,6 +168,8 @@ int procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
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);