Print this page
11690 ::ps -s could show service FMRIs
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Jason King <jason.king@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mdb/common/modules/genunix/genunix.c
          +++ new/usr/src/cmd/mdb/common/modules/genunix/genunix.c
↓ open down ↓ 53 lines elided ↑ open up ↑
  54   54  #include <sys/sysmacros.h>
  55   55  #include <sys/sysconf.h>
  56   56  #include <sys/task.h>
  57   57  #include <sys/project.h>
  58   58  #include <sys/errorq_impl.h>
  59   59  #include <sys/cred_impl.h>
  60   60  #include <sys/zone.h>
  61   61  #include <sys/panic.h>
  62   62  #include <regex.h>
  63   63  #include <sys/port_impl.h>
       64 +#include <sys/contract/process_impl.h>
  64   65  
  65   66  #include "avl.h"
  66   67  #include "bio.h"
  67   68  #include "bitset.h"
  68   69  #include "combined.h"
  69   70  #include "contract.h"
  70   71  #include "cpupart_mdb.h"
  71   72  #include "cred.h"
  72   73  #include "ctxop.h"
  73   74  #include "cyclic.h"
↓ open down ↓ 63 lines elided ↑ open up ↑
 137  138                  default: return ('?');
 138  139          }
 139  140  }
 140  141  
 141  142  #define PS_PRTTHREADS   0x1
 142  143  #define PS_PRTLWPS      0x2
 143  144  #define PS_PSARGS       0x4
 144  145  #define PS_TASKS        0x8
 145  146  #define PS_PROJECTS     0x10
 146  147  #define PS_ZONES        0x20
      148 +#define PS_SERVICES     0x40
 147  149  
 148  150  static int
 149  151  ps_threadprint(uintptr_t addr, const void *data, void *private)
 150  152  {
 151  153          const kthread_t *t = (const kthread_t *)data;
 152  154          uint_t prt_flags = *((uint_t *)private);
 153  155  
 154  156          static const mdb_bitmask_t t_state_bits[] = {
 155  157                  { "TS_FREE",    UINT_MAX,       TS_FREE         },
 156  158                  { "TS_SLEEP",   TS_SLEEP,       TS_SLEEP        },
↓ open down ↓ 109 lines elided ↑ open up ↑
 266  268  }
 267  269  
 268  270  typedef struct mdb_ps_proc {
 269  271          char            p_stat;
 270  272          struct pid      *p_pidp;
 271  273          struct pid      *p_pgidp;
 272  274          struct cred     *p_cred;
 273  275          struct sess     *p_sessp;
 274  276          struct task     *p_task;
 275  277          struct zone     *p_zone;
      278 +        struct cont_process *p_ct_process;
 276  279          pid_t           p_ppid;
 277  280          uint_t          p_flag;
 278  281          struct {
 279  282                  char            u_comm[MAXCOMLEN + 1];
 280  283                  char            u_psargs[PSARGSZ];
 281  284          } p_user;
 282  285  } mdb_ps_proc_t;
 283  286  
      287 +/*
      288 + * A reasonable enough limit. Note that we purposefully let this column over-run
      289 + * if needed.
      290 + */
      291 +#define FMRI_LEN (128)
      292 +
 284  293  int
 285  294  ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 286  295  {
 287  296          uint_t prt_flags = 0;
 288  297          mdb_ps_proc_t pr;
 289  298          struct pid pid, pgid, sid;
 290  299          sess_t session;
 291  300          cred_t cred;
 292  301          task_t tk;
 293  302          kproject_t pj;
 294  303          zone_t zn;
      304 +        struct cont_process cp;
      305 +        char fmri[FMRI_LEN] = "";
 295  306  
 296  307          if (!(flags & DCMD_ADDRSPEC)) {
 297  308                  if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) {
 298  309                          mdb_warn("can't walk 'proc'");
 299  310                          return (DCMD_ERR);
 300  311                  }
 301  312                  return (DCMD_OK);
 302  313          }
 303  314  
 304  315          if (mdb_getopts(argc, argv,
 305  316              'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags,
 306  317              'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags,
      318 +            's', MDB_OPT_SETBITS, PS_SERVICES, &prt_flags,
 307  319              'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags,
 308  320              'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags,
 309  321              'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags,
 310  322              't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc)
 311  323                  return (DCMD_USAGE);
 312  324  
 313  325          if (DCMD_HDRSPEC(flags)) {
 314      -                mdb_printf("%<u>%1s %6s %6s %6s %6s ",
      326 +                mdb_printf("%<u>%-1s %-6s %-6s %-6s %-6s ",
 315  327                      "S", "PID", "PPID", "PGID", "SID");
 316  328                  if (prt_flags & PS_TASKS)
 317      -                        mdb_printf("%5s ", "TASK");
      329 +                        mdb_printf("%-5s ", "TASK");
 318  330                  if (prt_flags & PS_PROJECTS)
 319      -                        mdb_printf("%5s ", "PROJ");
      331 +                        mdb_printf("%-5s ", "PROJ");
 320  332                  if (prt_flags & PS_ZONES)
 321      -                        mdb_printf("%5s ", "ZONE");
 322      -                mdb_printf("%6s %10s %?s %s%</u>\n",
      333 +                        mdb_printf("%-5s ", "ZONE");
      334 +                if (prt_flags & PS_SERVICES)
      335 +                        mdb_printf("%-40s ", "SERVICE");
      336 +                mdb_printf("%-6s %-10s %-?s %-s%</u>\n",
 323  337                      "UID", "FLAGS", "ADDR", "NAME");
 324  338          }
 325  339  
 326  340          if (mdb_ctf_vread(&pr, "proc_t", "mdb_ps_proc_t", addr, 0) == -1)
 327  341                  return (DCMD_ERR);
 328  342  
 329  343          mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp);
 330  344          mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp);
 331  345          mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred);
 332  346          mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp);
 333  347          mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp);
 334  348          if (prt_flags & (PS_TASKS | PS_PROJECTS))
 335  349                  mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task);
 336  350          if (prt_flags & PS_PROJECTS)
 337  351                  mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj);
 338  352          if (prt_flags & PS_ZONES)
 339  353                  mdb_vread(&zn, sizeof (zn), (uintptr_t)pr.p_zone);
      354 +        if ((prt_flags & PS_SERVICES) && pr.p_ct_process != NULL) {
      355 +                mdb_vread(&cp, sizeof (cp), (uintptr_t)pr.p_ct_process);
 340  356  
 341      -        mdb_printf("%c %6d %6d %6d %6d ",
      357 +                if (mdb_read_refstr((uintptr_t)cp.conp_svc_fmri, fmri,
      358 +                    sizeof (fmri)) <= 0)
      359 +                        (void) strlcpy(fmri, "?", sizeof (fmri));
      360 +
      361 +                /* Strip any standard prefix and suffix. */
      362 +                if (strncmp(fmri, "svc:/", sizeof ("svc:/") - 1) == 0) {
      363 +                        char *i = fmri;
      364 +                        char *j = fmri + sizeof ("svc:/") - 1;
      365 +                        for (; *j != '\0'; i++, j++) {
      366 +                                if (strcmp(j, ":default") == 0)
      367 +                                        break;
      368 +                                *i = *j;
      369 +                        }
      370 +
      371 +                        *i = '\0';
      372 +                }
      373 +        }
      374 +
      375 +        mdb_printf("%-c %-6d %-6d %-6d %-6d ",
 342  376              pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id,
 343  377              sid.pid_id);
 344  378          if (prt_flags & PS_TASKS)
 345      -                mdb_printf("%5d ", tk.tk_tkid);
      379 +                mdb_printf("%-5d ", tk.tk_tkid);
 346  380          if (prt_flags & PS_PROJECTS)
 347      -                mdb_printf("%5d ", pj.kpj_id);
      381 +                mdb_printf("%-5d ", pj.kpj_id);
 348  382          if (prt_flags & PS_ZONES)
 349      -                mdb_printf("%5d ", zn.zone_id);
 350      -        mdb_printf("%6d 0x%08x %0?p %s\n",
      383 +                mdb_printf("%-5d ", zn.zone_id);
      384 +        if (prt_flags & PS_SERVICES)
      385 +                mdb_printf("%-40s ", fmri);
      386 +        mdb_printf("%-6d 0x%08x %0?p %-s\n",
 351  387              cred.cr_uid, pr.p_flag, addr,
 352  388              (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm);
 353  389  
 354  390          if (prt_flags & ~PS_PSARGS)
 355  391                  (void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr);
 356  392  
 357  393          return (DCMD_OK);
 358  394  }
 359  395  
 360  396  static void
 361  397  ps_help(void)
 362  398  {
 363  399          mdb_printf("Display processes.\n\n"
 364  400              "Options:\n"
 365  401              "    -f\tDisplay command arguments\n"
 366  402              "    -l\tDisplay LWPs\n"
 367  403              "    -T\tDisplay tasks\n"
 368  404              "    -P\tDisplay projects\n"
      405 +            "    -s\tDisplay SMF FMRI\n"
 369  406              "    -z\tDisplay zones\n"
 370  407              "    -t\tDisplay threads\n\n");
 371  408  
 372  409          mdb_printf("The resulting output is a table of the processes on the "
 373  410              "system.  The\n"
 374  411              "columns in the output consist of a combination of the "
 375  412              "following fields:\n\n");
 376  413          mdb_printf("S\tProcess state.  Possible states are:\n"
 377  414              "\tS\tSleeping (SSLEEP)\n"
 378  415              "\tR\tRunnable (SRUN)\n"
↓ open down ↓ 3 lines elided ↑ open up ↑
 382  419              "\tT\tStopped (SSTOP)\n"
 383  420              "\tW\tWaiting (SWAIT)\n");
 384  421  
 385  422          mdb_printf("PID\tProcess id.\n");
 386  423          mdb_printf("PPID\tParent process id.\n");
 387  424          mdb_printf("PGID\tProcess group id.\n");
 388  425          mdb_printf("SID\tProcess id of the session leader.\n");
 389  426          mdb_printf("TASK\tThe task id of the process.\n");
 390  427          mdb_printf("PROJ\tThe project id of the process.\n");
 391  428          mdb_printf("ZONE\tThe zone id of the process.\n");
      429 +        mdb_printf("SERVICE The SMF service FMRI of the process.\n");
 392  430          mdb_printf("UID\tThe user id of the process.\n");
 393  431          mdb_printf("FLAGS\tThe process flags (see ::pflags).\n");
 394  432          mdb_printf("ADDR\tThe kernel address of the proc_t structure of the "
 395  433              "process\n");
 396  434          mdb_printf("NAME\tThe name (p_user.u_comm field) of the process.  If "
 397  435              "the -f flag\n"
 398  436              "\tis specified, the arguments of the process are displayed.\n");
 399  437  }
 400  438  
 401  439  #define PG_NEWEST       0x0001
↓ open down ↓ 4483 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX