Print this page
OS-3280 need a way to specify the root of a native system in the lx brand
OS-3279 lx brand should allow delegated datasets
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ptools/psig/psig.c
          +++ new/usr/src/cmd/ptools/psig/psig.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  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   22   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
  24   25   */
  25   26  
  26      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  27      -
  28   27  #include <stdio.h>
  29   28  #include <stdio_ext.h>
  30   29  #include <stdlib.h>
  31   30  #include <unistd.h>
  32   31  #include <ctype.h>
  33   32  #include <fcntl.h>
  34   33  #include <string.h>
  35   34  #include <signal.h>
  36   35  #include <stddef.h>
  37   36  #include <sys/types.h>
  38   37  #include <sys/stat.h>
  39   38  #include <libproc.h>
       39 +#include "ptools_common.h"
  40   40  
  41   41  /* evil knowledge of libc internals */
  42   42  #include "../../../lib/libc/inc/thr_uberdata.h"
  43   43  
  44   44  #define MAX_SYMNAMLEN   1024    /* Recommended max symbol name length */
  45   45  
  46   46  static  char    *sigflags(int, int);
  47   47  static  int     look(char *);
  48   48  static  void    perr(char *);
  49   49  static  int     usage(void);
↓ open down ↓ 115 lines elided ↑ open up ↑
 165  165           * Return non-zero to terminate the iteration
 166  166           * if the sigmask has become all zeros.
 167  167           */
 168  168          return ((ssp->__sigbits[0] | ssp->__sigbits[1] |
 169  169              ssp->__sigbits[2] | ssp->__sigbits[3]) == 0);
 170  170  }
 171  171  
 172  172  static int
 173  173  look(char *arg)
 174  174  {
 175      -        char pathname[100];
      175 +        char pathname[PATH_MAX];
 176  176          struct stat statb;
 177  177          int fd = -1;
 178  178          int sig, gcode;
 179  179          sigset_t holdmask;
 180  180          int maxsig;
 181  181          struct sigaction *action = NULL;
 182  182          psinfo_t psinfo;
 183  183          const psinfo_t *psinfop;
 184  184          struct ps_prochandle *Pr = NULL;
 185  185          uintptr_t uberaddr;
↓ open down ↓ 6 lines elided ↑ open up ↑
 192  192          procname = arg;         /* for perr() */
 193  193          if ((Pr = proc_arg_grab(arg, PR_ARG_PIDS, PGRAB_RDONLY|PGRAB_FORCE,
 194  194              &gcode)) == NULL || (psinfop = Ppsinfo(Pr)) == NULL) {
 195  195                  (void) fprintf(stderr, "%s: cannot examine %s: %s\n",
 196  196                      command, arg, Pgrab_error(gcode));
 197  197                  goto look_error;
 198  198          }
 199  199          (void) memcpy(&psinfo, psinfop, sizeof (psinfo_t));
 200  200          proc_unctrl_psinfo(&psinfo);
 201  201  
 202      -        (void) sprintf(pathname, "/proc/%d/sigact", (int)psinfo.pr_pid);
      202 +        (void) proc_snprintf(pathname, sizeof (pathname), "/proc/%d/sigact",
      203 +            (int)psinfo.pr_pid);
 203  204          if ((fd = open(pathname, O_RDONLY)) < 0) {
 204  205                  perr("open sigact");
 205  206                  goto look_error;
 206  207          }
 207  208  
 208  209          if (fstat(fd, &statb) != 0) {
 209  210                  perr("fstat sigact");
 210  211                  goto look_error;
 211  212          }
 212  213          maxsig = statb.st_size / sizeof (struct sigaction);
 213  214          action = malloc(maxsig * sizeof (struct sigaction));
 214  215          if (action == NULL) {
 215  216                  (void) fprintf(stderr,
 216      -                "%s: cannot malloc() space for %d sigaction structures\n",
 217      -                        command, maxsig);
      217 +                    "%s: cannot malloc() space for %d sigaction structures\n",
      218 +                    command, maxsig);
 218  219                  goto look_error;
 219  220          }
 220  221          if (read(fd, (char *)action, maxsig * sizeof (struct sigaction)) !=
 221  222              maxsig * sizeof (struct sigaction)) {
 222  223                  perr("read sigact");
 223  224                  goto look_error;
 224  225          }
 225  226          (void) close(fd);
 226  227          fd = -1;
 227  228  
