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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #pragma ident "%Z%%M% %I% %E% SMI"
27
28 #include <stdio.h>
29 #include <stdio_ext.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <ctype.h>
33 #include <fcntl.h>
34 #include <string.h>
35 #include <signal.h>
36 #include <stddef.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <libproc.h>
40
41 /* evil knowledge of libc internals */
42 #include "../../../lib/libc/inc/thr_uberdata.h"
43
44 #define MAX_SYMNAMLEN 1024 /* Recommended max symbol name length */
45
46 static char *sigflags(int, int);
47 static int look(char *);
48 static void perr(char *);
49 static int usage(void);
50 static uintptr_t deinterpose(int, void *, psinfo_t *, struct sigaction *);
51
52 static char *command;
53 static char *procname;
54 static int all_flag = 0;
55 static int lookuphandlers_flag = 1;
56
57 int
58 main(int argc, char **argv)
59 {
155 lwp_iter(void *cd, const lwpstatus_t *lwpstatus)
156 {
157 sigset_t *ssp = cd;
158
159 ssp->__sigbits[0] &= lwpstatus->pr_lwphold.__sigbits[0];
160 ssp->__sigbits[1] &= lwpstatus->pr_lwphold.__sigbits[1];
161 ssp->__sigbits[2] &= lwpstatus->pr_lwphold.__sigbits[2];
162 ssp->__sigbits[3] &= lwpstatus->pr_lwphold.__sigbits[3];
163
164 /*
165 * Return non-zero to terminate the iteration
166 * if the sigmask has become all zeros.
167 */
168 return ((ssp->__sigbits[0] | ssp->__sigbits[1] |
169 ssp->__sigbits[2] | ssp->__sigbits[3]) == 0);
170 }
171
172 static int
173 look(char *arg)
174 {
175 char pathname[100];
176 struct stat statb;
177 int fd = -1;
178 int sig, gcode;
179 sigset_t holdmask;
180 int maxsig;
181 struct sigaction *action = NULL;
182 psinfo_t psinfo;
183 const psinfo_t *psinfop;
184 struct ps_prochandle *Pr = NULL;
185 uintptr_t uberaddr;
186 uintptr_t aharraddr;
187 uintptr_t intfnaddr;
188 size_t aharrlen;
189 void *aharr = NULL;
190 int error = 1;
191
192 procname = arg; /* for perr() */
193 if ((Pr = proc_arg_grab(arg, PR_ARG_PIDS, PGRAB_RDONLY|PGRAB_FORCE,
194 &gcode)) == NULL || (psinfop = Ppsinfo(Pr)) == NULL) {
195 (void) fprintf(stderr, "%s: cannot examine %s: %s\n",
196 command, arg, Pgrab_error(gcode));
197 goto look_error;
198 }
199 (void) memcpy(&psinfo, psinfop, sizeof (psinfo_t));
200 proc_unctrl_psinfo(&psinfo);
201
202 (void) sprintf(pathname, "/proc/%d/sigact", (int)psinfo.pr_pid);
203 if ((fd = open(pathname, O_RDONLY)) < 0) {
204 perr("open sigact");
205 goto look_error;
206 }
207
208 if (fstat(fd, &statb) != 0) {
209 perr("fstat sigact");
210 goto look_error;
211 }
212 maxsig = statb.st_size / sizeof (struct sigaction);
213 action = malloc(maxsig * sizeof (struct sigaction));
214 if (action == NULL) {
215 (void) fprintf(stderr,
216 "%s: cannot malloc() space for %d sigaction structures\n",
217 command, maxsig);
218 goto look_error;
219 }
220 if (read(fd, (char *)action, maxsig * sizeof (struct sigaction)) !=
221 maxsig * sizeof (struct sigaction)) {
222 perr("read sigact");
|
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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
25 */
26
27 #include <stdio.h>
28 #include <stdio_ext.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <ctype.h>
32 #include <fcntl.h>
33 #include <string.h>
34 #include <signal.h>
35 #include <stddef.h>
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <libproc.h>
39 #include "ptools_common.h"
40
41 /* evil knowledge of libc internals */
42 #include "../../../lib/libc/inc/thr_uberdata.h"
43
44 #define MAX_SYMNAMLEN 1024 /* Recommended max symbol name length */
45
46 static char *sigflags(int, int);
47 static int look(char *);
48 static void perr(char *);
49 static int usage(void);
50 static uintptr_t deinterpose(int, void *, psinfo_t *, struct sigaction *);
51
52 static char *command;
53 static char *procname;
54 static int all_flag = 0;
55 static int lookuphandlers_flag = 1;
56
57 int
58 main(int argc, char **argv)
59 {
155 lwp_iter(void *cd, const lwpstatus_t *lwpstatus)
156 {
157 sigset_t *ssp = cd;
158
159 ssp->__sigbits[0] &= lwpstatus->pr_lwphold.__sigbits[0];
160 ssp->__sigbits[1] &= lwpstatus->pr_lwphold.__sigbits[1];
161 ssp->__sigbits[2] &= lwpstatus->pr_lwphold.__sigbits[2];
162 ssp->__sigbits[3] &= lwpstatus->pr_lwphold.__sigbits[3];
163
164 /*
165 * Return non-zero to terminate the iteration
166 * if the sigmask has become all zeros.
167 */
168 return ((ssp->__sigbits[0] | ssp->__sigbits[1] |
169 ssp->__sigbits[2] | ssp->__sigbits[3]) == 0);
170 }
171
172 static int
173 look(char *arg)
174 {
175 char pathname[PATH_MAX];
176 struct stat statb;
177 int fd = -1;
178 int sig, gcode;
179 sigset_t holdmask;
180 int maxsig;
181 struct sigaction *action = NULL;
182 psinfo_t psinfo;
183 const psinfo_t *psinfop;
184 struct ps_prochandle *Pr = NULL;
185 uintptr_t uberaddr;
186 uintptr_t aharraddr;
187 uintptr_t intfnaddr;
188 size_t aharrlen;
189 void *aharr = NULL;
190 int error = 1;
191
192 procname = arg; /* for perr() */
193 if ((Pr = proc_arg_grab(arg, PR_ARG_PIDS, PGRAB_RDONLY|PGRAB_FORCE,
194 &gcode)) == NULL || (psinfop = Ppsinfo(Pr)) == NULL) {
195 (void) fprintf(stderr, "%s: cannot examine %s: %s\n",
196 command, arg, Pgrab_error(gcode));
197 goto look_error;
198 }
199 (void) memcpy(&psinfo, psinfop, sizeof (psinfo_t));
200 proc_unctrl_psinfo(&psinfo);
201
202 (void) proc_snprintf(pathname, sizeof (pathname), "/proc/%d/sigact",
203 (int)psinfo.pr_pid);
204 if ((fd = open(pathname, O_RDONLY)) < 0) {
205 perr("open sigact");
206 goto look_error;
207 }
208
209 if (fstat(fd, &statb) != 0) {
210 perr("fstat sigact");
211 goto look_error;
212 }
213 maxsig = statb.st_size / sizeof (struct sigaction);
214 action = malloc(maxsig * sizeof (struct sigaction));
215 if (action == NULL) {
216 (void) fprintf(stderr,
217 "%s: cannot malloc() space for %d sigaction structures\n",
218 command, maxsig);
219 goto look_error;
220 }
221 if (read(fd, (char *)action, maxsig * sizeof (struct sigaction)) !=
222 maxsig * sizeof (struct sigaction)) {
223 perr("read sigact");
|