summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1999-11-16 20:31:58 +0000
committerphk <phk@FreeBSD.org>1999-11-16 20:31:58 +0000
commitcc6b664e2eb821b39837e7bb980e5ee87e201491 (patch)
tree65eeb4add32e588f36f28e2a0bb819c17a67ff70 /lib
parent47e5f46c7642e6d8e2ed20c8afca59596d3c2dc1 (diff)
downloadFreeBSD-src-cc6b664e2eb821b39837e7bb980e5ee87e201491.zip
FreeBSD-src-cc6b664e2eb821b39837e7bb980e5ee87e201491.tar.gz
Introduce commandline caching in the kernel.
This fixes some nasty procfs problems for SMP, makes ps(1) run much faster, and makes ps(1) even less dependent on /proc which will aid chroot and jails alike. To disable this facility and revert to previous behaviour: sysctl -w kern.ps_arg_cache_limit=0 For full details see the current@FreeBSD.org mail-archives.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/setproctitle.c9
-rw-r--r--lib/libkvm/kvm_proc.c48
-rw-r--r--lib/libutil/setproctitle.c9
3 files changed, 66 insertions, 0 deletions
diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c
index a5cf234..36c21db 100644
--- a/lib/libc/gen/setproctitle.c
+++ b/lib/libc/gen/setproctitle.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
/*
* Older FreeBSD 2.0, 2.1 and 2.2 had different ps_strings structures and
@@ -74,6 +75,7 @@ setproctitle(fmt, va_alist)
va_list ap;
size_t len;
unsigned long ul_ps_strings;
+ int oid[4];
#if defined(__STDC__)
va_start(ap, fmt);
@@ -103,6 +105,13 @@ setproctitle(fmt, va_alist)
va_end(ap);
+ /* Set the title into the kernel cached command line */
+ oid[0] = CTL_KERN;
+ oid[1] = KERN_PROC;
+ oid[2] = KERN_PROC_ARGS;
+ oid[3] = getpid();
+ sysctl(oid, 4, 0, 0, buf, strlen(buf) + 1);
+
if (ps_strings == NULL) {
len = sizeof(ul_ps_strings);
if (sysctlbyname("kern.ps_strings", &ul_ps_strings, &len, NULL,
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c
index 9543fee..feba974 100644
--- a/lib/libkvm/kvm_proc.c
+++ b/lib/libkvm/kvm_proc.c
@@ -33,6 +33,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
#if defined(LIBC_SCCS) && !defined(lint)
@@ -666,6 +668,52 @@ kvm_getargv(kd, kp, nchr)
const struct kinfo_proc *kp;
int nchr;
{
+ int oid[4];
+ int i, l;
+ static int buflen;
+ static char *buf, *p;
+ static char **bufp;
+ static int argc;
+
+ if (!buflen) {
+ l = sizeof(buflen);
+ i = sysctlbyname("kern.ps_arg_cache_limit",
+ &buflen, &l, NULL, 0);
+ if (i == -1) {
+ buflen == 0;
+ } else {
+ buf = malloc(buflen);
+ if (buf == NULL)
+ buflen = 0;
+ argc = 32;
+ bufp = malloc(sizeof(char *) * argc);
+ }
+ }
+ if (buf != NULL) {
+ oid[0] = CTL_KERN;
+ oid[1] = KERN_PROC;
+ oid[2] = KERN_PROC_ARGS;
+ oid[3] = kp->kp_proc.p_pid;
+ l = buflen;
+ i = sysctl(oid, 4, buf, &l, 0, 0);
+ if (i == 0 && l > 0) {
+ i = 0;
+ p = buf;
+ do {
+ bufp[i++] = p;
+ p += strlen(p) + 1;
+ if (i >= argc) {
+ argc += argc;
+ bufp = realloc(bufp,
+ sizeof(char *) * argc);
+ }
+ } while (p < buf + l);
+ bufp[i++] = 0;
+ return (bufp);
+ }
+ }
+ if (kp->kp_proc.p_flag & P_SYSTEM)
+ return (NULL);
return (kvm_doargv(kd, kp, nchr, ps_str_a));
}
diff --git a/lib/libutil/setproctitle.c b/lib/libutil/setproctitle.c
index a5cf234..36c21db 100644
--- a/lib/libutil/setproctitle.c
+++ b/lib/libutil/setproctitle.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
/*
* Older FreeBSD 2.0, 2.1 and 2.2 had different ps_strings structures and
@@ -74,6 +75,7 @@ setproctitle(fmt, va_alist)
va_list ap;
size_t len;
unsigned long ul_ps_strings;
+ int oid[4];
#if defined(__STDC__)
va_start(ap, fmt);
@@ -103,6 +105,13 @@ setproctitle(fmt, va_alist)
va_end(ap);
+ /* Set the title into the kernel cached command line */
+ oid[0] = CTL_KERN;
+ oid[1] = KERN_PROC;
+ oid[2] = KERN_PROC_ARGS;
+ oid[3] = getpid();
+ sysctl(oid, 4, 0, 0, buf, strlen(buf) + 1);
+
if (ps_strings == NULL) {
len = sizeof(ul_ps_strings);
if (sysctlbyname("kern.ps_strings", &ul_ps_strings, &len, NULL,
OpenPOWER on IntegriCloud