summaryrefslogtreecommitdiffstats
path: root/lib/libprocstat
diff options
context:
space:
mode:
authortrociny <trociny@FreeBSD.org>2013-04-20 08:03:56 +0000
committertrociny <trociny@FreeBSD.org>2013-04-20 08:03:56 +0000
commit72dafce20f72d7aa3e2fab75a4ef453d39b8dbdd (patch)
treeb4ce59716cb01690836df8b4dfc7522f3c47e658 /lib/libprocstat
parent93aa05a11832f64ae31ddaef20437c6224698efc (diff)
downloadFreeBSD-src-72dafce20f72d7aa3e2fab75a4ef453d39b8dbdd.zip
FreeBSD-src-72dafce20f72d7aa3e2fab75a4ef453d39b8dbdd.tar.gz
Add procstat_getosrel function to retrieve a process osrel info.
MFC after: 1 month
Diffstat (limited to 'lib/libprocstat')
-rw-r--r--lib/libprocstat/Symbol.map1
-rw-r--r--lib/libprocstat/core.c4
-rw-r--r--lib/libprocstat/core.h1
-rw-r--r--lib/libprocstat/libprocstat.314
-rw-r--r--lib/libprocstat/libprocstat.c52
-rw-r--r--lib/libprocstat/libprocstat.h2
6 files changed, 74 insertions, 0 deletions
diff --git a/lib/libprocstat/Symbol.map b/lib/libprocstat/Symbol.map
index c4db0f3..569c6f4 100644
--- a/lib/libprocstat/Symbol.map
+++ b/lib/libprocstat/Symbol.map
@@ -20,6 +20,7 @@ FBSD_1.3 {
procstat_freevmmap;
procstat_get_shm_info;
procstat_getgroups;
+ procstat_getosrel;
procstat_getpathname;
procstat_getrlimit;
procstat_getumask;
diff --git a/lib/libprocstat/core.c b/lib/libprocstat/core.c
index 2ff3975..e750222 100644
--- a/lib/libprocstat/core.c
+++ b/lib/libprocstat/core.c
@@ -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);
diff --git a/lib/libprocstat/core.h b/lib/libprocstat/core.h
index 967c193..4d572b1 100644
--- a/lib/libprocstat/core.h
+++ b/lib/libprocstat/core.h
@@ -36,6 +36,7 @@ enum psc_type {
PSC_TYPE_GROUPS,
PSC_TYPE_UMASK,
PSC_TYPE_RLIMIT,
+ PSC_TYPE_OSREL,
};
struct procstat_core;
diff --git a/lib/libprocstat/libprocstat.3 b/lib/libprocstat/libprocstat.3
index fd843cb..9fecf87 100644
--- a/lib/libprocstat/libprocstat.3
+++ b/lib/libprocstat/libprocstat.3
@@ -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
diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c
index e469f8e..6a71bf4 100644
--- a/lib/libprocstat/libprocstat.c
+++ b/lib/libprocstat/libprocstat.c
@@ -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);
+ }
+}
diff --git a/lib/libprocstat/libprocstat.h b/lib/libprocstat/libprocstat.h
index 24826ec..353948b 100644
--- a/lib/libprocstat/libprocstat.h
+++ b/lib/libprocstat/libprocstat.h
@@ -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,
OpenPOWER on IntegriCloud