dt_proc.c (238979) | dt_proc.c (249367) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 11 unchanged lines hidden (view full) --- 20 */ 21 22/* 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 11 unchanged lines hidden (view full) --- 20 */ 21 22/* 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27/* |
28 * Copyright (c) 2012 by Delphix. All rights reserved. 29 */ 30 31/* |
|
28 * DTrace Process Control 29 * 30 * This file provides a set of routines that permit libdtrace and its clients 31 * to create and grab process handles using libproc, and to share these handles 32 * between library mechanisms that need libproc access, such as ustack(), and 33 * client mechanisms that need libproc access, such as dtrace(1M) -c and -p. 34 * The library provides several mechanisms in the libproc control layer: 35 * --- 462 unchanged lines hidden (view full) --- 498 * libdtrace client wishes to exit or abort our wait, SIGCANCEL can be used. 499 */ 500static void * 501dt_proc_control(void *arg) 502{ 503 dt_proc_control_data_t *datap = arg; 504 dtrace_hdl_t *dtp = datap->dpcd_hdl; 505 dt_proc_t *dpr = datap->dpcd_proc; | 32 * DTrace Process Control 33 * 34 * This file provides a set of routines that permit libdtrace and its clients 35 * to create and grab process handles using libproc, and to share these handles 36 * between library mechanisms that need libproc access, such as ustack(), and 37 * client mechanisms that need libproc access, such as dtrace(1M) -c and -p. 38 * The library provides several mechanisms in the libproc control layer: 39 * --- 462 unchanged lines hidden (view full) --- 502 * libdtrace client wishes to exit or abort our wait, SIGCANCEL can be used. 503 */ 504static void * 505dt_proc_control(void *arg) 506{ 507 dt_proc_control_data_t *datap = arg; 508 dtrace_hdl_t *dtp = datap->dpcd_hdl; 509 dt_proc_t *dpr = datap->dpcd_proc; |
506 dt_proc_hash_t *dph = dpr->dpr_hdl->dt_procs; | 510 dt_proc_hash_t *dph = dtp->dt_procs; |
507 struct ps_prochandle *P = dpr->dpr_proc; 508 int pid = dpr->dpr_pid; 509 510#if defined(sun) 511 int pfd = Pctlfd(P); 512 513 const long wstop = PCWSTOP; 514#endif --- 444 unchanged lines hidden (view full) --- 959 960 if ((dpr = dt_zalloc(dtp, sizeof (dt_proc_t))) == NULL) 961 return (NULL); /* errno is set for us */ 962 963 (void) pthread_mutex_init(&dpr->dpr_lock, NULL); 964 (void) pthread_cond_init(&dpr->dpr_cv, NULL); 965 966#if defined(sun) | 511 struct ps_prochandle *P = dpr->dpr_proc; 512 int pid = dpr->dpr_pid; 513 514#if defined(sun) 515 int pfd = Pctlfd(P); 516 517 const long wstop = PCWSTOP; 518#endif --- 444 unchanged lines hidden (view full) --- 963 964 if ((dpr = dt_zalloc(dtp, sizeof (dt_proc_t))) == NULL) 965 return (NULL); /* errno is set for us */ 966 967 (void) pthread_mutex_init(&dpr->dpr_lock, NULL); 968 (void) pthread_cond_init(&dpr->dpr_cv, NULL); 969 970#if defined(sun) |
967 if ((dpr->dpr_proc = Pcreate(file, argv, &err, NULL, 0)) == NULL) { | 971 dpr->dpr_proc = Pxcreate(file, argv, dtp->dt_proc_env, &err, NULL, 0); 972 if (dpr->dpr_proc == NULL) { |
968#else 969 if ((err = proc_create(file, argv, pcf, child_arg, 970 &dpr->dpr_proc)) != 0) { 971#endif 972 return (dt_proc_error(dtp, dpr, 973 "failed to execute %s: %s\n", file, Pcreate_error(err))); 974 } 975 --- 159 unchanged lines hidden (view full) --- 1135dt_proc_unlock(dtrace_hdl_t *dtp, struct ps_prochandle *P) 1136{ 1137 dt_proc_t *dpr = dt_proc_lookup(dtp, P, B_FALSE); 1138 int err = pthread_mutex_unlock(&dpr->dpr_lock); 1139 assert(err == 0); /* check for unheld lock */ 1140} 1141 1142void | 973#else 974 if ((err = proc_create(file, argv, pcf, child_arg, 975 &dpr->dpr_proc)) != 0) { 976#endif 977 return (dt_proc_error(dtp, dpr, 978 "failed to execute %s: %s\n", file, Pcreate_error(err))); 979 } 980 --- 159 unchanged lines hidden (view full) --- 1140dt_proc_unlock(dtrace_hdl_t *dtp, struct ps_prochandle *P) 1141{ 1142 dt_proc_t *dpr = dt_proc_lookup(dtp, P, B_FALSE); 1143 int err = pthread_mutex_unlock(&dpr->dpr_lock); 1144 assert(err == 0); /* check for unheld lock */ 1145} 1146 1147void |
1143dt_proc_hash_create(dtrace_hdl_t *dtp) | 1148dt_proc_init(dtrace_hdl_t *dtp) |
1144{ | 1149{ |
1150 extern char **environ; 1151 static char *envdef[] = { 1152 "LD_NOLAZYLOAD=1", /* linker lazy loading hides funcs */ 1153 NULL 1154 }; 1155 char **p; 1156 int i; 1157 |
|
1145 if ((dtp->dt_procs = dt_zalloc(dtp, sizeof (dt_proc_hash_t) + | 1158 if ((dtp->dt_procs = dt_zalloc(dtp, sizeof (dt_proc_hash_t) + |
1146 sizeof (dt_proc_t *) * _dtrace_pidbuckets - 1)) != NULL) { | 1159 sizeof (dt_proc_t *) * _dtrace_pidbuckets - 1)) == NULL) 1160 return; |
1147 | 1161 |
1148 (void) pthread_mutex_init(&dtp->dt_procs->dph_lock, NULL); 1149 (void) pthread_cond_init(&dtp->dt_procs->dph_cv, NULL); | 1162 (void) pthread_mutex_init(&dtp->dt_procs->dph_lock, NULL); 1163 (void) pthread_cond_init(&dtp->dt_procs->dph_cv, NULL); |
1150 | 1164 |
1151 dtp->dt_procs->dph_hashlen = _dtrace_pidbuckets; 1152 dtp->dt_procs->dph_lrulim = _dtrace_pidlrulim; | 1165 dtp->dt_procs->dph_hashlen = _dtrace_pidbuckets; 1166 dtp->dt_procs->dph_lrulim = _dtrace_pidlrulim; 1167 1168 1169 /* 1170 * Count how big our environment needs to be. 1171 */ 1172 for (i = 1, p = environ; *p != NULL; i++, p++) 1173 continue; 1174 for (p = envdef; *p != NULL; i++, p++) 1175 continue; 1176 1177 if ((dtp->dt_proc_env = dt_zalloc(dtp, sizeof (char *) * i)) == NULL) 1178 return; 1179 1180 for (i = 0, p = environ; *p != NULL; i++, p++) { 1181 if ((dtp->dt_proc_env[i] = strdup(*p)) == NULL) 1182 goto err; |
1153 } | 1183 } |
1184 for (p = envdef; *p != NULL; i++, p++) { 1185 if ((dtp->dt_proc_env[i] = strdup(*p)) == NULL) 1186 goto err; 1187 } 1188 1189 return; 1190 1191err: 1192 while (--i != 0) { 1193 dt_free(dtp, dtp->dt_proc_env[i]); 1194 } 1195 dt_free(dtp, dtp->dt_proc_env); 1196 dtp->dt_proc_env = NULL; |
|
1154} 1155 1156void | 1197} 1198 1199void |
1157dt_proc_hash_destroy(dtrace_hdl_t *dtp) | 1200dt_proc_fini(dtrace_hdl_t *dtp) |
1158{ 1159 dt_proc_hash_t *dph = dtp->dt_procs; 1160 dt_proc_t *dpr; | 1201{ 1202 dt_proc_hash_t *dph = dtp->dt_procs; 1203 dt_proc_t *dpr; |
1204 char **p; |
|
1161 1162 while ((dpr = dt_list_next(&dph->dph_lrulist)) != NULL) 1163 dt_proc_destroy(dtp, dpr->dpr_proc); 1164 1165 dtp->dt_procs = NULL; 1166 dt_free(dtp, dph); | 1205 1206 while ((dpr = dt_list_next(&dph->dph_lrulist)) != NULL) 1207 dt_proc_destroy(dtp, dpr->dpr_proc); 1208 1209 dtp->dt_procs = NULL; 1210 dt_free(dtp, dph); |
1211 1212 for (p = dtp->dt_proc_env; *p != NULL; p++) 1213 dt_free(dtp, *p); 1214 1215 dt_free(dtp, dtp->dt_proc_env); 1216 dtp->dt_proc_env = NULL; |
|
1167} 1168 1169struct ps_prochandle * 1170dtrace_proc_create(dtrace_hdl_t *dtp, const char *file, char *const *argv, 1171 proc_child_func *pcf, void *child_arg) 1172{ 1173 dt_ident_t *idp = dt_idhash_lookup(dtp->dt_macros, "target"); 1174 struct ps_prochandle *P = dt_proc_create(dtp, file, argv, pcf, child_arg); --- 35 unchanged lines hidden --- | 1217} 1218 1219struct ps_prochandle * 1220dtrace_proc_create(dtrace_hdl_t *dtp, const char *file, char *const *argv, 1221 proc_child_func *pcf, void *child_arg) 1222{ 1223 dt_ident_t *idp = dt_idhash_lookup(dtp->dt_macros, "target"); 1224 struct ps_prochandle *P = dt_proc_create(dtp, file, argv, pcf, child_arg); --- 35 unchanged lines hidden --- |