Print this page
NEX-9665 libcfgadm: memory leak in do_list_common()
Reviewed by: Jan Kryl <jan.kryl@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
NEX-9634 cfgadm_plugins/shp: memory leaks in cfga_list_ext()
Reviewed by: Jan Kryl <jan.kryl@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
NEX-8148 Alerts should be sent if cores are created on a system (lint fix)
NEX-8148 Alerts should be sent if cores are created on a system
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/core.c
          +++ new/usr/src/uts/common/os/core.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  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  /*
  23   23   * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright (c) 2011, Joyent Inc. All rights reserved.
  25   25   * Copyright (c) 2016 by Delphix. All rights reserved.
       26 + * Copyright 2017 Nexenta Systems, Inc.
  26   27   */
  27   28  
  28   29  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  29   30  /*        All Rights Reserved   */
  30   31  
  31   32  #include <sys/param.h>
  32   33  #include <sys/types.h>
  33   34  #include <sys/time.h>
  34   35  #include <sys/sysmacros.h>
  35   36  #include <sys/proc.h>
↓ open down ↓ 21 lines elided ↑ open up ↑
  57   58  #include <sys/core.h>
  58   59  #include <sys/corectl.h>
  59   60  #include <sys/cmn_err.h>
  60   61  #include <vm/as.h>
  61   62  #include <sys/rctl.h>
  62   63  #include <sys/nbmlock.h>
  63   64  #include <sys/stat.h>
  64   65  #include <sys/zone.h>
  65   66  #include <sys/contract/process_impl.h>
  66   67  #include <sys/ddi.h>
       68 +#include <sys/fm/protocol.h>
       69 +#include <sys/fm/util.h>
       70 +#include <sys/fm/sw/core.h>
       71 +#include <sys/sysevent.h>
  67   72  
  68   73  /*
  69   74   * Processes running within a zone potentially dump core in 3 locations,
  70   75   * based on the per-process, per-zone, and the global zone's core settings.
  71   76   *
  72   77   * Per-zone and global zone settings are often referred to as "global"
  73   78   * settings since they apply to the system (or zone) as a whole, as
  74   79   * opposed to a particular process.
  75   80   */
  76   81  enum core_types {
↓ open down ↓ 20 lines elided ↑ open up ↑
  97  102                  zcmn_err(zoneid, CE_NOTE, "core_log: %s[%d] %s", fn, pid, why);
  98  103          else if (error == 0)
  99  104                  zcmn_err(zoneid, CE_NOTE, "core_log: %s[%d] %s: %s", fn, pid,
 100  105                      why, path);
 101  106          else
 102  107                  zcmn_err(zoneid, CE_NOTE, "core_log: %s[%d] %s, errno=%d: %s",
 103  108                      fn, pid, why, error, path);
 104  109  }
 105  110  
 106  111  /*
      112 + * Generate FMA e-report for a core.
      113 + */
      114 +static void
      115 +gen_ereport(const char *path, int sig)
      116 +{
      117 +        nvlist_t *ereport = NULL;
      118 +        nvlist_t *fmri = NULL;
      119 +        nvlist_t *sw_obj = NULL;
      120 +        uint64_t ena;
      121 +        proc_t *p = curproc;
      122 +        int err = 0;
      123 +
      124 +        if ((ereport = fm_nvlist_create(NULL)) == NULL)
      125 +                return;
      126 +        if ((fmri = fm_nvlist_create(NULL)) == NULL)
      127 +                goto out;
      128 +        if ((sw_obj = fm_nvlist_create(NULL)) == NULL)
      129 +                goto out;
      130 +        ena = fm_ena_generate(0, FM_ENA_FMT1);
      131 +
      132 +        err |= nvlist_add_uint8(fmri, FM_VERSION, FM_SW_SCHEME_VERSION);
      133 +        err |= nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_SW);
      134 +        err |= nvlist_add_string(sw_obj, FM_FMRI_SW_OBJ_PATH, path);
      135 +        err |= nvlist_add_nvlist(fmri, FM_FMRI_SW_OBJ, sw_obj);
      136 +
      137 +        if (err != 0)
      138 +                goto out;
      139 +
      140 +        fm_ereport_set(ereport, FM_EREPORT_VERSION, CORE_ERROR_CLASS,
      141 +            ena, fmri, NULL);
      142 +
      143 +        fm_payload_set(ereport,
      144 +            FM_EREPORT_PAYLOAD_CORE_COMMAND, DATA_TYPE_STRING,
      145 +            p->p_exec->v_path ? p->p_exec->v_path : p->p_user.u_comm,
      146 +            FM_EREPORT_PAYLOAD_CORE_PSARGS, DATA_TYPE_STRING,
      147 +            p->p_user.u_psargs,
      148 +            FM_EREPORT_PAYLOAD_CORE_SIGNAL, DATA_TYPE_INT32, sig,
      149 +            FM_EREPORT_PAYLOAD_CORE_PATH, DATA_TYPE_STRING, path,
      150 +            NULL);
      151 +
      152 +        fm_ereport_post(ereport, EVCH_SLEEP);
      153 +
      154 +out:
      155 +        fm_nvlist_destroy(sw_obj, FM_NVA_FREE);
      156 +        fm_nvlist_destroy(ereport, FM_NVA_FREE);
      157 +        fm_nvlist_destroy(fmri, FM_NVA_FREE);
      158 +}
      159 +
      160 +/*
 107  161   * Private version of vn_remove().
 108  162   * Refuse to unlink a directory or an unwritable file.
 109  163   * Also allow the process to access files normally inaccessible due to
 110  164   * chroot(2) or Zone limitations.
 111  165   */
 112  166  static int
 113  167  remove_core_file(char *fp, enum core_types core_type)
 114  168  {
 115  169          vnode_t *vp = NULL;             /* entry vnode */
 116  170          vnode_t *dvp;                   /* ptr to parent dir vnode */
↓ open down ↓ 639 lines elided ↑ open up ↑
 756  810          mutex_enter(&p->p_lock);
 757  811          curthread->t_hold = sigmask;
 758  812          mutex_exit(&p->p_lock);
 759  813  
 760  814          if (!ext && p->p_ct_process != NULL)
 761  815                  contract_process_core(p->p_ct_process, p, sig,
 762  816                      error1 == 0 ? fp_process : NULL,
 763  817                      error2 == 0 ? fp_global : NULL,
 764  818                      error3 == 0 ? fp_zone : NULL);
 765  819  
      820 +        /*
      821 +         * FMA ereport is currently generated only for global zone cores
      822 +         * with global path.
      823 +         */
      824 +        if (error2 == 0 && global_cg == my_cg)
      825 +                gen_ereport(fp_global, sig);
      826 +
 766  827          if (fp_process != NULL)
 767  828                  kmem_free(fp_process, MAXPATHLEN);
 768  829          if (fp_global != NULL)
 769  830                  kmem_free(fp_global, MAXPATHLEN);
 770  831          if (fp_zone != NULL)
 771  832                  kmem_free(fp_zone, MAXPATHLEN);
 772  833  
 773  834          /*
 774  835           * Return non-zero if no core file was created.
 775  836           */
↓ open down ↓ 91 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX