svn commit: r249677 - head/lib/libprocstat
Mikolaj Golub
trociny at FreeBSD.org
Sat Apr 20 08:03:58 UTC 2013
Author: trociny
Date: Sat Apr 20 08:03:56 2013
New Revision: 249677
URL: http://svnweb.freebsd.org/changeset/base/249677
Log:
Add procstat_getosrel function to retrieve a process osrel info.
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 08:02:43 2013 (r249676)
+++ head/lib/libprocstat/Symbol.map Sat Apr 20 08:03:56 2013 (r249677)
@@ -20,6 +20,7 @@ FBSD_1.3 {
procstat_freevmmap;
procstat_get_shm_info;
procstat_getgroups;
+ procstat_getosrel;
procstat_getpathname;
procstat_getrlimit;
procstat_getumask;
Modified: head/lib/libprocstat/core.c
==============================================================================
--- head/lib/libprocstat/core.c Sat Apr 20 08:02:43 2013 (r249676)
+++ head/lib/libprocstat/core.c Sat Apr 20 08:03:56 2013 (r249677)
@@ -179,6 +179,10 @@ procstat_core_get(struct procstat_core *
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);
Modified: head/lib/libprocstat/core.h
==============================================================================
--- head/lib/libprocstat/core.h Sat Apr 20 08:02:43 2013 (r249676)
+++ head/lib/libprocstat/core.h Sat Apr 20 08:03:56 2013 (r249677)
@@ -36,6 +36,7 @@ enum psc_type {
PSC_TYPE_GROUPS,
PSC_TYPE_UMASK,
PSC_TYPE_RLIMIT,
+ PSC_TYPE_OSREL,
};
struct procstat_core;
Modified: head/lib/libprocstat/libprocstat.3
==============================================================================
--- head/lib/libprocstat/libprocstat.3 Sat Apr 20 08:02:43 2013 (r249676)
+++ head/lib/libprocstat/libprocstat.3 Sat Apr 20 08:03:56 2013 (r249677)
@@ -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 al
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
Modified: head/lib/libprocstat/libprocstat.c
==============================================================================
--- head/lib/libprocstat/libprocstat.c Sat Apr 20 08:02:43 2013 (r249676)
+++ head/lib/libprocstat/libprocstat.c Sat Apr 20 08:03:56 2013 (r249677)
@@ -1845,3 +1845,55 @@ procstat_getpathname(struct procstat *pr
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);
+ }
+}
Modified: head/lib/libprocstat/libprocstat.h
==============================================================================
--- head/lib/libprocstat/libprocstat.h Sat Apr 20 08:02:43 2013 (r249676)
+++ head/lib/libprocstat/libprocstat.h Sat Apr 20 08:03:56 2013 (r249677)
@@ -169,6 +169,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_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,
More information about the svn-src-head
mailing list