1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #include <stdio.h> 29*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 30*7c478bd9Sstevel@tonic-gate #include <unistd.h> 31*7c478bd9Sstevel@tonic-gate #include <string.h> /* for strerror() */ 32*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/tnf.h> 35*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 36*7c478bd9Sstevel@tonic-gate #include <errno.h> 37*7c478bd9Sstevel@tonic-gate #include <locale.h> 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #include "prbk.h" 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #include <tnf/tnfctl.h> 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate extern tnfctl_handle_t *g_hndl; 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate typedef struct _pidlist { 46*7c478bd9Sstevel@tonic-gate pid_t pid; 47*7c478bd9Sstevel@tonic-gate struct _pidlist *next; 48*7c478bd9Sstevel@tonic-gate } pidlist_t; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate static boolean_t check_kernelmode(tnfctl_trace_attrs_t *attrs_p); 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate static boolean_t 53*7c478bd9Sstevel@tonic-gate check_kernelmode(tnfctl_trace_attrs_t *attrs_p) 54*7c478bd9Sstevel@tonic-gate { 55*7c478bd9Sstevel@tonic-gate extern int g_kernelmode; 56*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate if (!g_kernelmode) { 59*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 60*7c478bd9Sstevel@tonic-gate "This command is only available " 61*7c478bd9Sstevel@tonic-gate "in kernel mode (prex invoked with the -k flag)\n")); 62*7c478bd9Sstevel@tonic-gate return (B_TRUE); 63*7c478bd9Sstevel@tonic-gate } 64*7c478bd9Sstevel@tonic-gate if (attrs_p) { 65*7c478bd9Sstevel@tonic-gate err = tnfctl_trace_attrs_get(g_hndl, attrs_p); 66*7c478bd9Sstevel@tonic-gate if (err) { 67*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 68*7c478bd9Sstevel@tonic-gate "error on checking trace attributes : %s\n"), 69*7c478bd9Sstevel@tonic-gate tnfctl_strerror(err)); 70*7c478bd9Sstevel@tonic-gate return (B_TRUE); 71*7c478bd9Sstevel@tonic-gate } 72*7c478bd9Sstevel@tonic-gate } 73*7c478bd9Sstevel@tonic-gate return (B_FALSE); 74*7c478bd9Sstevel@tonic-gate } 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* 77*7c478bd9Sstevel@tonic-gate * Print trace buffer status (is one allocated, and if so, how big is it. 78*7c478bd9Sstevel@tonic-gate */ 79*7c478bd9Sstevel@tonic-gate void 80*7c478bd9Sstevel@tonic-gate prbk_buffer_list() 81*7c478bd9Sstevel@tonic-gate { 82*7c478bd9Sstevel@tonic-gate tnfctl_trace_attrs_t attrs; 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate if (check_kernelmode(&attrs)) 85*7c478bd9Sstevel@tonic-gate return; 86*7c478bd9Sstevel@tonic-gate if (attrs.trace_buf_state == TNFCTL_BUF_NONE) { 87*7c478bd9Sstevel@tonic-gate (void) printf(gettext("No trace buffer allocated\n")); 88*7c478bd9Sstevel@tonic-gate } else { 89*7c478bd9Sstevel@tonic-gate (void) printf(gettext("Trace buffer size is %d bytes\n"), 90*7c478bd9Sstevel@tonic-gate attrs.trace_buf_size); 91*7c478bd9Sstevel@tonic-gate if (attrs.trace_buf_state == TNFCTL_BUF_BROKEN) { 92*7c478bd9Sstevel@tonic-gate (void) printf(gettext("Tracing system has failed -- " 93*7c478bd9Sstevel@tonic-gate "tracing suspended\n")); 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate } 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate /* 100*7c478bd9Sstevel@tonic-gate * Allocate a trace buffer. Check for reasonable size; reject if there's 101*7c478bd9Sstevel@tonic-gate * already a buffer. 102*7c478bd9Sstevel@tonic-gate */ 103*7c478bd9Sstevel@tonic-gate void 104*7c478bd9Sstevel@tonic-gate prbk_buffer_alloc(int size) 105*7c478bd9Sstevel@tonic-gate { 106*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 107*7c478bd9Sstevel@tonic-gate tnfctl_trace_attrs_t attrs; 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate if (check_kernelmode(&attrs)) 110*7c478bd9Sstevel@tonic-gate return; 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate if (attrs.trace_buf_state != TNFCTL_BUF_NONE) { 113*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 114*7c478bd9Sstevel@tonic-gate gettext("There is already a buffer allocated\n")); 115*7c478bd9Sstevel@tonic-gate return; 116*7c478bd9Sstevel@tonic-gate } 117*7c478bd9Sstevel@tonic-gate if (size < attrs.trace_min_size) { 118*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 119*7c478bd9Sstevel@tonic-gate "Size %d is less than the minimum buffer size of %d -- " 120*7c478bd9Sstevel@tonic-gate "buffer size set to %d bytes\n"), 121*7c478bd9Sstevel@tonic-gate size, attrs.trace_min_size, attrs.trace_min_size); 122*7c478bd9Sstevel@tonic-gate size = attrs.trace_min_size; 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate err = tnfctl_buffer_alloc(g_hndl, NULL, size); 126*7c478bd9Sstevel@tonic-gate if (err) { 127*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 128*7c478bd9Sstevel@tonic-gate gettext("error in allocating buffer: %s\n"), 129*7c478bd9Sstevel@tonic-gate tnfctl_strerror(err)); 130*7c478bd9Sstevel@tonic-gate return; 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate /* get the trace attributes again */ 134*7c478bd9Sstevel@tonic-gate if (check_kernelmode(&attrs)) 135*7c478bd9Sstevel@tonic-gate return; 136*7c478bd9Sstevel@tonic-gate (void) printf(gettext("Buffer of size %d bytes allocated\n"), 137*7c478bd9Sstevel@tonic-gate attrs.trace_buf_size); 138*7c478bd9Sstevel@tonic-gate } 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate /* 142*7c478bd9Sstevel@tonic-gate * Deallocate the kernel's trace buffer. 143*7c478bd9Sstevel@tonic-gate */ 144*7c478bd9Sstevel@tonic-gate void 145*7c478bd9Sstevel@tonic-gate prbk_buffer_dealloc() 146*7c478bd9Sstevel@tonic-gate { 147*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate if (check_kernelmode(NULL)) 150*7c478bd9Sstevel@tonic-gate return; 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate err = tnfctl_buffer_dealloc(g_hndl); 153*7c478bd9Sstevel@tonic-gate switch (err) { 154*7c478bd9Sstevel@tonic-gate case (TNFCTL_ERR_NONE): 155*7c478bd9Sstevel@tonic-gate (void) printf(gettext("buffer deallocated\n")); 156*7c478bd9Sstevel@tonic-gate break; 157*7c478bd9Sstevel@tonic-gate case (TNFCTL_ERR_NOBUF): 158*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 159*7c478bd9Sstevel@tonic-gate gettext("There is no buffer to deallocate\n")); 160*7c478bd9Sstevel@tonic-gate break; 161*7c478bd9Sstevel@tonic-gate case (TNFCTL_ERR_BADDEALLOC): 162*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 163*7c478bd9Sstevel@tonic-gate gettext("Can't deallocate the buffer when " 164*7c478bd9Sstevel@tonic-gate "tracing is active\n")); 165*7c478bd9Sstevel@tonic-gate break; 166*7c478bd9Sstevel@tonic-gate default: 167*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 168*7c478bd9Sstevel@tonic-gate gettext("error in deleting buffer: %s\n"), 169*7c478bd9Sstevel@tonic-gate tnfctl_strerror(err)); 170*7c478bd9Sstevel@tonic-gate break; 171*7c478bd9Sstevel@tonic-gate } 172*7c478bd9Sstevel@tonic-gate } 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate /* 176*7c478bd9Sstevel@tonic-gate * Process filter routines. 177*7c478bd9Sstevel@tonic-gate * 178*7c478bd9Sstevel@tonic-gate * Process id sets are encoded as "pidlists": a linked list of pids. 179*7c478bd9Sstevel@tonic-gate * In a feeble attempt at encapsulation, the pidlist_t type is private 180*7c478bd9Sstevel@tonic-gate * to this file; prexgram.y manipulates pidlists only as opaque handles. 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate /* 184*7c478bd9Sstevel@tonic-gate * Add the given pid (new) to the pidlist (pl). 185*7c478bd9Sstevel@tonic-gate */ 186*7c478bd9Sstevel@tonic-gate void * 187*7c478bd9Sstevel@tonic-gate prbk_pidlist_add(void *pl, int new) 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate { 190*7c478bd9Sstevel@tonic-gate pidlist_t *npl = (pidlist_t *) malloc(sizeof (*npl)); 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate if (npl == NULL) { 193*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 194*7c478bd9Sstevel@tonic-gate gettext("Out of memory -- can't process pid %d\n"), 195*7c478bd9Sstevel@tonic-gate new); 196*7c478bd9Sstevel@tonic-gate return (pl); 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate npl->next = pl; 199*7c478bd9Sstevel@tonic-gate npl->pid = new; 200*7c478bd9Sstevel@tonic-gate return (npl); 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate /* 204*7c478bd9Sstevel@tonic-gate * Add the pids in the given pidlist to the process filter list. 205*7c478bd9Sstevel@tonic-gate * For each pid, check whether it's already in the filter list, 206*7c478bd9Sstevel@tonic-gate * and whether the process exists. 207*7c478bd9Sstevel@tonic-gate */ 208*7c478bd9Sstevel@tonic-gate void 209*7c478bd9Sstevel@tonic-gate prbk_pfilter_add(void *pl) 210*7c478bd9Sstevel@tonic-gate { 211*7c478bd9Sstevel@tonic-gate pidlist_t *ppl = (pidlist_t *) pl; 212*7c478bd9Sstevel@tonic-gate pidlist_t *tmp; 213*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate if (check_kernelmode(NULL)) 216*7c478bd9Sstevel@tonic-gate return; 217*7c478bd9Sstevel@tonic-gate while (ppl != NULL) { 218*7c478bd9Sstevel@tonic-gate err = tnfctl_filter_list_add(g_hndl, ppl->pid); 219*7c478bd9Sstevel@tonic-gate if (err) { 220*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Process %ld: %s\n"), 221*7c478bd9Sstevel@tonic-gate ppl->pid, tnfctl_strerror(err)); 222*7c478bd9Sstevel@tonic-gate } 223*7c478bd9Sstevel@tonic-gate tmp = ppl; 224*7c478bd9Sstevel@tonic-gate ppl = ppl->next; 225*7c478bd9Sstevel@tonic-gate free(tmp); 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate /* 230*7c478bd9Sstevel@tonic-gate * Drop the pids in the given pidlist from the process filter list. 231*7c478bd9Sstevel@tonic-gate * For each pid, complain if it's not in the process filter list; 232*7c478bd9Sstevel@tonic-gate * and if the process no longer exists (and hence has already implicitly 233*7c478bd9Sstevel@tonic-gate * been dropped from the process filter list), say so. 234*7c478bd9Sstevel@tonic-gate */ 235*7c478bd9Sstevel@tonic-gate void 236*7c478bd9Sstevel@tonic-gate prbk_pfilter_drop(void *pl) 237*7c478bd9Sstevel@tonic-gate { 238*7c478bd9Sstevel@tonic-gate pidlist_t *ppl = (pidlist_t *) pl; 239*7c478bd9Sstevel@tonic-gate pidlist_t *tmp; 240*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate if (check_kernelmode(NULL)) 243*7c478bd9Sstevel@tonic-gate return; 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate while (ppl != NULL) { 246*7c478bd9Sstevel@tonic-gate tmp = ppl; 247*7c478bd9Sstevel@tonic-gate err = tnfctl_filter_list_delete(g_hndl, tmp->pid); 248*7c478bd9Sstevel@tonic-gate switch (err) { 249*7c478bd9Sstevel@tonic-gate case (TNFCTL_ERR_NONE): 250*7c478bd9Sstevel@tonic-gate break; 251*7c478bd9Sstevel@tonic-gate case (TNFCTL_ERR_BADARG): 252*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 253*7c478bd9Sstevel@tonic-gate gettext("Process %ld is not being traced\n"), 254*7c478bd9Sstevel@tonic-gate tmp->pid); 255*7c478bd9Sstevel@tonic-gate break; 256*7c478bd9Sstevel@tonic-gate case (TNFCTL_ERR_NOPROCESS): 257*7c478bd9Sstevel@tonic-gate (void) printf(gettext("Process %ld has exited\n"), 258*7c478bd9Sstevel@tonic-gate tmp->pid); 259*7c478bd9Sstevel@tonic-gate break; 260*7c478bd9Sstevel@tonic-gate default: 261*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Process %ld: %s\n"), 262*7c478bd9Sstevel@tonic-gate tmp->pid, tnfctl_strerror(err)); 263*7c478bd9Sstevel@tonic-gate break; 264*7c478bd9Sstevel@tonic-gate } 265*7c478bd9Sstevel@tonic-gate ppl = ppl->next; 266*7c478bd9Sstevel@tonic-gate free(tmp); 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate } 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate /* 271*7c478bd9Sstevel@tonic-gate * Turn process filter mode on or off. The process filter is maintained 272*7c478bd9Sstevel@tonic-gate * even when process filtering is off, but has no effect: all processes 273*7c478bd9Sstevel@tonic-gate * are traced. 274*7c478bd9Sstevel@tonic-gate */ 275*7c478bd9Sstevel@tonic-gate void 276*7c478bd9Sstevel@tonic-gate prbk_set_pfilter_mode(boolean_t onoff) 277*7c478bd9Sstevel@tonic-gate { 278*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate if (check_kernelmode(NULL)) 281*7c478bd9Sstevel@tonic-gate return; 282*7c478bd9Sstevel@tonic-gate err = tnfctl_filter_state_set(g_hndl, onoff); 283*7c478bd9Sstevel@tonic-gate if (err) { 284*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("pfilter: %s\n"), 285*7c478bd9Sstevel@tonic-gate tnfctl_strerror(err)); 286*7c478bd9Sstevel@tonic-gate } 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate 290*7c478bd9Sstevel@tonic-gate /* 291*7c478bd9Sstevel@tonic-gate * Report whether process filter mode is currently on or off, and 292*7c478bd9Sstevel@tonic-gate * dump the current process filter set. 293*7c478bd9Sstevel@tonic-gate */ 294*7c478bd9Sstevel@tonic-gate void 295*7c478bd9Sstevel@tonic-gate prbk_show_pfilter_mode() 296*7c478bd9Sstevel@tonic-gate { 297*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 298*7c478bd9Sstevel@tonic-gate tnfctl_trace_attrs_t attrs; 299*7c478bd9Sstevel@tonic-gate pid_t *pids_p; 300*7c478bd9Sstevel@tonic-gate int i, pid_count; 301*7c478bd9Sstevel@tonic-gate pid_t *cur_pid; 302*7c478bd9Sstevel@tonic-gate 303*7c478bd9Sstevel@tonic-gate if (check_kernelmode(&attrs)) 304*7c478bd9Sstevel@tonic-gate return; 305*7c478bd9Sstevel@tonic-gate (void) printf(gettext("Process filtering is %s\n"), 306*7c478bd9Sstevel@tonic-gate attrs.filter_state ? "on" : "off"); 307*7c478bd9Sstevel@tonic-gate err = tnfctl_filter_list_get(g_hndl, &pids_p, &pid_count); 308*7c478bd9Sstevel@tonic-gate if (err) { 309*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 310*7c478bd9Sstevel@tonic-gate gettext("error in getting process filter list: %s\n"), 311*7c478bd9Sstevel@tonic-gate tnfctl_strerror(err)); 312*7c478bd9Sstevel@tonic-gate return; 313*7c478bd9Sstevel@tonic-gate } 314*7c478bd9Sstevel@tonic-gate (void) printf(gettext("Process filter set is ")); 315*7c478bd9Sstevel@tonic-gate if (pid_count == 0) 316*7c478bd9Sstevel@tonic-gate (void) printf("empty.\n"); 317*7c478bd9Sstevel@tonic-gate else { 318*7c478bd9Sstevel@tonic-gate (void) printf("{"); 319*7c478bd9Sstevel@tonic-gate cur_pid = pids_p; 320*7c478bd9Sstevel@tonic-gate for (i = 0; i < pid_count; i++, cur_pid++) { 321*7c478bd9Sstevel@tonic-gate (void) printf("%ld%s", *cur_pid, 322*7c478bd9Sstevel@tonic-gate (i != (pid_count - 1)) ? ", " : "}\n"); 323*7c478bd9Sstevel@tonic-gate } 324*7c478bd9Sstevel@tonic-gate } 325*7c478bd9Sstevel@tonic-gate } 326*7c478bd9Sstevel@tonic-gate 327*7c478bd9Sstevel@tonic-gate /* 328*7c478bd9Sstevel@tonic-gate * Check for process filtering on with empty pid filter. 329*7c478bd9Sstevel@tonic-gate */ 330*7c478bd9Sstevel@tonic-gate void 331*7c478bd9Sstevel@tonic-gate prbk_warn_pfilter_empty(void) 332*7c478bd9Sstevel@tonic-gate { 333*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 334*7c478bd9Sstevel@tonic-gate pid_t *pids_p; 335*7c478bd9Sstevel@tonic-gate int pid_count; 336*7c478bd9Sstevel@tonic-gate tnfctl_trace_attrs_t attrs; 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate if (check_kernelmode(&attrs)) 339*7c478bd9Sstevel@tonic-gate return; 340*7c478bd9Sstevel@tonic-gate if (attrs.filter_state) { 341*7c478bd9Sstevel@tonic-gate err = tnfctl_filter_list_get(g_hndl, &pids_p, &pid_count); 342*7c478bd9Sstevel@tonic-gate if (err) { 343*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 344*7c478bd9Sstevel@tonic-gate gettext("error in getting process filter list: %s\n"), 345*7c478bd9Sstevel@tonic-gate tnfctl_strerror(err)); 346*7c478bd9Sstevel@tonic-gate return; 347*7c478bd9Sstevel@tonic-gate } 348*7c478bd9Sstevel@tonic-gate if (!pid_count) 349*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 350*7c478bd9Sstevel@tonic-gate gettext("Warning: Process filtering on, \ 351*7c478bd9Sstevel@tonic-gate but pid filter list is empty\n")); 352*7c478bd9Sstevel@tonic-gate } 353*7c478bd9Sstevel@tonic-gate } 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate /* 357*7c478bd9Sstevel@tonic-gate * Turn kernel tracing on or off. 358*7c478bd9Sstevel@tonic-gate */ 359*7c478bd9Sstevel@tonic-gate void 360*7c478bd9Sstevel@tonic-gate prbk_set_tracing(boolean_t onoff) 361*7c478bd9Sstevel@tonic-gate { 362*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t err; 363*7c478bd9Sstevel@tonic-gate 364*7c478bd9Sstevel@tonic-gate if (check_kernelmode(NULL)) 365*7c478bd9Sstevel@tonic-gate return; 366*7c478bd9Sstevel@tonic-gate 367*7c478bd9Sstevel@tonic-gate err = tnfctl_trace_state_set(g_hndl, onoff); 368*7c478bd9Sstevel@tonic-gate if (err) { 369*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 370*7c478bd9Sstevel@tonic-gate gettext("error in setting tracing state: %s\n"), 371*7c478bd9Sstevel@tonic-gate tnfctl_strerror(err)); 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate } 374*7c478bd9Sstevel@tonic-gate 375*7c478bd9Sstevel@tonic-gate /* 376*7c478bd9Sstevel@tonic-gate * Show whether kernel tracing is currently on or off. 377*7c478bd9Sstevel@tonic-gate */ 378*7c478bd9Sstevel@tonic-gate void 379*7c478bd9Sstevel@tonic-gate prbk_show_tracing() 380*7c478bd9Sstevel@tonic-gate { 381*7c478bd9Sstevel@tonic-gate tnfctl_trace_attrs_t attrs; 382*7c478bd9Sstevel@tonic-gate 383*7c478bd9Sstevel@tonic-gate if (check_kernelmode(&attrs)) 384*7c478bd9Sstevel@tonic-gate return; 385*7c478bd9Sstevel@tonic-gate (void) printf(gettext("Tracing is %s\n"), 386*7c478bd9Sstevel@tonic-gate attrs.trace_state ? "on" : "off"); 387*7c478bd9Sstevel@tonic-gate } 388