Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/ps g/c procfs fallback code, it's redundant now that we ...
details: https://anonhg.NetBSD.org/src/rev/dd737c252c2b
branches: trunk
changeset: 533019:dd737c252c2b
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Wed Jun 19 08:11:55 2002 +0000
description:
g/c procfs fallback code, it's redundant now that we use sysctl to get
process info
diffstat:
bin/ps/Makefile | 4 +-
bin/ps/extern.h | 4 +-
bin/ps/print.c | 14 +-
bin/ps/procfs_ops.c | 407 ----------------------------------------------------
bin/ps/ps.1 | 38 +----
bin/ps/ps.c | 40 +----
6 files changed, 16 insertions(+), 491 deletions(-)
diffs (truncated from 663 to 300 lines):
diff -r 855eb2909f12 -r dd737c252c2b bin/ps/Makefile
--- a/bin/ps/Makefile Wed Jun 19 05:30:09 2002 +0000
+++ b/bin/ps/Makefile Wed Jun 19 08:11:55 2002 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.27 2000/05/26 03:04:28 simonb Exp $
+# $NetBSD: Makefile,v 1.28 2002/06/19 08:11:55 jdolecek Exp $
# @(#)Makefile 8.1 (Berkeley) 6/2/93
PROG= ps
-SRCS= fmt.c keyword.c nlist.c print.c ps.c procfs_ops.c
+SRCS= fmt.c keyword.c nlist.c print.c ps.c
DPADD= ${LIBM} ${LIBKVM}
LDADD= -lm -lkvm
diff -r 855eb2909f12 -r dd737c252c2b bin/ps/extern.h
--- a/bin/ps/extern.h Wed Jun 19 05:30:09 2002 +0000
+++ b/bin/ps/extern.h Wed Jun 19 08:11:55 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.20 2001/07/14 06:53:43 matt Exp $ */
+/* $NetBSD: extern.h,v 1.21 2002/06/19 08:11:55 jdolecek Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -43,7 +43,7 @@
extern double ccpu;
extern int eval, fscale, mempages, nlistread, rawcpu, maxslp, uspace;
extern int sumrusage, termwidth, totwidth;
-extern int needenv, needcomm, commandonly, dontuseprocfs, use_procfs;
+extern int needenv, needcomm, commandonly, dontuseprocfs;
extern uid_t myuid;
extern kvm_t *kd;
extern VAR var[];
diff -r 855eb2909f12 -r dd737c252c2b bin/ps/print.c
--- a/bin/ps/print.c Wed Jun 19 05:30:09 2002 +0000
+++ b/bin/ps/print.c Wed Jun 19 08:11:55 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: print.c,v 1.73 2002/06/17 16:48:44 christos Exp $ */
+/* $NetBSD: print.c,v 1.74 2002/06/19 08:11:55 jdolecek Exp $ */
/*
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
#if 0
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
#else
-__RCSID("$NetBSD: print.c,v 1.73 2002/06/17 16:48:44 christos Exp $");
+__RCSID("$NetBSD: print.c,v 1.74 2002/06/19 08:11:55 jdolecek Exp $");
#endif
#endif /* not lint */
@@ -299,11 +299,7 @@
if (needcomm) {
name = ki->p_comm;
if (!commandonly) {
- argv = NULL;
- if (!use_procfs)
- argv = kvm_getargv2(kd, ki, termwidth);
- else
- argv = procfs_getargv(ki, termwidth);
+ argv = kvm_getargv2(kd, ki, termwidth);
if ((p = argv) != NULL) {
while (*p) {
fmt_puts(*p, &left);
@@ -321,10 +317,6 @@
fmt_puts(name, &left);
fmt_putc(')', &left);
}
- if (use_procfs) {
- free(argv[0]);
- free(argv);
- }
} else {
/*
* Commands that don't set an argv vector
diff -r 855eb2909f12 -r dd737c252c2b bin/ps/procfs_ops.c
--- a/bin/ps/procfs_ops.c Wed Jun 19 05:30:09 2002 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,407 +0,0 @@
-/* $NetBSD: procfs_ops.c,v 1.9 2000/05/26 03:04:28 simonb Exp $ */
-
-/*
- * Copyright (c) 1999 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Brian Grayson (bgrayson%netbsd.org@localhost).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT 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.
- */
-
-#include <sys/cdefs.h>
-#include <sys/param.h>
-#include <sys/mount.h>
-#include <sys/sysctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/resource.h> /* for rusage */
-
-#include <fcntl.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <err.h>
-#include <kvm.h>
-
-#include "ps.h"
-
-/* Assume that no process status file will ever be larger than this. */
-#define STATUS_SIZE 8192
-
-/*
- * Handy macro for only printing a warning once. Notice that
- * one needs to use two sets of parentheses when invoking the
- * macro: WARNX_ONLY_ONCE(("mesgstr", arg1, arg2, ...));
- */
-#define WARNX_ONLY_ONCE(x) \
-{ \
- static int firsttime = 1; \
- if (firsttime) { \
- firsttime = 0; \
- warnx x ; \
- } \
-}
-
-static int verify_procfs_fd __P((int, const char *));
-static int parsekinfo __P((const char *, struct kinfo_proc2 *));
-
-static int
-verify_procfs_fd(fd, path)
- int fd;
- const char *path;
-{
- struct statfs procfsstat;
-
- /*
- * If the fstatfs fails, die immediately. Since we already have the
- * FD open, any error is probably one that can't be worked around.
- */
- if (fstatfs(fd, &procfsstat))
- err(1, "fstatfs on %s", path);
-
- /* Now verify that the open file is truly on a procfs filesystem. */
- if (strcmp(procfsstat.f_fstypename, MOUNT_PROCFS)) {
- warnx("%s is on a `%s' filesystem, not `procfs'", path,
- procfsstat.f_fstypename);
- return -1;
- }
- return 0;
-}
-
-static int
-parsekinfo(path, ki)
- const char *path;
- struct kinfo_proc2 *ki;
-{
- char fullpath[MAXPATHLEN];
- int dirfd, fd, nbytes, devmajor, devminor;
- struct timeval usertime, systime, starttime;
- char buff[STATUS_SIZE];
- char flagstr[256];
-
- /*
- * Verify that /proc/<pid> is a procfs file (and that no one has
- * mounted anything on top of it). If we didn't do this, an intruder
- * could hide processes by simply mount_null'ing /tmp on top of the
- * /proc/<pid> directory. (And we can't just print warnings if we
- * fail to open /proc/<pid>/status, because the process may have died
- * since our getdents() call.)
- */
- snprintf(fullpath, MAXPATHLEN, "/proc/%s", path);
- dirfd = open(fullpath, O_RDONLY, 0);
- if (verify_procfs_fd(dirfd, fullpath)) {
- close(dirfd);
- return -1;
- }
-
- /* Open /proc/<pid>/status, and parse it into the kinfo_proc. */
- snprintf(fullpath, MAXPATHLEN, "/proc/%s/status", path);
- fd = open(fullpath, O_RDONLY, 0);
- close(dirfd);
- if (fd == -1) {
- /*
- * Don't print warning, as the process may have died since our
- * scan of the directory entries.
- */
- return -1; /* Process may no longer exist. */
- }
-
- /*
- * Bail out for this process attempt if it isn't on a procfs. Some
- * intruder could have mounted something on top of portions of /proc.
- */
- if (verify_procfs_fd(fd, fullpath)) {
- close(fd);
- return -1;
- }
-
- nbytes = read(fd, buff, STATUS_SIZE - 1);
- close(fd);
- if (nbytes <= 0) {
- /*
- * Don't print warning, as the process may have died since our
- * scan of the directory entries.
- */
- return -1; /* Process may no longer exist. */
- }
-
- /* Make sure the buffer is terminated. */
- buff[nbytes] = '\0';
-
- sscanf(buff, "%s %d %d %d %d %d,%d %s %ld,%ld %ld,%ld %ld,%ld %s %d",
- ki->p_comm, &ki->p_pid, &ki->p_ppid, &ki->p_tpgid, &ki->p_sid,
- &devmajor, &devminor, flagstr, &starttime.tv_sec,
- &starttime.tv_usec, &usertime.tv_sec, &usertime.tv_usec,
- &systime.tv_sec, &systime.tv_usec, ki->p_wmesg, &ki->p_uid);
-
- ki->p_wchan = 1; /* XXX Set it to _something_. */
- ki->p_tdev = makedev(devmajor, devminor);
-
- /* Put both user and sys time into rtime field. */
- ki->p_rtime_sec = usertime.tv_sec + systime.tv_sec;
- ki->p_rtime_usec = usertime.tv_usec + systime.tv_usec;
-
- /* if starttime.[u]sec is != -1, it's in-memory process */
- if (starttime.tv_sec != -1 && starttime.tv_usec != -1) {
- ki->p_flag |= P_INMEM;
- ki->p_uvalid = 1;
- ki->p_ustart_sec = starttime.tv_sec;
- ki->p_ustart_usec = starttime.tv_usec;
- }
-
- /*
- * CPU time isn't shown unless the ki_u.u_valid flag is set.
- * Unfortunately, we don't have access to that here.
- */
-
- /* Set the flag for whether or not there is a controlling terminal. */
- if (strstr(flagstr, "ctty"))
- ki->p_flag |= P_CONTROLT;
-
- /* Set the flag for whether or not this process is session leader */
- if (strstr(flagstr, "sldr"))
- ki->p_eflag |= EPROC_SLEADER;
-
- return 0;
-}
-
-struct kinfo_proc2 *
-getkinfo_procfs(op, arg, cnt)
- int op, arg;
- int *cnt;
-{
- struct stat statbuf;
- int procdirfd, nbytes, knum = 0, maxknum = 0;
- char *direntbuff;
- struct kinfo_proc2 *ki;
- int mib[4];
- size_t len;
- struct statfs procfsstat;
-
- /* First, make sure that /proc is a procfs filesystem. */
- if (statfs("/proc", &procfsstat)) {
- warn("statfs on /proc failed");
- return 0;
- }
- if (strcmp(procfsstat.f_fstypename, MOUNT_PROCFS)) {
- warnx("/proc exists but does not have a procfs mounted on it.");
- return 0;
- }
-
- /*
- * Try to stat /proc/1/status. If we can't do that, then just return
Home |
Main Index |
Thread Index |
Old Index