Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/prstat/prstat.c
          +++ new/usr/src/cmd/prstat/prstat.c
↓ open down ↓ 18 lines elided ↑ open up ↑
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2013 Gary Mills
  24   24   *
  25   25   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  26   26   * Use is subject to license terms.
  27   27   *
  28   28   * Portions Copyright 2009 Chad Mynhier
       29 + * Copyright 2018 Joyent, Inc.  All rights reserved.
  29   30   */
  30   31  
  31   32  #include <sys/types.h>
  32   33  #include <sys/resource.h>
  33   34  #include <sys/loadavg.h>
  34   35  #include <sys/time.h>
  35   36  #include <sys/pset.h>
  36   37  #include <sys/vm_usage.h>
  37   38  #include <zone.h>
  38   39  #include <libzonecfg.h>
↓ open down ↓ 40 lines elided ↑ open up ↑
  79   80  
  80   81  #define LOGIN_WIDTH     8
  81   82  #define ZONE_WIDTH      28
  82   83  #define PROJECT_WIDTH   28
  83   84  
  84   85  #define PSINFO_HEADER_PROC \
  85   86  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP       "
  86   87  #define PSINFO_HEADER_PROC_LGRP \
  87   88  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/NLWP  "
  88   89  #define PSINFO_HEADER_LWP \
  89      -"   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/LWPID      "
       90 +"   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/LWP        "
  90   91  #define PSINFO_HEADER_LWP_LGRP \
  91      -"   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/LWPID "
       92 +"   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/LWP   "
  92   93  #define USAGE_HEADER_PROC \
  93   94  "   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/NLWP  "
  94   95  #define USAGE_HEADER_LWP \
  95      -"   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/LWPID "
       96 +"   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/LWP   "
  96   97  #define USER_HEADER_PROC \
  97   98  " NPROC USERNAME  SWAP   RSS MEMORY      TIME  CPU                             "
  98   99  #define USER_HEADER_LWP \
  99  100  "  NLWP USERNAME  SWAP   RSS MEMORY      TIME  CPU                             "
 100  101  #define TASK_HEADER_PROC \
 101  102  "TASKID    NPROC  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 102  103  #define TASK_HEADER_LWP \
 103  104  "TASKID     NLWP  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 104  105  #define PROJECT_HEADER_PROC \
 105  106  "PROJID    NPROC  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 106  107  #define PROJECT_HEADER_LWP \
 107  108  "PROJID     NLWP  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 108  109  #define ZONE_HEADER_PROC \
 109  110  "ZONEID    NPROC  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 110  111  #define ZONE_HEADER_LWP \
 111  112  "ZONEID     NLWP  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 112  113  #define PSINFO_LINE \
 113      -"%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %-.16s/%d"
      114 +"%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %s"
 114  115  #define PSINFO_LINE_LGRP \
 115      -"%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %4d %-.16s/%d"
      116 +"%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %4d %s"
 116  117  #define USAGE_LINE \
 117  118  "%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\
 118      -"%3.3s %3.3s %-.12s/%d"
      119 +"%3.3s %3.3s %s"
 119  120  #define USER_LINE \
 120  121  "%6d %-8s %5.5s %5.5s   %3.3s%% %9s %3.3s%%"
 121  122  #define TASK_LINE \
 122  123  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 123  124  #define PROJECT_LINE \
 124  125  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 125  126  #define ZONE_LINE \
 126  127  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 127  128  
 128  129  #define TOTAL_LINE \
