Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/ps command(): don't start using procfs_getargv() instead...



details:   https://anonhg.NetBSD.org/src/rev/6b84c02a402d
branches:  trunk
changeset: 477215:6b84c02a402d
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Fri Oct 15 20:39:52 1999 +0000

description:
command(): don't start using procfs_getargv() instead of kvm_getargv()
just because the latter returned a NULL - that may normally happen,
when the process is, for example, a kernel thread

procfs_getargv(): if the name is brackened in '(' and ')', just
        return NULL immediately - the code in command() will DTRT
        and the output will be same for procfs- and kvm- based lookup
        in all cases

diffstat:

 bin/ps/print.c      |  15 ++++++---------
 bin/ps/procfs_ops.c |   9 ++++-----
 bin/ps/ps.c         |   7 ++++---
 3 files changed, 14 insertions(+), 17 deletions(-)

diffs (120 lines):

diff -r 6f39f0cbf5ce -r 6b84c02a402d bin/ps/print.c
--- a/bin/ps/print.c    Fri Oct 15 20:01:33 1999 +0000
+++ b/bin/ps/print.c    Fri Oct 15 20:39:52 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print.c,v 1.45 1999/10/15 19:31:24 jdolecek Exp $      */
+/*     $NetBSD: print.c,v 1.46 1999/10/15 20:39:52 jdolecek Exp $      */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)print.c    8.6 (Berkeley) 4/16/94";
 #else
-__RCSID("$NetBSD: print.c,v 1.45 1999/10/15 19:31:24 jdolecek Exp $");
+__RCSID("$NetBSD: print.c,v 1.46 1999/10/15 20:39:52 jdolecek Exp $");
 #endif
 #endif /* not lint */
 
@@ -68,7 +68,7 @@
 #include "ps.h"
 
 extern kvm_t *kd;
-extern int needenv, needcomm, commandonly, dontuseprocfs;
+extern int needenv, needcomm, commandonly, dontuseprocfs, use_procfs;
 
 static char *cmdpart __P((char *));
 static void  printval __P((char *, VAR *));
@@ -144,7 +144,6 @@
 {
        VAR *v;
        int left;
-       static int use_procfs=0;
        char **argv, **p, *name;
 
        v = ve->var;
@@ -171,12 +170,10 @@
                name = KI_PROC(ki)->p_comm;
                if (!commandonly) {
                        argv = NULL;
-                       if (kd && !use_procfs)
+                       if (!use_procfs)
                                argv = kvm_getargv(kd, ki->ki_p, termwidth);
-                       if (argv == NULL && !dontuseprocfs) {
+                       else
                                argv = procfs_getargv(ki->ki_p, termwidth);
-                               use_procfs = 1;
-                       }
                        if ((p = argv) != NULL) {
                                while (*p) {
                                        fmt_puts(*p, &left);
@@ -189,7 +186,7 @@
                                fmt_puts(name, &left);
                                fmt_putc(')', &left);
                        }
-                       if (use_procfs) {
+                       if (use_procfs && argv) {
                                free(argv[0]);
                                free(argv);
                        }
diff -r 6f39f0cbf5ce -r 6b84c02a402d bin/ps/procfs_ops.c
--- a/bin/ps/procfs_ops.c       Fri Oct 15 20:01:33 1999 +0000
+++ b/bin/ps/procfs_ops.c       Fri Oct 15 20:39:52 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_ops.c,v 1.6 1999/10/15 19:31:25 jdolecek Exp $  */
+/*     $NetBSD: procfs_ops.c,v 1.7 1999/10/15 20:39:52 jdolecek Exp $  */
 
 /*
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -399,13 +399,12 @@
        buf[len] = '\0'; /* end the string */
 
        /* if the name is the same as the p_comm, just enclosed
-        * in parentheses, remove the parentheses */
+        * in parentheses, just return NULL - the code in command()
+        * will DTRT */
        if (num == 1 && name[0] == '(' && name[len-1] == ')'
                && strncmp(name+1, kp->kp_proc.p_comm, len-2) == 0)
        {
-               len -= 2;
-               strncpy(name, name+1, len);
-               name[len] = '\0';
+               return (NULL);
        }
        
        argv = (char **) malloc(3*sizeof(char *));
diff -r 6f39f0cbf5ce -r 6b84c02a402d bin/ps/ps.c
--- a/bin/ps/ps.c       Fri Oct 15 20:01:33 1999 +0000
+++ b/bin/ps/ps.c       Fri Oct 15 20:39:52 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ps.c,v 1.30 1999/10/15 20:01:33 jdolecek Exp $ */
+/*     $NetBSD: ps.c,v 1.31 1999/10/15 20:39:52 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)ps.c       8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: ps.c,v 1.30 1999/10/15 20:01:33 jdolecek Exp $");
+__RCSID("$NetBSD: ps.c,v 1.31 1999/10/15 20:39:52 jdolecek Exp $");
 #endif
 #endif /* not lint */
 
@@ -86,7 +86,7 @@
 int    termwidth;              /* width of screen (0 == infinity) */
 int    totwidth;               /* calculated width of requested variables */
 
-int    needuser, needcomm, needenv, commandonly;
+int    needuser, needcomm, needenv, commandonly, use_procfs;
 
 enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT;
 
@@ -361,6 +361,7 @@
                fprintf(stderr, "%s%s",
                    "Warning:  /proc does not provide ",
                    "valid data for all fields.\n");
+               use_procfs = 1;
        }
 
        /*



Home | Main Index | Thread Index | Old Index