Add procstat_getosrel function to retrieve a process osrel info.
MFC after: 1 month
This commit is contained in:
parent
4cdf979641
commit
eec6cb1cf2
@ -20,6 +20,7 @@ FBSD_1.3 {
|
||||
procstat_freevmmap;
|
||||
procstat_get_shm_info;
|
||||
procstat_getgroups;
|
||||
procstat_getosrel;
|
||||
procstat_getpathname;
|
||||
procstat_getrlimit;
|
||||
procstat_getumask;
|
||||
|
@ -179,6 +179,10 @@ procstat_core_get(struct procstat_core *core, enum psc_type type, void *buf,
|
||||
n_type = NT_PROCSTAT_RLIMIT;
|
||||
structsize = sizeof(struct rlimit) * RLIM_NLIMITS;
|
||||
break;
|
||||
case PSC_TYPE_OSREL:
|
||||
n_type = NT_PROCSTAT_OSREL;
|
||||
structsize = sizeof(int);
|
||||
break;
|
||||
default:
|
||||
warnx("unknown core stat type: %d", type);
|
||||
return (NULL);
|
||||
|
@ -36,6 +36,7 @@ enum psc_type {
|
||||
PSC_TYPE_GROUPS,
|
||||
PSC_TYPE_UMASK,
|
||||
PSC_TYPE_RLIMIT,
|
||||
PSC_TYPE_OSREL,
|
||||
};
|
||||
|
||||
struct procstat_core;
|
||||
|
@ -34,6 +34,7 @@
|
||||
.Nm procstat_close ,
|
||||
.Nm procstat_getfiles ,
|
||||
.Nm procstat_getgroups ,
|
||||
.Nm procstat_getosrel ,
|
||||
.Nm procstat_getpathname ,
|
||||
.Nm procstat_getprocs ,
|
||||
.Nm procstat_getumask ,
|
||||
@ -120,6 +121,11 @@
|
||||
.Fa "struct procstat *procstat"
|
||||
.Fa "struct kinfo_proc *kp"
|
||||
.Fa "unsigned int *count"
|
||||
.Ft int
|
||||
.Fo procstat_getosrel
|
||||
.Fa "struct procstat *procstat"
|
||||
.Fa "struct kinfo_proc *kp"
|
||||
.Fa "int *osrelp"
|
||||
.Fc
|
||||
.Ft "struct kinfo_proc *"
|
||||
.Fo procstat_getprocs
|
||||
@ -276,6 +282,14 @@ The caller is responsible to free the allocated memory with a subsequent
|
||||
function call.
|
||||
.Pp
|
||||
The
|
||||
.Fn procstat_getosrel
|
||||
function gets a pointer to the
|
||||
.Vt procstat
|
||||
structure, a pointer to
|
||||
.Vt kinfo_proc
|
||||
structure, and returns osrel date in the 3rd reference parameter.
|
||||
.Pp
|
||||
The
|
||||
.Fn procstat_getpathname
|
||||
function gets a pointer to the
|
||||
.Vt procstat
|
||||
|
@ -1845,3 +1845,55 @@ procstat_getpathname(struct procstat *procstat, struct kinfo_proc *kp,
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
procstat_getosrel_sysctl(pid_t pid, int *osrelp)
|
||||
{
|
||||
int error, name[4];
|
||||
size_t len;
|
||||
|
||||
name[0] = CTL_KERN;
|
||||
name[1] = KERN_PROC;
|
||||
name[2] = KERN_PROC_OSREL;
|
||||
name[3] = pid;
|
||||
len = sizeof(*osrelp);
|
||||
error = sysctl(name, 4, osrelp, &len, NULL, 0);
|
||||
if (error != 0 && errno != ESRCH)
|
||||
warn("sysctl: kern.proc.osrel: %d", pid);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
procstat_getosrel_core(struct procstat_core *core, int *osrelp)
|
||||
{
|
||||
size_t len;
|
||||
int *buf;
|
||||
|
||||
buf = procstat_core_get(core, PSC_TYPE_OSREL, NULL, &len);
|
||||
if (buf == NULL)
|
||||
return (-1);
|
||||
if (len < sizeof(*osrelp)) {
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
*osrelp = *buf;
|
||||
free(buf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
procstat_getosrel(struct procstat *procstat, struct kinfo_proc *kp, int *osrelp)
|
||||
{
|
||||
switch(procstat->type) {
|
||||
case PROCSTAT_KVM:
|
||||
warnx("kvm method is not supported");
|
||||
return (-1);
|
||||
case PROCSTAT_SYSCTL:
|
||||
return (procstat_getosrel_sysctl(kp->ki_pid, osrelp));
|
||||
case PROCSTAT_CORE:
|
||||
return (procstat_getosrel_core(procstat->core, osrelp));
|
||||
default:
|
||||
warnx("unknown access method: %d", procstat->type);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +169,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_getosrel(struct procstat *procstat, struct kinfo_proc *kp,
|
||||
int *osrelp);
|
||||
int procstat_getpathname(struct procstat *procstat, struct kinfo_proc *kp,
|
||||
char *pathname, size_t maxlen);
|
||||
int procstat_getrlimit(struct procstat *procstat, struct kinfo_proc *kp,
|
||||
|
Loading…
Reference in New Issue
Block a user