↓ open down ↓ 13 lines elided ↑ open up ↑
 142  143  static uint_t   print_movecur = FALSE;          /* print movecur or not */
 143  144  static int      is_curses_on = FALSE;           /* current curses state */
 144  145  
 145  146  static table_t  pid_tbl = {0, 0, NULL};         /* selected processes */
 146  147  static table_t  cpu_tbl = {0, 0, NULL};         /* selected processors */
 147  148  static table_t  set_tbl = {0, 0, NULL};         /* selected processor sets */
 148  149  static table_t  prj_tbl = {0, 0, NULL};         /* selected projects */
 149  150  static table_t  tsk_tbl = {0, 0, NULL};         /* selected tasks */
 150  151  static table_t  lgr_tbl = {0, 0, NULL};         /* selected lgroups */
 151  152  static zonetbl_t zone_tbl = {0, 0, NULL};       /* selected zones */
 152      -static uidtbl_t euid_tbl = {0, 0, NULL};        /* selected effective users */
 153      -static uidtbl_t ruid_tbl = {0, 0, NULL};        /* selected real users */
      153 +static uidtbl_t euid_tbl = {0, 0, NULL};        /* selected effective users */
      154 +static uidtbl_t ruid_tbl = {0, 0, NULL};        /* selected real users */
 154  155  
 155  156  static uint_t   total_procs;                    /* total number of procs */
 156  157  static uint_t   total_lwps;                     /* total number of lwps */
 157  158  static float    total_cpu;                      /* total cpu usage */
 158  159  static float    total_mem;                      /* total memory usage */
 159  160  
 160  161  static list_t   lwps;                           /* list of lwps/processes */
 161  162  static list_t   users;                          /* list of users */
 162  163  static list_t   tasks;                          /* list of tasks */
 163  164  static list_t   projects;                       /* list of projects */
↓ open down ↓ 1 lines elided ↑ open up ↑
 165  166  static list_t   lgroups;                        /* list of lgroups */
 166  167  
 167  168  static volatile uint_t sigwinch = 0;
 168  169  static volatile uint_t sigtstp = 0;
 169  170  static volatile uint_t sigterm = 0;
 170  171  
 171  172  static long pagesize;
 172  173  
 173  174  /* default settings */
 174  175  
 175      -static optdesc_t opts = {
      176 +optdesc_t opts = {
 176  177          5,                      /* interval between updates, seconds */
 177  178          15,                     /* number of lines in top part */
 178  179          5,                      /* number of lines in bottom part */
 179  180          -1,                     /* number of iterations; infinitely */
 180  181          OPT_PSINFO | OPT_FULLSCREEN | OPT_USEHOME | OPT_TERMCAP,
 181  182          -1                      /* sort in decreasing order */
 182  183  };
 183  184  
 184  185  /*
 185  186   * Print timestamp as decimal reprentation of time_t value (-d u was specified)
↓ open down ↓ 168 lines elided ↑ open up ↑
 354  355  list_print(list_t *list)
 355  356  {
 356  357          lwp_info_t *lwp;
 357  358          id_info_t *id;
 358  359          char usr[4], sys[4], trp[4], tfl[4];
 359  360          char dfl[4], lck[4], slp[4], lat[4];
 360  361          char vcx[4], icx[4], scl[4], sig[4];
 361  362          char psize[6], prssize[6], pmem[6], pcpu[6], ptime[12];
 362  363          char pstate[7], pnice[4], ppri[4];
 363  364          char pname[LOGNAME_MAX+1];
      365 +        char name[PRFNSZ + THREAD_NAME_MAX + 2];
 364  366          char projname[PROJNAME_MAX+1];
 365  367          char zonename[ZONENAME_MAX+1];
 366  368          float cpu, mem;
 367  369          double loadavg[3] = {0, 0, 0};
 368      -        int i, lwpid;
      370 +        int i, n;
 369  371  
 370  372          if (list->l_size == 0)
 371  373                  return;
 372  374  
 373  375          if (foreach_element(&set_tbl, &loadavg, psetloadavg) == 0) {
 374  376                  /*
 375  377                   * If processor sets aren't specified, we display system-wide
 376  378                   * load averages.
 377  379                   */
 378  380                  (void) getloadavg(loadavg, 3);
 379  381          }
 380  382  
 381  383          if (((opts.o_outpmode & OPT_UDATE) || (opts.o_outpmode & OPT_DDATE)) &&
 382  384              ((list->l_type == LT_LWPS) || !(opts.o_outpmode & OPT_SPLIT)))
 383  385                  print_timestamp();
 384  386          if (opts.o_outpmode & OPT_TTY)
 385  387                  (void) putchar('\r');
 386  388          (void) putp(t_ulon);
 387  389  
      390 +        n = opts.o_cols;
 388  391          switch (list->l_type) {
 389  392          case LT_PROJECTS:
 390  393                  if (opts.o_outpmode & OPT_LWPS)
 391      -                        (void) printf(PROJECT_HEADER_LWP);
      394 +                        n = printf(PROJECT_HEADER_LWP);
 392  395                  else
 393      -                        (void) printf(PROJECT_HEADER_PROC);
      396 +                        n = printf(PROJECT_HEADER_PROC);
 394  397                  break;
 395  398          case LT_TASKS:
 396  399                  if (opts.o_outpmode & OPT_LWPS)
 397      -                        (void) printf(TASK_HEADER_LWP);
      400 +                        n = printf(TASK_HEADER_LWP);
 398  401                  else
 399      -                        (void) printf(TASK_HEADER_PROC);
      402 +                        n = printf(TASK_HEADER_PROC);
 400  403                  break;
 401  404          case LT_ZONES:
 402  405                  if (opts.o_outpmode & OPT_LWPS)
 403      -                        (void) printf(ZONE_HEADER_LWP);
      406 +                        n = printf(ZONE_HEADER_LWP);
 404  407                  else
 405      -                        (void) printf(ZONE_HEADER_PROC);
      408 +                        n = printf(ZONE_HEADER_PROC);
 406  409                  break;
 407  410          case LT_USERS:
 408  411                  if (opts.o_outpmode & OPT_LWPS)
 409      -                        (void) printf(USER_HEADER_LWP);
      412 +                        n = printf(USER_HEADER_LWP);
 410  413                  else
 411      -                        (void) printf(USER_HEADER_PROC);
      414 +                        n = printf(USER_HEADER_PROC);
 412  415                  break;
 413  416          case LT_LWPS:
 414  417                  if (opts.o_outpmode & OPT_LWPS) {
 415  418                          if (opts.o_outpmode & OPT_PSINFO) {
 416  419                                  if (opts.o_outpmode & OPT_LGRP)
 417      -                                        (void) printf(PSINFO_HEADER_LWP_LGRP);
      420 +                                        n = printf(PSINFO_HEADER_LWP_LGRP);
 418  421                                  else
 419      -                                        (void) printf(PSINFO_HEADER_LWP);
      422 +                                        n = printf(PSINFO_HEADER_LWP);
 420  423                          }
 421  424                          if (opts.o_outpmode & OPT_MSACCT)
 422      -                                (void) printf(USAGE_HEADER_LWP);
      425 +                                n = printf(USAGE_HEADER_LWP);
 423  426                  } else {
 424  427                          if (opts.o_outpmode & OPT_PSINFO) {
 425  428                                  if (opts.o_outpmode & OPT_LGRP)
 426      -                                        (void) printf(PSINFO_HEADER_PROC_LGRP);
      429 +                                        n = printf(PSINFO_HEADER_PROC_LGRP);
 427  430                                  else
 428      -                                        (void) printf(PSINFO_HEADER_PROC);
      431 +                                        n = printf(PSINFO_HEADER_PROC);
 429  432                          }
 430  433                          if (opts.o_outpmode & OPT_MSACCT)
 431      -                                (void) printf(USAGE_HEADER_PROC);
      434 +                                n = printf(USAGE_HEADER_PROC);
 432  435                  }
 433  436                  break;
 434  437          }
 435  438  
      439 +        /* Pad out the header line so the underline spans the whole width */
      440 +        if ((opts.o_outpmode & OPT_TERMCAP) && n < opts.o_cols)
      441 +                (void) printf("%*s", (int)(opts.o_cols - n), "");
      442 +
 436  443          (void) putp(t_uloff);
 437  444          (void) putp(t_eol);
 438  445          (void) putchar('\n');
 439  446  
 440  447          for (i = 0; i < list->l_used; i++) {
 441  448                  switch (list->l_type) {
 442  449                  case LT_PROJECTS:
 443  450                  case LT_TASKS:
 444  451                  case LT_USERS:
 445  452                  case LT_ZONES:
↓ open down ↓ 46 lines elided ↑ open up ↑
 492  499                                      id->id_nproc, psize, prssize, pmem, ptime,
 493  500                                      pcpu, zonename);
 494  501                          else
 495  502                                  (void) printf(USER_LINE, id->id_nproc, pname,
 496  503                                      psize, prssize, pmem, ptime, pcpu);
 497  504                          (void) putp(t_eol);
 498  505                          (void) putchar('\n');
 499  506                          break;
 500  507                  case LT_LWPS:
 501  508                          lwp = list->l_ptrs[i];
 502      -                        if (opts.o_outpmode & OPT_LWPS)
 503      -                                lwpid = lwp->li_info.pr_lwp.pr_lwpid;
 504      -                        else
 505      -                                lwpid = lwp->li_info.pr_nlwp +
 506      -                                    lwp->li_info.pr_nzomb;
      509 +
      510 +                        format_name(lwp, name, sizeof (name));
      511 +
 507  512                          pwd_getname(lwp->li_info.pr_uid, pname, sizeof (pname),
 508  513                              opts.o_outpmode & OPT_NORESOLVE,
 509  514                              opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
 510  515                              LOGIN_WIDTH);
      516 +
 511  517                          if (opts.o_outpmode & OPT_PSINFO) {
 512  518                                  Format_size(psize, lwp->li_info.pr_size, 6);
 513  519                                  Format_size(prssize, lwp->li_info.pr_rssize, 6);
 514  520                                  Format_state(pstate,
 515  521                                      lwp->li_info.pr_lwp.pr_sname,
 516  522                                      lwp->li_info.pr_lwp.pr_onpro, 7);
 517  523                                  if (strcmp(lwp->li_info.pr_lwp.pr_clname,
 518  524                                      "RT") == 0 ||
 519  525                                      strcmp(lwp->li_info.pr_lwp.pr_clname,
 520  526                                      "SYS") == 0 ||
↓ open down ↓ 8 lines elided ↑ open up ↑
 529  535                                      FRC2PCT(lwp->li_info.pr_lwp.pr_pctcpu), 4);
 530  536                                  if (opts.o_outpmode & OPT_LWPS)
 531  537                                          Format_time(ptime,
 532  538                                              lwp->li_info.pr_lwp.pr_time.tv_sec,
 533  539                                              10);
 534  540                                  else
 535  541                                          Format_time(ptime,
 536  542                                              lwp->li_info.pr_time.tv_sec, 10);
 537  543                                  if (opts.o_outpmode & OPT_TTY)
 538  544                                          (void) putchar('\r');
 539      -                                stripfname(lwp->li_info.pr_fname);
 540  545                                  if (opts.o_outpmode & OPT_LGRP) {
 541  546                                          (void) printf(PSINFO_LINE_LGRP,
 542  547                                              (int)lwp->li_info.pr_pid, pname,
 543  548                                              psize, prssize, pstate,
 544  549                                              ppri, pnice, ptime, pcpu,
 545      -                                            (int)lwp->li_info.pr_lwp.pr_lgrp,
 546      -                                            lwp->li_info.pr_fname, lwpid);
      550 +                                            lwp->li_info.pr_lwp.pr_lgrp, name);
 547  551                                  } else {
 548  552                                          (void) printf(PSINFO_LINE,
 549  553                                              (int)lwp->li_info.pr_pid, pname,
 550      -                                            psize, prssize,
 551      -                                            pstate, ppri, pnice,
 552      -                                            ptime, pcpu,
 553      -                                            lwp->li_info.pr_fname, lwpid);
      554 +                                            psize, prssize, pstate, ppri, pnice,
      555 +                                            ptime, pcpu, name);
 554  556                                  }
 555  557                                  (void) putp(t_eol);
 556  558                                  (void) putchar('\n');
 557  559                          }
 558  560                          if (opts.o_outpmode & OPT_MSACCT) {
 559  561                                  Format_pct(usr, lwp->li_usr, 4);
 560  562                                  Format_pct(sys, lwp->li_sys, 4);
 561  563                                  Format_pct(slp, lwp->li_slp, 4);
 562  564                                  Format_num(vcx, lwp->li_vcx, 4);
 563  565                                  Format_num(icx, lwp->li_icx, 4);
 564  566                                  Format_num(scl, lwp->li_scl, 4);
 565  567                                  Format_num(sig, lwp->li_sig, 4);
 566  568                                  Format_pct(trp, lwp->li_trp, 4);
 567  569                                  Format_pct(tfl, lwp->li_tfl, 4);
 568  570                                  Format_pct(dfl, lwp->li_dfl, 4);
 569  571                                  Format_pct(lck, lwp->li_lck, 4);
 570  572                                  Format_pct(lat, lwp->li_lat, 4);
 571  573                                  if (opts.o_outpmode & OPT_TTY)
 572  574                                          (void) putchar('\r');
 573      -                                stripfname(lwp->li_info.pr_fname);
 574  575                                  (void) printf(USAGE_LINE,
 575  576                                      (int)lwp->li_info.pr_pid, pname,
 576  577                                      usr, sys, trp, tfl, dfl, lck,
 577  578                                      slp, lat, vcx, icx, scl, sig,
 578      -                                    lwp->li_info.pr_fname, lwpid);
      579 +                                    name);
 579  580                                  (void) putp(t_eol);
 580  581                                  (void) putchar('\n');
 581  582                          }
 582  583                          break;
 583  584                  }
 584  585          }
 585  586  
 586  587          if (opts.o_outpmode & OPT_TTY)
 587  588                  (void) putchar('\r');
 588  589          if (opts.o_outpmode & OPT_TERMCAP) {
↓ open down ↓ 281 lines elided ↑ open up ↑
 870  871  
 871  872          lwpid = psinfo->pr_lwp.pr_lwpid;
 872  873          if ((lwp = lwpid_get(pid, lwpid)) == NULL)
 873  874                  lwp = list_add_lwp(&lwps, pid, lwpid);
 874  875          lwp->li_flags |= LWP_ALIVE | LWP_REPRESENT;
 875  876          (void) memcpy(&lwp->li_info, psinfo, sizeof (psinfo_t));
 876  877          lwp->li_info.pr_lwp.pr_pctcpu = lwp->li_info.pr_pctcpu;
 877  878  }
 878  879  
 879  880  static void
      881 +get_lwpname(pid_t pid, id_t lwpid, char *buf, size_t bufsize)
      882 +{
      883 +        char *path = NULL;
      884 +        int fd;
      885 +
      886 +        buf[0] = '\0';
      887 +
      888 +        if (asprintf(&path, "/proc/%d/lwp/%d/lwpname",
      889 +            (int)pid, (int)lwpid) == -1)
      890 +                return;
      891 +
      892 +        if ((fd = open(path, O_RDONLY)) != -1) {
      893 +                (void) read(fd, buf, bufsize);
      894 +                buf[bufsize - 1] = '\0';
      895 +                (void) close(fd);
      896 +        }
      897 +
      898 +        free(path);
      899 +}
      900 +
      901 +static void
 880  902  add_lwp(psinfo_t *psinfo, lwpsinfo_t *lwpsinfo, int flags)
 881  903  {
 882  904          lwp_info_t *lwp;
 883  905          pid_t pid = psinfo->pr_pid;
 884  906          id_t lwpid = lwpsinfo->pr_lwpid;
 885  907  
 886  908          if ((lwp = lwpid_get(pid, lwpid)) == NULL)
 887  909                  lwp = list_add_lwp(&lwps, pid, lwpid);
 888  910          lwp->li_flags &= ~LWP_REPRESENT;
 889  911          lwp->li_flags |= LWP_ALIVE;
 890  912          lwp->li_flags |= flags;
 891  913          (void) memcpy(&lwp->li_info, psinfo,
 892  914              sizeof (psinfo_t) - sizeof (lwpsinfo_t));
 893  915          (void) memcpy(&lwp->li_info.pr_lwp, lwpsinfo, sizeof (lwpsinfo_t));
      916 +        get_lwpname(pid, lwpid, lwp->li_lwpname, sizeof (lwp->li_lwpname));
 894  917  }
 895  918  
 896  919  static void
 897  920  prstat_scandir(DIR *procdir)
 898  921  {
 899  922          char *pidstr;
 900  923          pid_t pid;
 901  924          id_t lwpid;
 902  925          size_t entsz;
 903  926          long nlwps, nent, i;
↓ open down ↓ 202 lines elided ↑ open up ↑
1106 1129  
1107 1130                  } else {
1108 1131                          lwp_next = lwp->li_next;
1109 1132                          list_remove_lwp(&lwps, lwp);
1110 1133                          lwp = lwp_next;
1111 1134                  }
1112 1135          }
1113 1136  }
1114 1137  
1115 1138  static void
1116      -curses_on()
     1139 +curses_on(void)
