Print this page
3946 ::gcore
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>


   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright (c) 2013, Joyent, Inc. All rights reserved.

  28  */
  29 
  30 #include <assert.h>
  31 #include <dlfcn.h>
  32 #include <errno.h>
  33 #include <libzonecfg.h>
  34 #include <link.h>
  35 #include <string.h>
  36 #include <strings.h>
  37 #include <sys/list.h>
  38 #include <sys/types.h>
  39 #include <sys/mkdev.h>
  40 #include <sys/mman.h>
  41 #include <sys/mnttab.h>
  42 
  43 #include "Pcontrol.h"
  44 
  45 struct path_node {
  46         struct path_node        *pn_next;
  47         char                    *pn_path;


 214 Pbrandname(struct ps_prochandle *P, char *buf, size_t buflen)
 215 {
 216         long    addr;
 217 
 218         if ((addr = Pgetauxval(P, AT_SUN_BRANDNAME)) == -1)
 219                 return (NULL);
 220 
 221         if (Pread_string(P, buf, buflen, addr) == -1)
 222                 return (NULL);
 223 
 224         return (buf);
 225 }
 226 
 227 /*
 228  * Get the zone name from the core file if we have it; look up the
 229  * name based on the zone id if this is a live process.
 230  */
 231 char *
 232 Pzonename(struct ps_prochandle *P, char *s, size_t n)
 233 {
 234         if (P->state == PS_IDLE) {
 235                 errno = ENODATA;
 236                 return (NULL);
 237         }
 238 
 239         if (P->state == PS_DEAD) {
 240                 if (P->core->core_zonename == NULL) {
 241                         errno = ENODATA;
 242                         return (NULL);
 243                 }
 244                 (void) strlcpy(s, P->core->core_zonename, n);
 245         } else {
 246                 if (getzonenamebyid(P->status.pr_zoneid, s, n) < 0)
 247                         return (NULL);
 248                 s[n - 1] = '\0';
 249         }
 250         return (s);
 251 }
 252 
 253 char *
 254 Pzoneroot(struct ps_prochandle *P, char *s, size_t n)
 255 {
 256         char zname[ZONENAME_MAX], zpath[PATH_MAX], tmp[PATH_MAX];
 257         int rv;
 258 
 259         if (P->zoneroot != NULL) {
 260                 (void) strlcpy(s, P->zoneroot, n);
 261                 return (s);
 262         }
 263 
 264         if ((Pzonename(P, zname, sizeof (zname)) == NULL) ||
 265             (strcmp(zname, GLOBAL_ZONENAME) == 0)) {
 266                 if ((P->zoneroot = strdup("")) == NULL) {
 267                         errno = ENOMEM;
 268                         return (NULL);
 269                 }
 270                 dprintf("Pzoneroot defaulting to '%s'\n", GLOBAL_ZONENAME);




   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  28  * Copyright (c) 2013 by Delphix. All rights reserved.
  29  */
  30 
  31 #include <assert.h>
  32 #include <dlfcn.h>
  33 #include <errno.h>
  34 #include <libzonecfg.h>
  35 #include <link.h>
  36 #include <string.h>
  37 #include <strings.h>
  38 #include <sys/list.h>
  39 #include <sys/types.h>
  40 #include <sys/mkdev.h>
  41 #include <sys/mman.h>
  42 #include <sys/mnttab.h>
  43 
  44 #include "Pcontrol.h"
  45 
  46 struct path_node {
  47         struct path_node        *pn_next;
  48         char                    *pn_path;


 215 Pbrandname(struct ps_prochandle *P, char *buf, size_t buflen)
 216 {
 217         long    addr;
 218 
 219         if ((addr = Pgetauxval(P, AT_SUN_BRANDNAME)) == -1)
 220                 return (NULL);
 221 
 222         if (Pread_string(P, buf, buflen, addr) == -1)
 223                 return (NULL);
 224 
 225         return (buf);
 226 }
 227 
 228 /*
 229  * Get the zone name from the core file if we have it; look up the
 230  * name based on the zone id if this is a live process.
 231  */
 232 char *
 233 Pzonename(struct ps_prochandle *P, char *s, size_t n)
 234 {
 235         return (P->ops.pop_zonename(P, s, n, P->data));
















 236 }
 237 
 238 char *
 239 Pzoneroot(struct ps_prochandle *P, char *s, size_t n)
 240 {
 241         char zname[ZONENAME_MAX], zpath[PATH_MAX], tmp[PATH_MAX];
 242         int rv;
 243 
 244         if (P->zoneroot != NULL) {
 245                 (void) strlcpy(s, P->zoneroot, n);
 246                 return (s);
 247         }
 248 
 249         if ((Pzonename(P, zname, sizeof (zname)) == NULL) ||
 250             (strcmp(zname, GLOBAL_ZONENAME) == 0)) {
 251                 if ((P->zoneroot = strdup("")) == NULL) {
 252                         errno = ENOMEM;
 253                         return (NULL);
 254                 }
 255                 dprintf("Pzoneroot defaulting to '%s'\n", GLOBAL_ZONENAME);