author | rriggs |
Thu, 16 Mar 2017 15:40:38 -0400 | |
changeset 44269 | 762b2df849b3 |
parent 40206 | 8870e08b50bc |
child 45926 | 43879a69df50 |
permissions | -rw-r--r-- |
30899 | 1 |
/* |
44269
762b2df849b3
8176272: (process) ProcessHandle::onExit fails to wait for non-child process
rriggs
parents:
40206
diff
changeset
|
2 |
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
30899 | 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 |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#include "jni.h" |
|
27 |
#include "jni_util.h" |
|
28 |
#include "java_lang_ProcessHandleImpl.h" |
|
29 |
#include "java_lang_ProcessHandleImpl_Info.h" |
|
30 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
31 |
#include "ProcessHandleImpl_unix.h" |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
32 |
|
30899 | 33 |
|
34 |
#include <stdio.h> |
|
35 |
#include <errno.h> |
|
36 |
#include <fcntl.h> |
|
37 |
#include <signal.h> |
|
38 |
#include <stdlib.h> |
|
39 |
#include <unistd.h> |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
40 |
#include <string.h> |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
41 |
#include <dirent.h> |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
42 |
#include <ctype.h> |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
43 |
#include <limits.h> |
30899 | 44 |
#include <sys/types.h> |
45 |
#include <sys/stat.h> |
|
46 |
#include <sys/wait.h> |
|
47 |
||
40182
1e16a8fd76ba
8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents:
32209
diff
changeset
|
48 |
/* For POSIX-compliant getpwuid_r on Solaris */ |
1e16a8fd76ba
8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents:
32209
diff
changeset
|
49 |
#if defined(__solaris__) |
1e16a8fd76ba
8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents:
32209
diff
changeset
|
50 |
#define _POSIX_PTHREAD_SEMANTICS |
1e16a8fd76ba
8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents:
32209
diff
changeset
|
51 |
#endif |
1e16a8fd76ba
8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents:
32209
diff
changeset
|
52 |
#include <pwd.h> |
1e16a8fd76ba
8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
dcubed
parents:
32209
diff
changeset
|
53 |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
54 |
#ifdef _AIX |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
55 |
#include <sys/procfs.h> |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
56 |
#endif |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
57 |
#ifdef __solaris__ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
58 |
#include <procfs.h> |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
59 |
#endif |
30899 | 60 |
|
61 |
/** |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
62 |
* This file contains the implementation of the native ProcessHandleImpl |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
63 |
* functions which are common to all Unix variants. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
64 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
65 |
* The currently supported Unix variants are Solaris, Linux, MaxOS X and AIX. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
66 |
* The various similarities and differences between these systems make it hard |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
67 |
* to find a clear boundary between platform specific and shared code. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
68 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
69 |
* In order to ease code sharing between the platforms while still keeping the |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
70 |
* code as clean as possible (i.e. free of preprocessor macros) we use the |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
71 |
* following source code layout (remember that ProcessHandleImpl_unix.c will |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
72 |
* be compiled on EVERY Unix platform while ProcessHandleImpl_<os>.c will be |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
73 |
* only compiled on the specific OS): |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
74 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
75 |
* - all the JNI wrappers for the ProcessHandleImpl functions go into this file |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
76 |
* - if their implementation is common on ALL the supported Unix platforms it |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
77 |
* goes right into the JNI wrappers |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
78 |
* - if the whole function or substantial parts of it are platform dependent, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
79 |
* the implementation goes into os_<function_name> functions in |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
80 |
* ProcessHandleImpl_<os>.c |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
81 |
* - if at least two platforms implement an os_<function_name> function in the |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
82 |
* same way, this implementation is factored out into unix_<function_name>, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
83 |
* placed into this file and called from the corresponding os_<function_name> |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
84 |
* function. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
85 |
* - For convenience, all the os_ and unix_ functions are declared in |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
86 |
* ProcessHandleImpl_unix.h which is included into every |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
87 |
* ProcessHandleImpl_<os>.c file. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
88 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
89 |
* Example 1: |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
90 |
* ---------- |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
91 |
* The implementation of Java_java_lang_ProcessHandleImpl_initNative() |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
92 |
* is the same on all platforms except on Linux where it initilizes one |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
93 |
* additional field. So we place the implementation right into |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
94 |
* Java_java_lang_ProcessHandleImpl_initNative() but add call to |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
95 |
* os_init() at the end of the function which is empty on all platforms |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
96 |
* except Linux where it performs the additionally initializations. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
97 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
98 |
* Example 2: |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
99 |
* ---------- |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
100 |
* The implementation of Java_java_lang_ProcessHandleImpl_00024Info_info0 is the |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
101 |
* same on Solaris and AIX but different on Linux and MacOSX. We therefore simply |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
102 |
* call the helpers os_getParentPidAndTimings() and os_getCmdlineAndUserInfo(). |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
103 |
* The Linux and MaxOS X versions of these functions (in the corresponding files |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
104 |
* ProcessHandleImpl_linux.c and ProcessHandleImpl_macosx.c) directly contain |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
105 |
* the platform specific implementations while the Solaris and AIX |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
106 |
* implementations simply call back to unix_getParentPidAndTimings() and |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
107 |
* unix_getCmdlineAndUserInfo() which are implemented right in this file. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
108 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
109 |
* The term "same implementation" is still a question of interpretation. It my |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
110 |
* be acceptable to have a few ifdef'ed lines if that allows the sharing of a |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
111 |
* huge function. On the other hand, if the platform specific code in a shared |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
112 |
* function grows over a certain limit, it may be better to refactor that |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
113 |
* functionality into corresponding, platform-specific os_ functions. |
30899 | 114 |
*/ |
115 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
116 |
|
30899 | 117 |
#ifndef WIFEXITED |
118 |
#define WIFEXITED(status) (((status)&0xFF) == 0) |
|
119 |
#endif |
|
120 |
||
121 |
#ifndef WEXITSTATUS |
|
122 |
#define WEXITSTATUS(status) (((status)>>8)&0xFF) |
|
123 |
#endif |
|
124 |
||
125 |
#ifndef WIFSIGNALED |
|
126 |
#define WIFSIGNALED(status) (((status)&0xFF) > 0 && ((status)&0xFF00) == 0) |
|
127 |
#endif |
|
128 |
||
129 |
#ifndef WTERMSIG |
|
130 |
#define WTERMSIG(status) ((status)&0x7F) |
|
131 |
#endif |
|
132 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
133 |
#ifdef __solaris__ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
134 |
/* The child exited because of a signal. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
135 |
* The best value to return is 0x80 + signal number, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
136 |
* because that is what all Unix shells do, and because |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
137 |
* it allows callers to distinguish between process exit and |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
138 |
* process death by signal. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
139 |
* Unfortunately, the historical behavior on Solaris is to return |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
140 |
* the signal number, and we preserve this for compatibility. */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
141 |
#define WTERMSIG_RETURN(status) WTERMSIG(status) |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
142 |
#else |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
143 |
#define WTERMSIG_RETURN(status) (WTERMSIG(status) + 0x80) |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
144 |
#endif |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
145 |
|
30899 | 146 |
#define RESTARTABLE(_cmd, _result) do { \ |
147 |
do { \ |
|
148 |
_result = _cmd; \ |
|
149 |
} while((_result == -1) && (errno == EINTR)); \ |
|
150 |
} while(0) |
|
151 |
||
152 |
#define RESTARTABLE_RETURN_PTR(_cmd, _result) do { \ |
|
153 |
do { \ |
|
154 |
_result = _cmd; \ |
|
155 |
} while((_result == NULL) && (errno == EINTR)); \ |
|
156 |
} while(0) |
|
157 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
158 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
159 |
/* Field id for jString 'command' in java.lang.ProcessHandleImpl.Info */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
160 |
jfieldID ProcessHandleImpl_Info_commandID; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
161 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
162 |
/* Field id for jString 'commandLine' in java.lang.ProcessHandleImpl.Info */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
163 |
jfieldID ProcessHandleImpl_Info_commandLineID; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
164 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
165 |
/* Field id for jString[] 'arguments' in java.lang.ProcessHandleImpl.Info */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
166 |
jfieldID ProcessHandleImpl_Info_argumentsID; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
167 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
168 |
/* Field id for jlong 'totalTime' in java.lang.ProcessHandleImpl.Info */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
169 |
jfieldID ProcessHandleImpl_Info_totalTimeID; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
170 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
171 |
/* Field id for jlong 'startTime' in java.lang.ProcessHandleImpl.Info */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
172 |
jfieldID ProcessHandleImpl_Info_startTimeID; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
173 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
174 |
/* Field id for jString 'user' in java.lang.ProcessHandleImpl.Info */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
175 |
jfieldID ProcessHandleImpl_Info_userID; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
176 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
177 |
/* Size of password or group entry when not available via sysconf */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
178 |
#define ENT_BUF_SIZE 1024 |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
179 |
/* The value for the size of the buffer used by getpwuid_r(). The result of */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
180 |
/* sysconf(_SC_GETPW_R_SIZE_MAX) if available or ENT_BUF_SIZE otherwise. */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
181 |
static long getpw_buf_size; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
182 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
183 |
/************************************************************** |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
184 |
* Static method to initialize field IDs and the ticks per second rate. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
185 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
186 |
* Class: java_lang_ProcessHandleImpl_Info |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
187 |
* Method: initIDs |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
188 |
* Signature: ()V |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
189 |
*/ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
190 |
JNIEXPORT void JNICALL |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
191 |
Java_java_lang_ProcessHandleImpl_00024Info_initIDs(JNIEnv *env, jclass clazz) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
192 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
193 |
CHECK_NULL(ProcessHandleImpl_Info_commandID = |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
194 |
(*env)->GetFieldID(env, clazz, "command", "Ljava/lang/String;")); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
195 |
CHECK_NULL(ProcessHandleImpl_Info_commandLineID = |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
196 |
(*env)->GetFieldID(env, clazz, "commandLine", "Ljava/lang/String;")); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
197 |
CHECK_NULL(ProcessHandleImpl_Info_argumentsID = |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
198 |
(*env)->GetFieldID(env, clazz, "arguments", "[Ljava/lang/String;")); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
199 |
CHECK_NULL(ProcessHandleImpl_Info_totalTimeID = |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
200 |
(*env)->GetFieldID(env, clazz, "totalTime", "J")); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
201 |
CHECK_NULL(ProcessHandleImpl_Info_startTimeID = |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
202 |
(*env)->GetFieldID(env, clazz, "startTime", "J")); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
203 |
CHECK_NULL(ProcessHandleImpl_Info_userID = |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
204 |
(*env)->GetFieldID(env, clazz, "user", "Ljava/lang/String;")); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
205 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
206 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
207 |
/*********************************************************** |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
208 |
* Static method to initialize platform dependent constants. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
209 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
210 |
* Class: java_lang_ProcessHandleImpl |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
211 |
* Method: initNative |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
212 |
* Signature: ()V |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
213 |
*/ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
214 |
JNIEXPORT void JNICALL |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
215 |
Java_java_lang_ProcessHandleImpl_initNative(JNIEnv *env, jclass clazz) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
216 |
getpw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
217 |
if (getpw_buf_size == -1) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
218 |
getpw_buf_size = ENT_BUF_SIZE; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
219 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
220 |
os_initNative(env, clazz); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
221 |
} |
30899 | 222 |
|
223 |
/* Block until a child process exits and return its exit code. |
|
224 |
* Note, can only be called once for any given pid if reapStatus = true. |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
225 |
* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
226 |
* Class: java_lang_ProcessHandleImpl |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
227 |
* Method: waitForProcessExit0 |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
228 |
* Signature: (JZ)I |
30899 | 229 |
*/ |
230 |
JNIEXPORT jint JNICALL |
|
231 |
Java_java_lang_ProcessHandleImpl_waitForProcessExit0(JNIEnv* env, |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
232 |
jclass junk, |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
233 |
jlong jpid, |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
234 |
jboolean reapStatus) { |
30899 | 235 |
pid_t pid = (pid_t)jpid; |
236 |
errno = 0; |
|
237 |
||
238 |
if (reapStatus != JNI_FALSE) { |
|
239 |
/* Wait for the child process to exit. |
|
240 |
* waitpid() is standard, so use it on all POSIX platforms. |
|
241 |
* It is known to work when blocking to wait for the pid |
|
242 |
* This returns immediately if the child has already exited. |
|
243 |
*/ |
|
244 |
int status; |
|
245 |
while (waitpid(pid, &status, 0) < 0) { |
|
246 |
switch (errno) { |
|
44269
762b2df849b3
8176272: (process) ProcessHandle::onExit fails to wait for non-child process
rriggs
parents:
40206
diff
changeset
|
247 |
case ECHILD: |
762b2df849b3
8176272: (process) ProcessHandle::onExit fails to wait for non-child process
rriggs
parents:
40206
diff
changeset
|
248 |
return java_lang_ProcessHandleImpl_NOT_A_CHILD; // No child |
30899 | 249 |
case EINTR: break; |
250 |
default: return -1; |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
if (WIFEXITED(status)) { |
|
255 |
return WEXITSTATUS(status); |
|
256 |
} else if (WIFSIGNALED(status)) { |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
257 |
return WTERMSIG_RETURN(status); |
30899 | 258 |
} else { |
259 |
return status; |
|
260 |
} |
|
261 |
} else { |
|
262 |
/* |
|
263 |
* Wait for the child process to exit without reaping the exitValue. |
|
264 |
* waitid() is standard on all POSIX platforms. |
|
265 |
* Note: waitid on Mac OS X 10.7 seems to be broken; |
|
266 |
* it does not return the exit status consistently. |
|
267 |
*/ |
|
268 |
siginfo_t siginfo; |
|
269 |
int options = WEXITED | WNOWAIT; |
|
270 |
memset(&siginfo, 0, sizeof siginfo); |
|
271 |
while (waitid(P_PID, pid, &siginfo, options) < 0) { |
|
272 |
switch (errno) { |
|
44269
762b2df849b3
8176272: (process) ProcessHandle::onExit fails to wait for non-child process
rriggs
parents:
40206
diff
changeset
|
273 |
case ECHILD: |
762b2df849b3
8176272: (process) ProcessHandle::onExit fails to wait for non-child process
rriggs
parents:
40206
diff
changeset
|
274 |
return java_lang_ProcessHandleImpl_NOT_A_CHILD; // No child |
762b2df849b3
8176272: (process) ProcessHandle::onExit fails to wait for non-child process
rriggs
parents:
40206
diff
changeset
|
275 |
case EINTR: break; |
762b2df849b3
8176272: (process) ProcessHandle::onExit fails to wait for non-child process
rriggs
parents:
40206
diff
changeset
|
276 |
default: return -1; |
30899 | 277 |
} |
278 |
} |
|
279 |
||
280 |
if (siginfo.si_code == CLD_EXITED) { |
|
281 |
/* |
|
282 |
* The child exited normally; get its exit code. |
|
283 |
*/ |
|
284 |
return siginfo.si_status; |
|
285 |
} else if (siginfo.si_code == CLD_KILLED || siginfo.si_code == CLD_DUMPED) { |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
286 |
return WTERMSIG_RETURN(siginfo.si_status); |
30899 | 287 |
} else { |
288 |
/* |
|
289 |
* Unknown exit code; pass it through. |
|
290 |
*/ |
|
291 |
return siginfo.si_status; |
|
292 |
} |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
/* |
|
297 |
* Class: java_lang_ProcessHandleImpl |
|
298 |
* Method: getCurrentPid0 |
|
299 |
* Signature: ()J |
|
300 |
*/ |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
301 |
JNIEXPORT jlong JNICALL |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
302 |
Java_java_lang_ProcessHandleImpl_getCurrentPid0(JNIEnv *env, jclass clazz) { |
30899 | 303 |
pid_t pid = getpid(); |
304 |
return (jlong) pid; |
|
305 |
} |
|
306 |
||
307 |
/* |
|
308 |
* Class: java_lang_ProcessHandleImpl |
|
309 |
* Method: destroy0 |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
310 |
* Signature: (JJZ)Z |
30899 | 311 |
*/ |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
312 |
JNIEXPORT jboolean JNICALL |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
313 |
Java_java_lang_ProcessHandleImpl_destroy0(JNIEnv *env, |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
314 |
jobject obj, |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
315 |
jlong jpid, |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
316 |
jlong startTime, |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
317 |
jboolean force) { |
30899 | 318 |
pid_t pid = (pid_t) jpid; |
319 |
int sig = (force == JNI_TRUE) ? SIGKILL : SIGTERM; |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
320 |
jlong start = Java_java_lang_ProcessHandleImpl_isAlive0(env, obj, jpid); |
30899 | 321 |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
322 |
if (start == startTime || start == 0 || startTime == 0) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
323 |
return (kill(pid, sig) < 0) ? JNI_FALSE : JNI_TRUE; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
324 |
} else { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
325 |
return JNI_FALSE; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
326 |
} |
30899 | 327 |
} |
328 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
329 |
/* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
330 |
* Returns the children of the requested pid and optionally each parent and |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
331 |
* start time. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
332 |
* Accumulates any process who parent pid matches. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
333 |
* The resulting pids are stored into the array of longs. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
334 |
* The number of pids is returned if they all fit. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
335 |
* If the array is too short, the negative of the desired length is returned. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
336 |
* Class: java_lang_ProcessHandleImpl |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
337 |
* Method: getProcessPids0 |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
338 |
* Signature: (J[J[J[J)I |
30899 | 339 |
*/ |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
340 |
JNIEXPORT jint JNICALL |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
341 |
Java_java_lang_ProcessHandleImpl_getProcessPids0(JNIEnv *env, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
342 |
jclass clazz, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
343 |
jlong jpid, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
344 |
jlongArray jarray, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
345 |
jlongArray jparentArray, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
346 |
jlongArray jstimesArray) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
347 |
return os_getChildren(env, jpid, jarray, jparentArray, jstimesArray); |
30899 | 348 |
} |
349 |
||
350 |
/* |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
351 |
* Fill in the Info object from the OS information about the process. |
30899 | 352 |
* |
353 |
* Class: java_lang_ProcessHandleImpl_Info |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
354 |
* Method: info0 |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
355 |
* Signature: (Ljava/lang/ProcessHandle/Info;J)I |
30899 | 356 |
*/ |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
357 |
JNIEXPORT void JNICALL |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
358 |
Java_java_lang_ProcessHandleImpl_00024Info_info0(JNIEnv *env, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
359 |
jobject jinfo, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
360 |
jlong jpid) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
361 |
pid_t pid = (pid_t) jpid; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
362 |
pid_t ppid; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
363 |
jlong totalTime = -1L; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
364 |
jlong startTime = -1L; |
30899 | 365 |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
366 |
ppid = os_getParentPidAndTimings(env, pid, &totalTime, &startTime); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
367 |
if (ppid >= 0) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
368 |
(*env)->SetLongField(env, jinfo, ProcessHandleImpl_Info_totalTimeID, totalTime); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
369 |
JNU_CHECK_EXCEPTION(env); |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
370 |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
371 |
(*env)->SetLongField(env, jinfo, ProcessHandleImpl_Info_startTimeID, startTime); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
372 |
JNU_CHECK_EXCEPTION(env); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
373 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
374 |
os_getCmdlineAndUserInfo(env, jinfo, pid); |
30899 | 375 |
} |
376 |
||
377 |
/* |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
378 |
* Check if a process is alive. |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
379 |
* Return the start time (ms since 1970) if it is available. |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
380 |
* If the start time is not available return 0. |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
381 |
* If the pid is invalid, return -1. |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
382 |
* |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
383 |
* Class: java_lang_ProcessHandleImpl |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
384 |
* Method: isAlive0 |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
385 |
* Signature: (J)J |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
386 |
*/ |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
387 |
JNIEXPORT jlong JNICALL |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
388 |
Java_java_lang_ProcessHandleImpl_isAlive0(JNIEnv *env, jobject obj, jlong jpid) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
389 |
pid_t pid = (pid_t) jpid; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
390 |
jlong startTime = 0L; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
391 |
jlong totalTime = 0L; |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
392 |
pid_t ppid = os_getParentPidAndTimings(env, pid, &totalTime, &startTime); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
393 |
return (ppid < 0) ? -1 : startTime; |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
394 |
} |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
395 |
|
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
396 |
/* |
30899 | 397 |
* Returns the parent pid of the requested pid. |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
398 |
* The start time of the process must match (or be ANY). |
30899 | 399 |
* |
400 |
* Class: java_lang_ProcessHandleImpl |
|
401 |
* Method: parent0 |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
402 |
* Signature: (JJ)J |
30899 | 403 |
*/ |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
404 |
JNIEXPORT jlong JNICALL |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
405 |
Java_java_lang_ProcessHandleImpl_parent0(JNIEnv *env, |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
406 |
jobject obj, |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
407 |
jlong jpid, |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
408 |
jlong startTime) { |
30899 | 409 |
pid_t pid = (pid_t) jpid; |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
410 |
pid_t ppid; |
30899 | 411 |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
412 |
if (pid == getpid()) { |
30899 | 413 |
ppid = getppid(); |
414 |
} else { |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
415 |
jlong start = 0L; |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
416 |
jlong total = 0L; // unused |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
417 |
ppid = os_getParentPidAndTimings(env, pid, &total, &start); |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
418 |
if (start != startTime && start != 0 && startTime != 0) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
419 |
ppid = -1; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
420 |
} |
30899 | 421 |
} |
422 |
return (jlong) ppid; |
|
423 |
} |
|
424 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
425 |
/** |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
426 |
* Construct the argument array by parsing the arguments from the sequence |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
427 |
* of arguments. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
428 |
*/ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
429 |
void unix_fillArgArray(JNIEnv *env, jobject jinfo, int nargs, char *cp, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
430 |
char *argsEnd, jstring cmdexe, char *cmdline) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
431 |
jobject argsArray; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
432 |
int i; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
433 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
434 |
(*env)->SetObjectField(env, jinfo, ProcessHandleImpl_Info_commandID, cmdexe); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
435 |
JNU_CHECK_EXCEPTION(env); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
436 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
437 |
if (nargs >= 1) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
438 |
// Create a String array for nargs-1 elements |
40179
b5d59a6f093a
8161431: JNI pending exceptions in ProcessHandleImpl_linux.c and ProcessHandleImpl_unix.c
rriggs
parents:
32209
diff
changeset
|
439 |
jclass clazzString = JNU_ClassString(env); |
b5d59a6f093a
8161431: JNI pending exceptions in ProcessHandleImpl_linux.c and ProcessHandleImpl_unix.c
rriggs
parents:
32209
diff
changeset
|
440 |
CHECK_NULL(clazzString); |
b5d59a6f093a
8161431: JNI pending exceptions in ProcessHandleImpl_linux.c and ProcessHandleImpl_unix.c
rriggs
parents:
32209
diff
changeset
|
441 |
argsArray = (*env)->NewObjectArray(env, nargs - 1, clazzString, NULL); |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
442 |
CHECK_NULL(argsArray); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
443 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
444 |
for (i = 0; i < nargs - 1; i++) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
445 |
jstring str = NULL; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
446 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
447 |
cp += strlen(cp) + 1; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
448 |
if (cp > argsEnd || *cp == '\0') { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
449 |
return; // Off the end pointer or an empty argument is an error |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
450 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
451 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
452 |
CHECK_NULL((str = JNU_NewStringPlatform(env, cp))); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
453 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
454 |
(*env)->SetObjectArrayElement(env, argsArray, i, str); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
455 |
JNU_CHECK_EXCEPTION(env); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
456 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
457 |
(*env)->SetObjectField(env, jinfo, ProcessHandleImpl_Info_argumentsID, argsArray); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
458 |
JNU_CHECK_EXCEPTION(env); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
459 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
460 |
if (cmdline != NULL) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
461 |
jstring commandLine = NULL; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
462 |
CHECK_NULL((commandLine = JNU_NewStringPlatform(env, cmdline))); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
463 |
(*env)->SetObjectField(env, jinfo, ProcessHandleImpl_Info_commandLineID, commandLine); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
464 |
JNU_CHECK_EXCEPTION(env); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
465 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
466 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
467 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
468 |
void unix_getUserInfo(JNIEnv* env, jobject jinfo, uid_t uid) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
469 |
int result = 0; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
470 |
char* pwbuf; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
471 |
jstring name = NULL; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
472 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
473 |
/* allocate buffer for password record */ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
474 |
pwbuf = (char*)malloc(getpw_buf_size); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
475 |
if (pwbuf == NULL) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
476 |
JNU_ThrowOutOfMemoryError(env, "Unable to open getpwent"); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
477 |
} else { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
478 |
struct passwd pwent; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
479 |
struct passwd* p = NULL; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
480 |
RESTARTABLE(getpwuid_r(uid, &pwent, pwbuf, (size_t)getpw_buf_size, &p), result); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
481 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
482 |
// Create the Java String if a name was found |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
483 |
if (result == 0 && p != NULL && |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
484 |
p->pw_name != NULL && *(p->pw_name) != '\0') { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
485 |
name = JNU_NewStringPlatform(env, p->pw_name); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
486 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
487 |
free(pwbuf); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
488 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
489 |
if (name != NULL) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
490 |
(*env)->SetObjectField(env, jinfo, ProcessHandleImpl_Info_userID, name); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
491 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
492 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
493 |
|
30899 | 494 |
/* |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
495 |
* The following functions are common on Solaris, Linux and AIX. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
496 |
*/ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
497 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
498 |
#if defined(__solaris__) || defined (__linux__) || defined(_AIX) |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
499 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
500 |
/* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
501 |
* Returns the children of the requested pid and optionally each parent and |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
502 |
* start time. |
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
503 |
* Reads /proc and accumulates any process who parent pid matches. |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
504 |
* The resulting pids are stored into the array of longs. |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
505 |
* The number of pids is returned if they all fit. |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
506 |
* If the array is too short, the negative of the desired length is returned. |
30899 | 507 |
*/ |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
508 |
jint unix_getChildren(JNIEnv *env, jlong jpid, jlongArray jarray, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
509 |
jlongArray jparentArray, jlongArray jstimesArray) { |
30899 | 510 |
DIR* dir; |
511 |
struct dirent* ptr; |
|
512 |
pid_t pid = (pid_t) jpid; |
|
513 |
jlong* pids = NULL; |
|
514 |
jlong* ppids = NULL; |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
515 |
jlong* stimes = NULL; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
516 |
jsize parentArraySize = 0; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
517 |
jsize arraySize = 0; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
518 |
jsize stimesSize = 0; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
519 |
jsize count = 0; |
30899 | 520 |
|
521 |
arraySize = (*env)->GetArrayLength(env, jarray); |
|
522 |
JNU_CHECK_EXCEPTION_RETURN(env, -1); |
|
523 |
if (jparentArray != NULL) { |
|
524 |
parentArraySize = (*env)->GetArrayLength(env, jparentArray); |
|
525 |
JNU_CHECK_EXCEPTION_RETURN(env, -1); |
|
526 |
||
527 |
if (arraySize != parentArraySize) { |
|
528 |
JNU_ThrowIllegalArgumentException(env, "array sizes not equal"); |
|
529 |
return 0; |
|
530 |
} |
|
531 |
} |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
532 |
if (jstimesArray != NULL) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
533 |
stimesSize = (*env)->GetArrayLength(env, jstimesArray); |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
534 |
JNU_CHECK_EXCEPTION_RETURN(env, -1); |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
535 |
|
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
536 |
if (arraySize != stimesSize) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
537 |
JNU_ThrowIllegalArgumentException(env, "array sizes not equal"); |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
538 |
return 0; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
539 |
} |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
540 |
} |
30899 | 541 |
|
542 |
/* |
|
543 |
* To locate the children we scan /proc looking for files that have a |
|
544 |
* position integer as a filename. |
|
545 |
*/ |
|
546 |
if ((dir = opendir("/proc")) == NULL) { |
|
547 |
JNU_ThrowByNameWithLastError(env, |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
548 |
"java/lang/RuntimeException", "Unable to open /proc"); |
30899 | 549 |
return -1; |
550 |
} |
|
551 |
||
552 |
do { // Block to break out of on Exception |
|
553 |
pids = (*env)->GetLongArrayElements(env, jarray, NULL); |
|
554 |
if (pids == NULL) { |
|
555 |
break; |
|
556 |
} |
|
557 |
if (jparentArray != NULL) { |
|
558 |
ppids = (*env)->GetLongArrayElements(env, jparentArray, NULL); |
|
559 |
if (ppids == NULL) { |
|
560 |
break; |
|
561 |
} |
|
562 |
} |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
563 |
if (jstimesArray != NULL) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
564 |
stimes = (*env)->GetLongArrayElements(env, jstimesArray, NULL); |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
565 |
if (stimes == NULL) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
566 |
break; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
567 |
} |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
568 |
} |
30899 | 569 |
|
570 |
while ((ptr = readdir(dir)) != NULL) { |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
571 |
pid_t ppid = 0; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
572 |
jlong totalTime = 0L; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
573 |
jlong startTime = 0L; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
574 |
|
30899 | 575 |
/* skip files that aren't numbers */ |
576 |
pid_t childpid = (pid_t) atoi(ptr->d_name); |
|
577 |
if ((int) childpid <= 0) { |
|
578 |
continue; |
|
579 |
} |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
580 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
581 |
// Get the parent pid, and start time |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
582 |
ppid = os_getParentPidAndTimings(env, childpid, &totalTime, &startTime); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
583 |
if (ppid >= 0 && (pid == 0 || ppid == pid)) { |
30899 | 584 |
if (count < arraySize) { |
585 |
// Only store if it fits |
|
586 |
pids[count] = (jlong) childpid; |
|
587 |
||
588 |
if (ppids != NULL) { |
|
589 |
// Store the parentPid |
|
590 |
ppids[count] = (jlong) ppid; |
|
591 |
} |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
592 |
if (stimes != NULL) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
593 |
// Store the process start time |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
594 |
stimes[count] = startTime; |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
595 |
} |
30899 | 596 |
} |
597 |
count++; // Count to tabulate size needed |
|
598 |
} |
|
599 |
} |
|
600 |
} while (0); |
|
601 |
||
602 |
if (pids != NULL) { |
|
603 |
(*env)->ReleaseLongArrayElements(env, jarray, pids, 0); |
|
604 |
} |
|
605 |
if (ppids != NULL) { |
|
606 |
(*env)->ReleaseLongArrayElements(env, jparentArray, ppids, 0); |
|
607 |
} |
|
31682
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
608 |
if (stimes != NULL) { |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
609 |
(*env)->ReleaseLongArrayElements(env, jstimesArray, stimes, 0); |
c19dcf5e0b6d
8078099: (process) ProcessHandle should uniquely identify processes
rriggs
parents:
30899
diff
changeset
|
610 |
} |
30899 | 611 |
|
612 |
closedir(dir); |
|
613 |
// If more pids than array had size for; count will be greater than array size |
|
614 |
return count; |
|
615 |
} |
|
616 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
617 |
#endif // defined(__solaris__) || defined (__linux__) || defined(_AIX) |
30899 | 618 |
|
619 |
/* |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
620 |
* The following functions are common on Solaris and AIX. |
30899 | 621 |
*/ |
622 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
623 |
#if defined(__solaris__) || defined(_AIX) |
30899 | 624 |
|
625 |
/** |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
626 |
* Helper function to get the 'psinfo_t' data from "/proc/%d/psinfo". |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
627 |
* Returns 0 on success and -1 on error. |
30899 | 628 |
*/ |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
629 |
static int getPsinfo(pid_t pid, psinfo_t *psinfo) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
630 |
FILE* fp; |
30899 | 631 |
char fn[32]; |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
632 |
int ret; |
30899 | 633 |
|
634 |
/* |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
635 |
* Try to open /proc/%d/psinfo |
30899 | 636 |
*/ |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
637 |
snprintf(fn, sizeof fn, "/proc/%d/psinfo", pid); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
638 |
fp = fopen(fn, "r"); |
30899 | 639 |
if (fp == NULL) { |
640 |
return -1; |
|
641 |
} |
|
642 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
643 |
ret = fread(psinfo, 1, sizeof(psinfo_t), fp); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
644 |
fclose(fp); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
645 |
if (ret < sizeof(psinfo_t)) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
646 |
return -1; |
30899 | 647 |
} |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
648 |
return 0; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
649 |
} |
30899 | 650 |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
651 |
/** |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
652 |
* Read /proc/<pid>/psinfo and return the ppid, total cputime and start time. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
653 |
* Return: -1 is fail; >= 0 is parent pid |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
654 |
* 'total' will contain the running time of 'pid' in nanoseconds. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
655 |
* 'start' will contain the start time of 'pid' in milliseconds since epoch. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
656 |
*/ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
657 |
pid_t unix_getParentPidAndTimings(JNIEnv *env, pid_t pid, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
658 |
jlong *totalTime, jlong* startTime) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
659 |
psinfo_t psinfo; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
660 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
661 |
if (getPsinfo(pid, &psinfo) < 0) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
662 |
return -1; |
30899 | 663 |
} |
664 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
665 |
*totalTime = psinfo.pr_time.tv_sec * 1000000000L + psinfo.pr_time.tv_nsec; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
666 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
667 |
*startTime = psinfo.pr_start.tv_sec * (jlong)1000 + |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
668 |
psinfo.pr_start.tv_nsec / 1000000; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
669 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
670 |
return (pid_t) psinfo.pr_ppid; |
30899 | 671 |
} |
672 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
673 |
void unix_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
674 |
psinfo_t psinfo; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
675 |
char fn[32]; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
676 |
char exePath[PATH_MAX]; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
677 |
char prargs[PRARGSZ + 1]; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
678 |
jstring cmdexe = NULL; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
679 |
int ret; |
30899 | 680 |
|
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
681 |
/* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
682 |
* On Solaris, the full path to the executable command is the link in |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
683 |
* /proc/<pid>/paths/a.out. But it is only readable for processes we own. |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
684 |
*/ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
685 |
#if defined(__solaris__) |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
686 |
snprintf(fn, sizeof fn, "/proc/%d/path/a.out", pid); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
687 |
if ((ret = readlink(fn, exePath, PATH_MAX - 1)) > 0) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
688 |
// null terminate and create String to store for command |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
689 |
exePath[ret] = '\0'; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
690 |
CHECK_NULL(cmdexe = JNU_NewStringPlatform(env, exePath)); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
691 |
} |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
692 |
#endif |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
693 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
694 |
/* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
695 |
* Now try to open /proc/%d/psinfo |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
696 |
*/ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
697 |
if (getPsinfo(pid, &psinfo) < 0) { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
698 |
unix_fillArgArray(env, jinfo, 0, NULL, NULL, cmdexe, NULL); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
699 |
return; |
30899 | 700 |
} |
701 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
702 |
unix_getUserInfo(env, jinfo, psinfo.pr_uid); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
703 |
|
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
704 |
/* |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
705 |
* Now read psinfo.pr_psargs which contains the first PRARGSZ characters of the |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
706 |
* argument list (i.e. arg[0] arg[1] ...). Unfortunately, PRARGSZ is usually set |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
707 |
* to 80 characters only. Nevertheless it's better than nothing :) |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
708 |
*/ |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
709 |
strncpy(prargs, psinfo.pr_psargs, PRARGSZ); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
710 |
prargs[PRARGSZ] = '\0'; |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
711 |
if (prargs[0] == '\0') { |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
712 |
/* If psinfo.pr_psargs didn't contain any strings, use psinfo.pr_fname |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
713 |
* (which only contains the last component of exec()ed pathname) as a |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
714 |
* last resort. This is true for AIX kernel processes for example. |
30899 | 715 |
*/ |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
716 |
strncpy(prargs, psinfo.pr_fname, PRARGSZ); |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
717 |
prargs[PRARGSZ] = '\0'; |
30899 | 718 |
} |
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
719 |
unix_fillArgArray(env, jinfo, 0, NULL, NULL, cmdexe, |
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
720 |
prargs[0] == '\0' ? NULL : prargs); |
30899 | 721 |
} |
722 |
||
32209
24bb680a1609
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents:
31682
diff
changeset
|
723 |
#endif // defined(__solaris__) || defined(_AIX) |