1117 1140  {
1118 1141          if ((opts.o_outpmode & OPT_TERMCAP) && (is_curses_on == FALSE)) {
1119 1142                  (void) initscr();
1120 1143                  (void) nonl();
1121 1144                  (void) putp(t_smcup);
1122 1145                  is_curses_on = TRUE;
1123 1146          }
1124 1147  }
1125 1148  
1126 1149  static void
1127      -curses_off()
     1150 +curses_off(void)
1128 1151  {
1129 1152          if ((is_curses_on == TRUE) && (opts.o_outpmode & OPT_TERMCAP)) {
1130 1153                  (void) putp(t_rmcup);
1131 1154                  (void) endwin();
1132 1155                  is_curses_on = FALSE;
1133 1156          }
1134 1157          (void) fflush(stdout);
1135 1158  }
1136 1159  
1137 1160  static int
1138      -nlines()
     1161 +nlines(int *linesp, int *colsp)
1139 1162  {
1140 1163          struct winsize ws;
1141 1164          char *envp;
1142 1165          int n;
     1166 +
     1167 +        *linesp = -1;
     1168 +        *colsp = -1;
1143 1169          if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1) {
1144 1170                  if (ws.ws_row > 0)
1145      -                        return (ws.ws_row);
     1171 +                        *linesp = ws.ws_row;
     1172 +                if (ws.ws_col > 0)
     1173 +                        *colsp = ws.ws_col;
     1174 +                if (ws.ws_row > 0 && ws.ws_col > 0)
     1175 +                        return (0);
1146 1176          }
1147      -        if (envp = getenv("LINES")) {
     1177 +
     1178 +        if ((envp = getenv("LINES")) != NULL) {
1148 1179                  if ((n = Atoi(envp)) > 0) {
1149 1180                          opts.o_outpmode &= ~OPT_USEHOME;
1150      -                        return (n);
     1181 +                        *linesp = n;
1151 1182                  }
1152 1183          }
1153      -        return (-1);
     1184 +        if ((envp = getenv("COLUMNS")) != NULL) {
     1185 +                if ((n = Atoi(envp)) > 0) {
     1186 +                        *colsp = n;
     1187 +                }
     1188 +        }
     1189 +
     1190 +        return ((*linesp > 0 && *colsp > 0) ? 0 : -1);
1154 1191  }
1155 1192  
1156 1193  static void
1157      -setmovecur()
     1194 +setmovecur(void)
