diff options
Diffstat (limited to 'usr/src/lib')
| -rw-r--r-- | usr/src/lib/libcpc/common/libcpc.c | 25 | ||||
| -rw-r--r-- | usr/src/lib/libcpc/common/libcpc.h | 4 | ||||
| -rw-r--r-- | usr/src/lib/libcpc/common/mapfile-vers | 1 | ||||
| -rw-r--r-- | usr/src/lib/libpctx/common/libpctx.c | 29 | ||||
| -rw-r--r-- | usr/src/lib/libpctx/common/libpctx.h | 11 | ||||
| -rw-r--r-- | usr/src/lib/libpctx/common/mapfile-vers | 1 |
6 files changed, 58 insertions, 13 deletions
diff --git a/usr/src/lib/libcpc/common/libcpc.c b/usr/src/lib/libcpc/common/libcpc.c index 5bdba39fda..9f4f6ac848 100644 --- a/usr/src/lib/libcpc/common/libcpc.c +++ b/usr/src/lib/libcpc/common/libcpc.c @@ -168,6 +168,23 @@ cpc_close(cpc_t *cpc) return (0); } +/* + * Terminate everything that runs in pctx_run + */ +void +cpc_terminate(cpc_t *cpc) +{ + cpc_set_t *csp; + int sigblocked; + + sigblocked = cpc_lock(cpc); + for (csp = cpc->cpc_sets; csp != NULL; csp = csp->cs_next) { + if (csp->cs_pctx != NULL) + pctx_terminate(csp->cs_pctx); + } + cpc_unlock(cpc, sigblocked); +} + cpc_set_t * cpc_set_create(cpc_t *cpc) { @@ -224,6 +241,14 @@ cpc_set_destroy(cpc_t *cpc, cpc_set_t *set) if (csp->cs_state != CS_UNBOUND) (void) cpc_unbind(cpc, csp); + /* + * Detach from the process + */ + if (csp->cs_pctx != NULL) { + pctx_release(csp->cs_pctx); + csp->cs_pctx = NULL; + } + for (req = csp->cs_request; req != NULL; req = next) { next = req->cr_next; diff --git a/usr/src/lib/libcpc/common/libcpc.h b/usr/src/lib/libcpc/common/libcpc.h index 384474a76c..73627345a0 100644 --- a/usr/src/lib/libcpc/common/libcpc.h +++ b/usr/src/lib/libcpc/common/libcpc.h @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -163,6 +163,8 @@ extern void cpc_walk_attrs(cpc_t *cpc, void *arg, extern int cpc_enable(cpc_t *cpc); extern int cpc_disable(cpc_t *cpc); +extern void cpc_terminate(cpc_t *); + #if defined(__sparc) || defined(__i386) /* diff --git a/usr/src/lib/libcpc/common/mapfile-vers b/usr/src/lib/libcpc/common/mapfile-vers index 91f1689c9f..e577fc7c5e 100644 --- a/usr/src/lib/libcpc/common/mapfile-vers +++ b/usr/src/lib/libcpc/common/mapfile-vers @@ -83,6 +83,7 @@ SUNW_1.2 { SUNWprivate_1.1 { global: SUNWprivate_1.1; + cpc_terminate; local: *; }; diff --git a/usr/src/lib/libpctx/common/libpctx.c b/usr/src/lib/libpctx/common/libpctx.c index 9c28fb9b9b..f17e238322 100644 --- a/usr/src/lib/libpctx/common/libpctx.c +++ b/usr/src/lib/libpctx/common/libpctx.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * This file contains a set of generic routines for periodically * sampling the state of another process, or tree of processes. @@ -66,6 +64,7 @@ struct __pctx { int verbose; int created; int sigblocked; + int terminate; sigset_t savedset; cpc_t *cpc; }; @@ -108,6 +107,7 @@ pctx_create( pctx = calloc(1, sizeof (*pctx)); pctx->uarg = arg; pctx->verbose = verbose; + pctx->terminate = 0; pctx->errfn = errfn ? errfn : pctx_default_errfn; if ((pctx->Pr = Pcreate(filename, argv, &err, 0, 0)) == NULL) { @@ -487,6 +487,7 @@ pctx_release(pctx_t *pctx) Prelease(pctx->Pr, PRELEASE_CLEAR); pctx->Pr = NULL; } + pctx_free(pctx); bzero(pctx, sizeof (*pctx)); free(pctx); @@ -577,7 +578,7 @@ pctx_run( * exited successfully or the number of time samples has expired. * Otherwise, if an error has occurred, running becomes -1. */ - while (running == 1) { + while (running == 1 && !pctx->terminate) { if (Psetrun(pctx->Pr, 0, 0) != 0) { if (pctx->verbose) @@ -609,10 +610,13 @@ pctx_run( if (nsamples != 1) nsamples--; } - } while (mswait == 0); + } while (mswait == 0 && !pctx->terminate); } - (void) Pwait(pctx->Pr, mswait); + if (pctx->terminate) + goto bailout; + else + (void) Pwait(pctx->Pr, mswait); checkstate: switch (pstate = Pstate(pctx->Pr)) { @@ -854,6 +858,9 @@ checkstate: bailout: (void) signal(SIGCHLD, sigsaved); + if (pctx->terminate) + return (0); + switch (running) { case 0: return (0); @@ -885,6 +892,7 @@ __pctx_cpc(pctx_t *pctx, cpc_t *cpc, * We store the last cpc_t used by libpctx, so that when this pctx is * destroyed, libpctx can notify libcpc. */ + if (pctx->cpc != NULL && pctx->cpc != cpc && pctx_cpc_callback != NULL) (*pctx_cpc_callback)(pctx->cpc, pctx); pctx->cpc = cpc; @@ -993,3 +1001,12 @@ __pctx_cpc_register_callback(void (*arg)(struct __cpc *, struct __pctx *)) { pctx_cpc_callback = arg; } + +/* + * Tell pctx_run to bail out immediately + */ +void +pctx_terminate(struct __pctx *pctx) +{ + pctx->terminate = 1; +} diff --git a/usr/src/lib/libpctx/common/libpctx.h b/usr/src/lib/libpctx/common/libpctx.h index 10d0fb7c7e..7cd9ffff91 100644 --- a/usr/src/lib/libpctx/common/libpctx.h +++ b/usr/src/lib/libpctx/common/libpctx.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,15 +19,13 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _LIBPCTX_H #define _LIBPCTX_H -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/types.h> #include <fcntl.h> #include <stdarg.h> @@ -67,6 +64,8 @@ typedef int pctx_init_lwpfn_t(pctx_t *, pid_t, id_t, void *); typedef int pctx_fini_lwpfn_t(pctx_t *, pid_t, id_t, void *); typedef int pctx_sysc_lwp_exitfn_t(pctx_t *, pid_t, id_t, void *); +extern void pctx_terminate(pctx_t *); + typedef enum { PCTX_NULL_EVENT = 0, PCTX_SYSC_EXEC_EVENT, diff --git a/usr/src/lib/libpctx/common/mapfile-vers b/usr/src/lib/libpctx/common/mapfile-vers index 1b296817d4..e316020c8b 100644 --- a/usr/src/lib/libpctx/common/mapfile-vers +++ b/usr/src/lib/libpctx/common/mapfile-vers @@ -50,6 +50,7 @@ SUNWprivate_1.1 { global: __pctx_cpc; __pctx_cpc_register_callback; + pctx_terminate; local: *; }; |
