1 /*
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
31 #include <stdlib.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <unistd.h>
35 #include <signal.h>
36 #include <dirent.h>
37 #include <ctype.h>
38 #include <sys/types.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <sys/stat.h>
42 #include <sys/un.h>
43
44 #include "sun_tools_attach_VirtualMachineImpl.h"
45
46 #define RESTARTABLE(_cmd, _result) do { \
47 do { \
48 _result = _cmd; \
49 } while((_result == -1) && (errno == EINTR)); \
50 } while(0)
51
52 /*
53 * Defines a callback that is invoked for each process
54 */
55 typedef void (*ProcessCallback)(const pid_t pid, void* user_data);
56
57 /*
58 * Invokes the callback function for each process
59 */
60 static void forEachProcess(ProcessCallback f, void* user_data) {
61 DIR* dir;
62 struct dirent* ptr;
63
64 /*
65 * To locate the children we scan /proc looking for files that have a
66 * position integer as a filename.
67 */
68 if ((dir = opendir("/proc")) == NULL) {
69 return;
70 }
|
1 /*
2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
31 #include <stdlib.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <unistd.h>
35 #include <signal.h>
36 #include <dirent.h>
37 #include <ctype.h>
38 #include <sys/types.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <sys/stat.h>
42 #include <sys/un.h>
43
44 #include "sun_tools_attach_VirtualMachineImpl.h"
45
46 #define RESTARTABLE(_cmd, _result) do { \
47 do { \
48 _result = _cmd; \
49 } while((_result == -1) && (errno == EINTR)); \
50 } while(0)
51
52 /*
53 * Declare library specific JNI_Onload entry if static build
54 */
55 DEF_STATIC_JNI_OnLoad
56
57 /*
58 * Defines a callback that is invoked for each process
59 */
60 typedef void (*ProcessCallback)(const pid_t pid, void* user_data);
61
62 /*
63 * Invokes the callback function for each process
64 */
65 static void forEachProcess(ProcessCallback f, void* user_data) {
66 DIR* dir;
67 struct dirent* ptr;
68
69 /*
70 * To locate the children we scan /proc looking for files that have a
71 * position integer as a filename.
72 */
73 if ((dir = opendir("/proc")) == NULL) {
74 return;
75 }
|