1158 1195  {
1159 1196          int i, n;
1160 1197          if ((opts.o_outpmode & OPT_FULLSCREEN) &&
1161 1198              (opts.o_outpmode & OPT_USEHOME)) {
1162 1199                  movecur = t_home;
1163 1200                  return;
1164 1201          }
1165 1202          if (opts.o_outpmode & OPT_SPLIT) {
1166 1203                  if (opts.o_ntop == 0)
1167 1204                          n = opts.o_nbottom + 1;
↓ open down ↓ 9 lines elided ↑ open up ↑
1177 1214                  n++;
1178 1215  
1179 1216          if (movecur != NULL && movecur != empty_string && movecur != t_home)
1180 1217                  free(movecur);
1181 1218          movecur = Zalloc(strlen(t_up) * (n + 5));
1182 1219          for (i = 0; i <= n; i++)
1183 1220                  (void) strcat(movecur, t_up);
1184 1221  }
1185 1222  
1186 1223  static int
1187      -setsize()
     1224 +setsize(void)
1188 1225  {
1189 1226          static int oldn = 0;
1190      -        int n;
     1227 +        int cols, n, ret;
1191 1228  
1192 1229          if (opts.o_outpmode & OPT_FULLSCREEN) {
1193      -                n = nlines();
     1230 +                ret = nlines(&n, &cols);
     1231 +                if (ret != -1)
     1232 +                        opts.o_cols = cols;
1194 1233                  if (n == oldn)
1195 1234                          return (0);
1196 1235                  oldn = n;
1197      -                if (n == -1) {
     1236 +                if (ret == -1) {
1198 1237                          opts.o_outpmode &= ~OPT_USEHOME;
1199 1238                          setmovecur();           /* set default window size */
1200 1239                          return (1);
1201 1240                  }
1202 1241                  n = n - 3;      /* minus header, total and cursor lines */
1203 1242                  if ((opts.o_outpmode & OPT_UDATE) ||
1204 1243                      (opts.o_outpmode & OPT_DDATE))
1205 1244                          n--;    /* minus timestamp */
1206 1245                  if (n < 1)
1207 1246                          Die(gettext("window is too small (try -n)\n"));
↓ open down ↓ 477 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX