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.
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.
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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <sys/types.h>
38 static int start(char *);
39 static int lwpstart(int *, const lwpstatus_t
*, const lwpsinfo_t
*);
42 static const char *lwps
;
43 static struct ps_prochandle
*P
;
46 main(int argc
, char **argv
)
50 if ((command
= strrchr(argv
[0], '/')) != NULL
)
56 (void) fprintf(stderr
, "usage:\t%s pid[/lwps] ...\n", command
);
57 (void) fprintf(stderr
, " (set stopped processes or lwps "
74 if ((P
= proc_arg_xgrab(arg
, NULL
, PR_ARG_PIDS
, PGRAB_FORCE
|
75 PGRAB_RETAIN
| PGRAB_NOSTOP
, &gcode
, &lwps
)) == NULL
) {
76 (void) fprintf(stderr
, "%s: cannot control %s: %s\n",
77 command
, arg
, Pgrab_error(gcode
));
82 * If the victim is stopped because of a job control signal, we
83 * need to send it SIGCONT to get it moving again, otherwise
84 * the agent will not be able to run, and so will not be able to
87 (void) kill(Pstatus(P
)->pr_pid
, SIGCONT
);
90 * if the agent already exists, Pcreate_agent will adopt the
91 * extant agent so that we can destroy it
93 if (Pstatus(P
)->pr_lwp
.pr_flags
& PR_AGENT
) {
94 if (Pcreate_agent(P
) != 0) {
95 (void) fprintf(stderr
,
96 "%s: cannot remove agent from %s: %s\n",
97 command
, arg
, strerror(errno
));
108 * The user provided an lwp specification. Let's consider the
109 * lwp specification as a mask. We iterate over all lwps in the
110 * process and set running every lwp, which matches the mask.
111 * If there is no lwp matching the mask or an error occured
112 * during the iteration, set the return code to 1 as indication
113 * of an error. We need to unset run-on-last-close flag,
114 * otherwise *all* lwps could be set running after detaching
115 * from the process and not only lwps, which were selected.
119 (void) Punsetflags(P
, PR_RLC
);
120 (void) Plwp_iter_all(P
, (proc_lwp_all_f
*)lwpstart
, &lwpcount
);
123 (void) fprintf(stderr
, "%s: cannot control %s:"
124 " no matching LWPs found\n", command
, arg
);
126 } else if (lwpcount
== -1)
129 (void) Psetrun(P
, 0, 0); /* Set the process running. */
133 * Prelease could change the tracing flags or leave the victim hung
134 * so we free the handle by hand.
142 lwpstart(int *lwpcount
, const lwpstatus_t
*status
, const lwpsinfo_t
*info
)
144 struct ps_lwphandle
*L
;
147 if (proc_lwp_in_set(lwps
, info
->pr_lwpid
)) {
149 * There is a race between the callback from the iterator and
150 * grabbing of the lwp. If the lwp has already exited, Lgrab
151 * will return the error code G_NOPROC. It's not a real error,
152 * only if there is no lwp matching the specification.
154 if ((L
= Lgrab(P
, info
->pr_lwpid
, &gcode
)) != NULL
) {
155 (void) Lsetrun(L
, 0, 0);
159 } else if (gcode
!= G_NOPROC
) {
160 (void) fprintf(stderr
, "%s: cannot control %d/%d: %s\n",
161 command
, (int)Pstatus(P
)->pr_pid
,
162 (int)info
->pr_lwpid
, Lgrab_error(gcode
));