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/w/w.c
          +++ new/usr/src/cmd/w/w.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 ↓ 30 lines elided ↑ open up ↑
  62   64  #include <sys/stat.h>
  63   65  #include <dirent.h>
  64   66  #include <procfs.h>             /* /proc header file */
  65   67  #include <locale.h>
  66   68  #include <unistd.h>
  67   69  #include <sys/loadavg.h>
  68   70  #include <limits.h>
  69   71  #include <priv_utils.h>
  70   72  
  71   73  /*
  72      - * utmpx defines wider fields for user and line.  For compatibility of output,
  73      - * we are limiting these to the old maximums in utmp. Define UTMPX_NAMELEN
  74      - * to use the full lengths.
       74 + * Use the full lengths from utmpx for user and line.
  75   75   */
  76      -#ifndef UTMPX_NAMELEN
  77      -/* XXX - utmp - fix name length */
  78      -#define NMAX            (_POSIX_LOGIN_NAME_MAX - 1)
  79      -#define LMAX            12
  80      -#else   /* UTMPX_NAMELEN */
  81   76  static struct utmpx dummy;
  82   77  #define NMAX            (sizeof (dummy.ut_user))
  83   78  #define LMAX            (sizeof (dummy.ut_line))
  84      -#endif /* UTMPX_NAMELEN */
  85   79  
       80 +/* Print minimum field widths. */
       81 +#define LOGIN_WIDTH     8
       82 +#define LINE_WIDTH      12
       83 +
  86   84  #define DIV60(t)        ((t+30)/60)     /* x/60 rounded */
  87   85  
  88   86  #ifdef ERR
  89   87  #undef ERR
  90   88  #endif
  91   89  #define ERR             (-1)
  92   90  
  93   91  #define HSIZE           256             /* size of process hash table   */
  94   92  #define PROCDIR         "/proc"
  95   93  #define INITPROCESS     (pid_t)1        /* init process pid */
↓ open down ↓ 380 lines elided ↑ open up ↑
 476  474           * loop through utmpx file, printing process info
 477  475           * about each logged in user
 478  476           */
 479  477          for (ut = utmpbegin; ut < utmpend; ut++) {
 480  478                  if (ut->ut_type != USER_PROCESS)
 481  479                          continue;
 482  480                  if (sel_user && strncmp(ut->ut_name, sel_user, NMAX) != 0)
 483  481                          continue;       /* we're looking for somebody else */
 484  482  
 485  483                  /* print login name of the user */
 486      -                PRINTF(("%-*.*s ", NMAX, NMAX, ut->ut_name));
      484 +                PRINTF(("%-*.*s ", LOGIN_WIDTH, NMAX, ut->ut_name));
 487  485  
 488  486                  /* print tty user is on */
 489  487                  if (lflag) {
 490      -                        PRINTF(("%-*.*s", LMAX, LMAX, ut->ut_line));
      488 +                        PRINTF(("%-*.*s", LINE_WIDTH, LMAX, ut->ut_line));
 491  489                  } else {
 492  490                          if (ut->ut_line[0] == 'p' && ut->ut_line[1] == 't' &&
 493  491                              ut->ut_line[2] == 's' && ut->ut_line[3] == '/') {
 494  492                                  PRINTF(("%-*.3s", LMAX, &ut->ut_line[4]));
 495  493                          } else {
 496      -                                PRINTF(("%-*.*s", LMAX, LMAX, ut->ut_line));
      494 +                                PRINTF(("%-*.*s", LINE_WIDTH, LMAX,
      495 +                                    ut->ut_line));
 497  496                          }
 498  497                  }
 499  498  
 500  499                  /* print when the user logged in */
 501  500                  if (lflag) {
 502  501                          time_t tim = ut->ut_xtime;
 503  502                          prtat(&tim);
 504  503                  }
 505  504  
 506  505                  /* print idle time */
↓ open down ↓ 247 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX