Print this page


Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ptools/pargs/pargs.c
          +++ new/usr/src/cmd/ptools/pargs/pargs.c
↓ open down ↓ 65 lines elided ↑ open up ↑
  66   66  #include <setjmp.h>
  67   67  #include <sys/types.h>
  68   68  #include <sys/auxv.h>
  69   69  #include <sys/archsystm.h>
  70   70  #include <sys/proc.h>
  71   71  #include <sys/elf.h>
  72   72  #include <libproc.h>
  73   73  #include <wctype.h>
  74   74  #include <widec.h>
  75   75  #include <elfcap.h>
  76      -#include <libgen.h>
  77   76  
  78      -typedef enum pargs_cmd {
  79      -        PARGS_ARGV,
  80      -        PARGS_ENV,
  81      -        PARGS_AUXV
  82      -} pargs_cmd_t;
  83      -
  84   77  typedef struct pargs_data {
  85   78          struct ps_prochandle *pd_proc;  /* target proc handle */
  86   79          psinfo_t *pd_psinfo;            /* target psinfo */
  87   80          char *pd_locale;                /* target process locale */
  88   81          int pd_conv_flags;              /* flags governing string conversion */
  89   82          iconv_t pd_iconv;               /* iconv conversion descriptor */
  90   83          size_t pd_argc;
  91   84          uintptr_t *pd_argv;
  92   85          char **pd_argv_strs;
  93   86          size_t pd_envc;
↓ open down ↓ 1189 lines elided ↑ open up ↑
1283 1276  }
1284 1277  
1285 1278  int
1286 1279  main(int argc, char *argv[])
1287 1280  {
1288 1281          int aflag = 0, cflag = 0, eflag = 0, xflag = 0, lflag = 0;
1289 1282          int errflg = 0, retc = 0;
1290 1283          int opt;
1291 1284          int error = 1;
1292 1285          core_content_t content = 0;
1293      -        pargs_cmd_t cmd = PARGS_ARGV;
1294 1286  
1295 1287          (void) setlocale(LC_ALL, "");
1296 1288  
1297      -        command = basename(argv[0]);
     1289 +        if ((command = strrchr(argv[0], '/')) != NULL)
     1290 +                command++;
     1291 +        else
     1292 +                command = argv[0];
1298 1293  
1299      -        if (strcmp(command, "penv") == 0)
1300      -                cmd = PARGS_ENV;
1301      -        else if (strcmp(command, "pauxv") == 0)
1302      -                cmd = PARGS_AUXV;
1303      -
1304 1294          while ((opt = getopt(argc, argv, "acelxF")) != EOF) {
1305 1295                  switch (opt) {
1306 1296                  case 'a':               /* show process arguments */
1307 1297                          content |= CC_CONTENT_STACK;
1308 1298                          aflag++;
1309      -                        if (cmd != PARGS_ARGV)
1310      -                                errflg++;
1311 1299                          break;
1312 1300                  case 'c':               /* force 7-bit ascii */
1313 1301                          cflag++;
1314 1302                          break;
1315 1303                  case 'e':               /* show environment variables */
1316 1304                          content |= CC_CONTENT_STACK;
1317 1305                          eflag++;
1318      -                        if (cmd != PARGS_ARGV)
1319      -                                errflg++;
1320 1306                          break;
1321 1307                  case 'l':
1322 1308                          lflag++;
1323 1309                          aflag++;        /* -l implies -a */
1324      -                        if (cmd != PARGS_ARGV)
1325      -                                errflg++;
1326 1310                          break;
1327 1311                  case 'x':               /* show aux vector entries */
1328 1312                          xflag++;
1329      -                        if (cmd != PARGS_ARGV)
1330      -                                errflg++;
1331 1313                          break;
1332 1314                  case 'F':
1333 1315                          /*
1334 1316                           * Since we open the process read-only, there is no need
1335 1317                           * for the -F flag.  It's a documented flag, so we
1336 1318                           * consume it silently.
1337 1319                           */
1338 1320                          break;
1339 1321                  default:
1340 1322                          errflg++;
1341 1323                          break;
1342 1324                  }
1343 1325          }
1344 1326  
1345 1327          /* -a is the default if no options are specified */
1346 1328          if ((aflag + eflag + xflag + lflag) == 0) {
1347      -                switch (cmd) {
1348      -                case PARGS_ARGV:
1349      -                        aflag++;
1350      -                        content |= CC_CONTENT_STACK;
1351      -                        break;
1352      -                case PARGS_ENV:
1353      -                        content |= CC_CONTENT_STACK;
1354      -                        eflag++;
1355      -                        break;
1356      -                case PARGS_AUXV:
1357      -                        xflag++;
1358      -                        break;
1359      -                }
     1329 +                aflag++;
     1330 +                content |= CC_CONTENT_STACK;
1360 1331          }
1361 1332  
1362 1333          /* -l cannot be used with the -x or -e flags */
1363 1334          if (lflag && (xflag || eflag)) {
1364 1335                  (void) fprintf(stderr, "-l is incompatible with -x and -e\n");
1365 1336                  errflg++;
1366 1337          }
1367 1338  
1368 1339          argc -= optind;
1369 1340          argv += optind;
↓ open down ↓ 231 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX