Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/whodo/whodo.c
          +++ new/usr/src/cmd/whodo/whodo.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
       22 + * Copyright (c) 2013 Gary Mills
       23 + *
  22   24   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   25   * Use is subject to license terms.
  24   26   */
  25   27  
  26   28  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  27   29  /*        All Rights Reserved   */
  28   30  
  29   31  /*
  30   32   * University Copyright- Copyright (c) 1982, 1986, 1988
  31   33   * The Regents of the University of California
↓ open down ↓ 29 lines elided ↑ open up ↑
  61   63  #include <sys/mkdev.h>
  62   64  #include <dirent.h>
  63   65  #include <procfs.h>             /* /proc header file */
  64   66  #include <sys/wait.h>
  65   67  #include <locale.h>
  66   68  #include <unistd.h>
  67   69  #include <limits.h>
  68   70  #include <priv_utils.h>
  69   71  
  70   72  /*
  71      - * utmpx defines wider fields for user and line.  For compatibility of output,
  72      - * we are limiting these to the old maximums in utmp. Define UTMPX_NAMELEN
  73      - * to use the full lengths.
       73 + * Use the full lengths from utmpx for user and line.
  74   74   */
  75      -#ifndef UTMPX_NAMELEN
  76      -/* XXX - utmp - fix name length */
  77      -#define NMAX            (_POSIX_LOGIN_NAME_MAX - 1)
  78      -#define LMAX            12
  79      -#else /* UTMPX_NAMELEN */
  80      -static struct utmpx dummy;
  81      -#define NMAX    (sizeof (dummy.ut_user))
  82      -#define LMAX    (sizeof (dummy.ut_line))
  83      -#endif /* UTMPX_NAMELEN */
       75 +#define NMAX    (sizeof (((struct utmpx *)0)->ut_user))
       76 +#define LMAX    (sizeof (((struct utmpx *)0)->ut_line))
  84   77  
       78 +/* Print minimum field widths. */
       79 +#define LOGIN_WIDTH     8
       80 +#define LINE_WIDTH      12
       81 +
  85   82  #define DIV60(t)        ((t+30)/60)    /* x/60 rounded */
  86   83  
  87   84  #ifdef ERR
  88   85  #undef ERR
  89   86  #endif
  90   87  #define ERR             (-1)
  91   88  
  92   89  #define DEVNAMELEN      14
  93   90  #define HSIZE           256             /* size of process hash table */
  94   91  #define PROCDIR         "/proc"
↓ open down ↓ 371 lines elided ↑ open up ↑
 466  463           */
 467  464          for (ut = utmpbegin; ut < utmpend; ut++) {
 468  465                  time_t tim;
 469  466  
 470  467                  if (ut->ut_type != USER_PROCESS)
 471  468                          continue;
 472  469                  if (sel_user && strncmp(ut->ut_name, sel_user, NMAX) != 0)
 473  470                          continue;       /* we're looking for somebody else */
 474  471                  if (lflag) {    /* -l flag format (w command) */
 475  472                          /* print login name of the user */
 476      -                        (void) printf("%-*.*s ", NMAX, NMAX, ut->ut_name);
      473 +                        (void) printf("%-*.*s ", LOGIN_WIDTH, (int)NMAX,
      474 +                            ut->ut_name);
 477  475  
 478  476                          /* print tty user is on */
 479      -                        (void) printf("%-*.*s", LMAX, LMAX, ut->ut_line);
      477 +                        (void) printf("%-*.*s", LINE_WIDTH, (int)LMAX,
      478 +                            ut->ut_line);
 480  479  
 481  480                          /* print when the user logged in */
 482  481                          tim = ut->ut_xtime;
 483  482                          (void) prtat(&tim);
 484  483  
 485  484                          /* print idle time */
 486  485                          idle = findidle(ut->ut_line);
 487  486                          if (idle >= 36 * 60)
 488  487                                  (void) printf(dcgettext(NULL, "%2ddays ",
 489  488                                      LC_TIME), (idle + 12 * 60) / (24 * 60));
 490  489                          else
 491  490                                  prttime(idle, " ");
 492  491                          showtotals(findhash((pid_t)ut->ut_pid));
 493  492                  } else {        /* standard whodo format */
 494  493                          tim = ut->ut_xtime;
 495  494                          tm = localtime(&tim);
 496  495                          (void) printf("\n%-*.*s %-*.*s %2.1d:%2.2d\n",
 497      -                            LMAX, LMAX, ut->ut_line,
 498      -                            NMAX, NMAX, ut->ut_name, tm->tm_hour, tm->tm_min);
      496 +                            LINE_WIDTH, (int)LMAX, ut->ut_line,
      497 +                            LOGIN_WIDTH, (int)NMAX, ut->ut_name, tm->tm_hour,
      498 +                            tm->tm_min);
 499  499                          showproc(findhash((pid_t)ut->ut_pid));
 500  500                  }
 501  501          }
 502  502  
 503  503          return (0);
 504  504  }
 505  505  
 506  506  /*
 507  507   * Used for standard whodo format.
 508  508   * This is the recursive routine descending the process
↓ open down ↓ 4 lines elided ↑ open up ↑
 513  513  static void
 514  514  showproc(struct uproc *up)
 515  515  {
 516  516          struct  uproc   *zp;
 517  517  
 518  518          if (up->p_state == VISITED) /* we already been here */
 519  519                  return;
 520  520          /* print the data for this process */
 521  521          if (up->p_state == ZOMBIE)
 522  522                  (void) printf("    %-*.*s %5d %4.1ld:%2.2ld %s\n",
 523      -                    LMAX, LMAX, "  ?", (int)up->p_upid, 0L, 0L, "<defunct>");
      523 +                    LINE_WIDTH, (int)LMAX, "  ?", (int)up->p_upid, 0L, 0L,
      524 +                    "<defunct>");
 524  525          else if (up->p_state != NONE) {
 525  526                  (void) printf("    %-*.*s %5d %4.1ld:%2.2ld %s\n",
 526      -                    LMAX, LMAX, getty(up->p_ttyd), (int)up->p_upid,
      527 +                    LINE_WIDTH, (int)LMAX, getty(up->p_ttyd), (int)up->p_upid,
 527  528                      up->p_time / 60L, up->p_time % 60L,
 528  529                      up->p_comm);
 529  530          }
 530  531          up->p_state = VISITED;
 531  532  
 532  533          /* descend for its children */
 533  534          if (up->p_child) {
 534  535                  showproc(up->p_child);
 535  536                  for (zp = up->p_child->p_sibling; zp; zp = zp->p_sibling) {
 536  537                          showproc(zp);
↓ open down ↓ 307 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX