Source-Changes-HG archive

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

[src/trunk]: src/bin/ps Fix handling of "ps U<user>" where <user> ended it 't...



details:   https://anonhg.NetBSD.org/src/rev/d8c7d00a6316
branches:  trunk
changeset: 487483:d8c7d00a6316
user:      simonb <simonb%NetBSD.org@localhost>
date:      Thu Jun 08 13:30:39 2000 +0000

description:
Fix handling of "ps U<user>" where <user> ended it 't' - now if the
first argument doesn't start with a '-' and ends in 't', the 't' only
gets converted to a 'T' (for listing processes on the current tty)
if it doesn't contain any other command line option characters that
take an argument.  Problem noticed by ITOH Yasufumi on tech-userlevel.

If the 'start' format was the last column, the width wouldn't be set
and started() output a zero length string instead of a string the right
length - fix header width calculations so the the last column is handled
the same all others.  This only showed up for 'start' because started()
knew that the column header is the same width and the field itself...

Update copyrights.

diffstat:

 bin/ps/nlist.c |  42 +++++++++++++++++++++++++++++++++++--
 bin/ps/print.c |  60 ++++++++++++++++++++++++++++++++++++++++++++-----------
 bin/ps/ps.c    |  63 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 3 files changed, 140 insertions(+), 25 deletions(-)

diffs (272 lines):

diff -r e1ab67297a81 -r d8c7d00a6316 bin/ps/nlist.c
--- a/bin/ps/nlist.c    Thu Jun 08 13:16:55 2000 +0000
+++ b/bin/ps/nlist.c    Thu Jun 08 13:30:39 2000 +0000
@@ -1,6 +1,42 @@
-/*     $NetBSD: nlist.c,v 1.16 2000/05/26 03:04:28 simonb Exp $        */
+/*     $NetBSD: nlist.c,v 1.17 2000/06/08 13:30:39 simonb Exp $        */
 
-/*-
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Simon Burge.
+ *
+ * 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.
+ */
+
+/*
  * Copyright (c) 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
@@ -38,7 +74,7 @@
 #if 0
 static char sccsid[] = "@(#)nlist.c    8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: nlist.c,v 1.16 2000/05/26 03:04:28 simonb Exp $");
+__RCSID("$NetBSD: nlist.c,v 1.17 2000/06/08 13:30:39 simonb Exp $");
 #endif
 #endif /* not lint */
 
diff -r e1ab67297a81 -r d8c7d00a6316 bin/ps/print.c
--- a/bin/ps/print.c    Thu Jun 08 13:16:55 2000 +0000
+++ b/bin/ps/print.c    Thu Jun 08 13:30:39 2000 +0000
@@ -1,6 +1,42 @@
-/*     $NetBSD: print.c,v 1.54 2000/06/08 00:51:10 simonb Exp $        */
+/*     $NetBSD: print.c,v 1.55 2000/06/08 13:30:40 simonb Exp $        */
 
-/*-
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Simon Burge.
+ *
+ * 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.
+ */
+
+/*
  * Copyright (c) 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
@@ -38,7 +74,7 @@
 #if 0
 static char sccsid[] = "@(#)print.c    8.6 (Berkeley) 4/16/94";
 #else
-__RCSID("$NetBSD: print.c,v 1.54 2000/06/08 00:51:10 simonb Exp $");
+__RCSID("$NetBSD: print.c,v 1.55 2000/06/08 13:30:40 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -97,7 +133,7 @@
 
        for (vent = vhead; vent; vent = vent->next) {
                v = vent->var;
-               if (firsttime && vent->next != NULL) {
+               if (firsttime) {
                        len = strlen(v->header);
                        if (len > v->width)
                                v->width = len;
@@ -115,8 +151,10 @@
                        (void)putchar(' ');
        }
        (void)putchar('\n');
-       if (firsttime)
+       if (firsttime) {
                firsttime = 0;
+               totwidth--;     /* take off last space */
+       }
 }
 
 static int
@@ -142,8 +180,8 @@
 
        if (argv[1] == 0 &&
            !strncmp(name, title, namelen) &&
-           title[namelen+0] == ':' &&
-           title[namelen+1] == ' ')
+           title[namelen + 0] == ':' &&
+           title[namelen + 1] == ' ')
                return (0);
 
        return (1);
@@ -228,15 +266,13 @@
        int left;
        char **argv, **p, *name;
 
-       v = ve->var;
-       if (mode == WIDTHMODE) {
-               v->width = 0;
+       if (mode == WIDTHMODE)
                return;
-       }
+
        v = ve->var;
        if (ve->next != NULL || termwidth != UNLIMITED) {
                if (ve->next == NULL) {
-                       left = termwidth - totwidth;
+                       left = termwidth - (totwidth - v->width);
                        if (left < 1) /* already wrapped, just use std width */
                                left = v->width;
                } else
diff -r e1ab67297a81 -r d8c7d00a6316 bin/ps/ps.c
--- a/bin/ps/ps.c       Thu Jun 08 13:16:55 2000 +0000
+++ b/bin/ps/ps.c       Thu Jun 08 13:30:39 2000 +0000
@@ -1,6 +1,42 @@
-/*     $NetBSD: ps.c,v 1.39 2000/06/07 04:58:01 simonb Exp $   */
+/*     $NetBSD: ps.c,v 1.40 2000/06/08 13:30:40 simonb Exp $   */
 
-/*-
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Simon Burge.
+ *
+ * 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.
+ */
+
+/*
  * Copyright (c) 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
@@ -43,7 +79,7 @@
 #if 0
 static char sccsid[] = "@(#)ps.c       8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: ps.c,v 1.39 2000/06/07 04:58:01 simonb Exp $");
+__RCSID("$NetBSD: ps.c,v 1.40 2000/06/08 13:30:40 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -72,6 +108,13 @@
 
 #include "ps.h"
 
+/*
+ * ARGOPTS must contain all option characters that take arguments
+ * (except for 't'!) - it is used in kludge_oldps_options()
+ */
+#define        GETOPTSTR       "acCeghjKLlM:mN:O:o:p:rSTt:U:uvW:wx"
+#define        ARGOPTS         "MNOopUW"
+
 struct kinfo_proc2 *kinfo;
 struct varent *vhead, *vtail;
 
@@ -133,8 +176,7 @@
        flag = myuid = getuid();
        memf = nlistf = swapf = NULL;
        mode = PRINTMODE;
-       while ((ch = getopt(argc, argv,
-           "acCeghjKLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1)
+       while ((ch = getopt(argc, argv, GETOPTSTR)) != -1)
                switch((char)ch) {
                case 'a':
                        what = KERN_PROC_ALL;
@@ -478,11 +520,12 @@
         */
        cp = s + len - 1;
        /*
-        * if last letter is a 't' flag with no argument (in the context
-        * of the oldps options -- option string NOT starting with a '-' --
-        * then convert to 'T' (meaning *this* terminal, i.e. ttyname(0)).
+        * if the last letter is a 't' flag and there are no other option
+        * characters that take arguments (eg U, p, o) in the option
+        * string and the option string doesn't start with a '-' then
+        * convert to 'T' (meaning *this* terminal, i.e. ttyname(0)).
         */
-       if (*cp == 't' && *s != '-')
+       if (*cp == 't' && *s != '-' && strpbrk(s, ARGOPTS) == NULL)
                *cp = 'T';
        else {
                /*
@@ -504,7 +547,7 @@
             (cp - 1 == s || cp[-2] != 't'))))
                *ns++ = 'p';
        /* and append the number */
-       (void)strcpy(ns, cp);           /* XXX strcpy is safe */
+       (void)strcpy(ns, cp);           /* XXX strcpy is safe here */
 
        return (newopts);
 }



Home | Main Index | Thread Index | Old Index