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


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



  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <limits.h>
  30 #include <string.h>
  31 #include <stdarg.h>
  32 #include <stdio.h>
  33 #include <errno.h>
  34 
  35 #include "Pcontrol.h"
  36 #include "Putil.h"
  37 
  38 /*
  39  * Place the new element on the list prior to the existing element.
  40  */
  41 void
  42 list_link(void *new, void *existing)
  43 {
  44         plist_t *p = new;
  45         plist_t *q = existing;
  46 
  47         if (q) {
  48                 p->list_forw = q;


 132                 (void) vfprintf(stderr, format, alist);
 133                 va_end(alist);
 134         }
 135 }
 136 
 137 /*
 138  * Printf-style error reporting function.  This is used to supplement the error
 139  * return codes from various libproc functions with additional text.  Since we
 140  * are a library, and should not be spewing messages to stderr, we provide a
 141  * default version of this function that does nothing, but by calling this
 142  * function we allow the client program to define its own version of the
 143  * function that will interpose on our empty default.  This may be useful for
 144  * clients that wish to display such messages to the user.
 145  */
 146 /*ARGSUSED*/
 147 /*PRINTFLIKE2*/
 148 void
 149 Perror_printf(struct ps_prochandle *P, const char *format, ...)
 150 {
 151         /* nothing to do here */





























































































 152 }


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


  30 #include <limits.h>
  31 #include <string.h>
  32 #include <stdarg.h>
  33 #include <stdio.h>
  34 #include <errno.h>
  35 
  36 #include "Pcontrol.h"
  37 #include "Putil.h"
  38 
  39 /*
  40  * Place the new element on the list prior to the existing element.
  41  */
  42 void
  43 list_link(void *new, void *existing)
  44 {
  45         plist_t *p = new;
  46         plist_t *q = existing;
  47 
  48         if (q) {
  49                 p->list_forw = q;


 133                 (void) vfprintf(stderr, format, alist);
 134                 va_end(alist);
 135         }
 136 }
 137 
 138 /*
 139  * Printf-style error reporting function.  This is used to supplement the error
 140  * return codes from various libproc functions with additional text.  Since we
 141  * are a library, and should not be spewing messages to stderr, we provide a
 142  * default version of this function that does nothing, but by calling this
 143  * function we allow the client program to define its own version of the
 144  * function that will interpose on our empty default.  This may be useful for
 145  * clients that wish to display such messages to the user.
 146  */
 147 /*ARGSUSED*/
 148 /*PRINTFLIKE2*/
 149 void
 150 Perror_printf(struct ps_prochandle *P, const char *format, ...)
 151 {
 152         /* nothing to do here */
 153 }
 154 
 155 /*
 156  * Default operations.
 157  */
 158 static ssize_t
 159 Pdefault_ssizet()
 160 {
 161         return (-1);
 162 }
 163 
 164 static int
 165 Pdefault_int()
 166 {
 167         return (-1);
 168 }
 169 
 170 static void
 171 Pdefault_void()
 172 {
 173 }
 174 
 175 static void *
 176 Pdefault_voidp()
 177 {
 178         return (NULL);
 179 }
 180 
 181 static const ps_ops_t P_default_ops = {
 182         .pop_pread      = (pop_pread_t)Pdefault_ssizet,
 183         .pop_pwrite     = (pop_pwrite_t)Pdefault_ssizet,
 184         .pop_read_maps  = (pop_read_maps_t)Pdefault_int,
 185         .pop_read_aux   = (pop_read_aux_t)Pdefault_void,
 186         .pop_cred       = (pop_cred_t)Pdefault_int,
 187         .pop_priv       = (pop_priv_t)Pdefault_int,
 188         .pop_psinfo     = (pop_psinfo_t)Pdefault_voidp,
 189         .pop_status     = (pop_status_t)Pdefault_void,
 190         .pop_lstatus    = (pop_lstatus_t)Pdefault_voidp,
 191         .pop_lpsinfo    = (pop_lpsinfo_t)Pdefault_voidp,
 192         .pop_fini       = (pop_fini_t)Pdefault_void,
 193         .pop_platform   = (pop_platform_t)Pdefault_voidp,
 194         .pop_uname      = (pop_uname_t)Pdefault_int,
 195         .pop_zonename   = (pop_zonename_t)Pdefault_voidp,
 196         .pop_execname   = (pop_execname_t)Pdefault_voidp,
 197 #if defined(__i386) || defined(__amd64)
 198         .pop_ldt        = (pop_ldt_t)Pdefault_int
 199 #endif
 200 };
 201 
 202 /*
 203  * Initialize the destination ops vector with functions from the source.
 204  * Functions which are NULL in the source ops vector are set to corresponding
 205  * default function in the destination vector.
 206  */
 207 void
 208 Pinit_ops(ps_ops_t *dst, const ps_ops_t *src)
 209 {
 210         *dst = P_default_ops;
 211 
 212         if (src->pop_pread != NULL)
 213                 dst->pop_pread = src->pop_pread;
 214         if (src->pop_pwrite != NULL)
 215                 dst->pop_pwrite = src->pop_pwrite;
 216         if (src->pop_read_maps != NULL)
 217                 dst->pop_read_maps = src->pop_read_maps;
 218         if (src->pop_read_aux != NULL)
 219                 dst->pop_read_aux = src->pop_read_aux;
 220         if (src->pop_cred != NULL)
 221                 dst->pop_cred = src->pop_cred;
 222         if (src->pop_priv != NULL)
 223                 dst->pop_priv = src->pop_priv;
 224         if (src->pop_psinfo != NULL)
 225                 dst->pop_psinfo = src->pop_psinfo;
 226         if (src->pop_status != NULL)
 227                 dst->pop_status = src->pop_status;
 228         if (src->pop_lstatus != NULL)
 229                 dst->pop_lstatus = src->pop_lstatus;
 230         if (src->pop_lpsinfo != NULL)
 231                 dst->pop_lpsinfo = src->pop_lpsinfo;
 232         if (src->pop_fini != NULL)
 233                 dst->pop_fini = src->pop_fini;
 234         if (src->pop_platform != NULL)
 235                 dst->pop_platform = src->pop_platform;
 236         if (src->pop_uname != NULL)
 237                 dst->pop_uname = src->pop_uname;
 238         if (src->pop_zonename != NULL)
 239                 dst->pop_zonename = src->pop_zonename;
 240         if (src->pop_execname != NULL)
 241                 dst->pop_execname = src->pop_execname;
 242 #if defined(__i386) || defined(__amd64)
 243         if (src->pop_ldt != NULL)
 244                 dst->pop_ldt = src->pop_ldt;
 245 #endif
 246 }