↓ open down ↓ 4 lines elided ↑ open up ↑
 232  233  
 233  234          if ((uberaddr = uberdata_addr(Pr, psinfo.pr_dmodel)) == 0) {
 234  235                  aharraddr = 0;
 235  236                  aharrlen = 0;
 236  237                  intfnaddr = 0;
 237  238          } else {
 238  239  #ifdef _LP64
 239  240                  if (psinfo.pr_dmodel != PR_MODEL_NATIVE) {
 240  241                          caddr32_t addr;
 241  242                          aharraddr = uberaddr +
 242      -                                offsetof(uberdata32_t, siguaction);
      243 +                            offsetof(uberdata32_t, siguaction);
 243  244                          aharrlen = sizeof (siguaction32_t) * NSIG;
 244  245                          (void) Pread(Pr, &addr, sizeof (addr),
 245  246                              uberaddr + offsetof(uberdata32_t, sigacthandler));
 246  247                          intfnaddr = (uintptr_t)addr;
 247  248                  } else
 248  249  #endif
 249  250                  {
 250  251                          aharraddr = uberaddr +
 251      -                                offsetof(uberdata_t, siguaction);
      252 +                            offsetof(uberdata_t, siguaction);
 252  253                          aharrlen = sizeof (siguaction_t) * NSIG;
 253  254                          (void) Pread(Pr, &intfnaddr, sizeof (intfnaddr),
 254  255                              uberaddr + offsetof(uberdata_t, sigacthandler));
 255  256                  }
 256  257          }
 257  258  
 258  259          if (aharraddr) {
 259  260                  aharr = malloc(aharrlen);
 260  261                  if (aharr == NULL) {
 261  262                          (void) fprintf(stderr,
↓ open down ↓ 54 lines elided ↑ open up ↑
 316  317                                          (void) printf("caught");
 317  318                          }
 318  319  
 319  320                          if (caught || all_flag) {
 320  321                                  if (lookuphandlers_flag && haddr > 1 &&
 321  322                                      Plookup_by_addr(Pr, haddr, hname,
 322  323                                      sizeof (hname), &hsym) == 0)
 323  324                                          (void) printf("\t%-8s", hname);
 324  325                                  else
 325  326                                          (void) printf("\t0x%-8lx",
 326      -                                                (ulong_t)haddr);
      327 +                                            (ulong_t)haddr);
 327  328  
 328  329                                  s = sigflags(sig, sp->sa_flags);
 329  330                                  (void) printf("%s", (*s != '\0')? s : "\t0");
 330  331                                  (void) proc_sigset2str(&sp->sa_mask, ",", 1,
 331  332                                      buf, sizeof (buf));
 332  333                                  if (buf[0] != '\0')
 333  334                                          (void) printf("\t%s", buf);
 334  335                          }
 335  336                  } else if (sig == SIGCLD) {
 336  337                          s = sigflags(sig,
 337      -                                sp->sa_flags & (SA_NOCLDWAIT|SA_NOCLDSTOP));
      338 +                            sp->sa_flags & (SA_NOCLDWAIT|SA_NOCLDSTOP));
 338  339                          if (*s != '\0')
 339  340                                  (void) printf("\t\t%s", s);
 340  341                  }
 341  342                  (void) printf("\n");
 342  343          }
 343  344  
 344  345          error = 0;
 345  346  
 346  347  look_error:
 347  348          if (fd >= 0)
↓ open down ↓ 16 lines elided ↑ open up ↑
 364  365                  s = procname;
 365  366          perror(s);
 366  367  }
 367  368  
 368  369  static char *
 369  370  sigflags(int sig, int flags)
 370  371  {
 371  372          static char code_buf[100];
 372  373          char *str = code_buf;
 373  374          int flagmask =
 374      -                (SA_ONSTACK|SA_RESETHAND|SA_RESTART|SA_SIGINFO|SA_NODEFER);
      375 +            (SA_ONSTACK|SA_RESETHAND|SA_RESTART|SA_SIGINFO|SA_NODEFER);
 375  376  
 376  377          if (sig == SIGCLD)
 377  378                  flagmask |= (SA_NOCLDSTOP|SA_NOCLDWAIT);
 378  379  
 379  380          *str = '\0';
 380  381          if (flags & ~flagmask)
 381  382                  (void) sprintf(str, ",0x%x,", flags & ~flagmask);
 382  383          else if (flags == 0)
 383  384                  return (str);
 384  385  
↓ open down ↓ 22 lines elided ↑ open up ↑
 407  408  
 408  409  /*ARGSUSED2*/
 409  410  static uintptr_t
 410  411  deinterpose(int sig, void *aharr, psinfo_t *psinfo, struct sigaction *sp)
 411  412  {
 412  413          if (sp->sa_handler == SIG_DFL || sp->sa_handler == SIG_IGN)
 413  414                  return ((uintptr_t)sp->sa_handler);
 414  415  #ifdef _LP64
 415  416          if (psinfo->pr_dmodel != PR_MODEL_NATIVE) {
 416  417                  struct sigaction32 *sa32 = (struct sigaction32 *)
 417      -                        ((uintptr_t)aharr + sig * sizeof (siguaction32_t) +
 418      -                        offsetof(siguaction32_t, sig_uaction));
      418 +                    ((uintptr_t)aharr + sig * sizeof (siguaction32_t) +
      419 +                    offsetof(siguaction32_t, sig_uaction));
 419  420  
 420  421                  sp->sa_flags = sa32->sa_flags;
 421  422                  sp->sa_handler = (void (*)())(uintptr_t)sa32->sa_handler;
 422  423                  (void) memcpy(&sp->sa_mask, &sa32->sa_mask,
 423      -                        sizeof (sp->sa_mask));
      424 +                    sizeof (sp->sa_mask));
 424  425          } else
 425  426  #endif
 426  427          {
 427  428                  struct sigaction *sa = (struct sigaction *)
 428      -                        ((uintptr_t)aharr + sig * sizeof (siguaction_t) +
 429      -                        offsetof(siguaction_t, sig_uaction));
      429 +                    ((uintptr_t)aharr + sig * sizeof (siguaction_t) +
      430 +                    offsetof(siguaction_t, sig_uaction));
 430  431  
 431  432                  sp->sa_flags = sa->sa_flags;
 432  433                  sp->sa_handler = sa->sa_handler;
 433  434                  sp->sa_mask = sa->sa_mask;
 434  435          }
 435  436          return ((uintptr_t)sp->sa_handler);
 436  437  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX