1 /*
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2013 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
127
128 // statics
129 char AixAttachListener::_path[UNIX_PATH_MAX];
130 bool AixAttachListener::_has_path;
131 int AixAttachListener::_listener = -1;
132 // Shutdown marker to prevent accept blocking during clean-up
133 bool AixAttachListener::_shutdown = false;
134
135 // Supporting class to help split a buffer into individual components
136 class ArgumentIterator : public StackObj {
137 private:
138 char* _pos;
139 char* _end;
140 public:
141 ArgumentIterator(char* arg_buffer, size_t arg_size) {
142 _pos = arg_buffer;
143 _end = _pos + arg_size - 1;
144 }
145 char* next() {
146 if (*_pos == '\0') {
147 return NULL;
148 }
149 char* res = _pos;
150 char* next_pos = strchr(_pos, '\0');
151 if (next_pos < _end) {
152 next_pos++;
153 }
154 _pos = next_pos;
155 return res;
156 }
157 };
158
159 // On AIX if sockets block until all data has been transmitted
160 // successfully in some communication domains a socket "close" may
161 // never complete. We have to take care that after the socket shutdown
162 // the listener never enters accept state.
163
164 // atexit hook to stop listener and unlink the file that it is
165 // bound too.
166
197 // register function to cleanup
198 ::atexit(listener_cleanup);
199
200 int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
201 os::get_temp_directory(), os::current_process_id());
202 if (n < (int)UNIX_PATH_MAX) {
203 n = snprintf(initial_path, UNIX_PATH_MAX, "%s.tmp", path);
204 }
205 if (n >= (int)UNIX_PATH_MAX) {
206 return -1;
207 }
208
209 // create the listener socket
210 listener = ::socket(PF_UNIX, SOCK_STREAM, 0);
211 if (listener == -1) {
212 return -1;
213 }
214
215 // bind socket
216 struct sockaddr_un addr;
217 addr.sun_family = AF_UNIX;
218 strcpy(addr.sun_path, initial_path);
219 ::unlink(initial_path);
220 // We must call bind with the actual socketaddr length. This is obligatory for AS400.
221 int res = ::bind(listener, (struct sockaddr*)&addr, SUN_LEN(&addr));
222 if (res == -1) {
223 RESTARTABLE(::close(listener), res);
224 return -1;
225 }
226
227 // put in listen mode, set permissions, and rename into place
228 res = ::listen(listener, 5);
229 if (res == 0) {
230 RESTARTABLE(::chmod(initial_path, (S_IREAD|S_IWRITE) & ~(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)), res);
231 if (res == 0) {
232 res = ::rename(initial_path, path);
233 }
234 }
235 if (res == -1) {
236 RESTARTABLE(::close(listener), res);
|
1 /*
2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2015 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
127
128 // statics
129 char AixAttachListener::_path[UNIX_PATH_MAX];
130 bool AixAttachListener::_has_path;
131 int AixAttachListener::_listener = -1;
132 // Shutdown marker to prevent accept blocking during clean-up
133 bool AixAttachListener::_shutdown = false;
134
135 // Supporting class to help split a buffer into individual components
136 class ArgumentIterator : public StackObj {
137 private:
138 char* _pos;
139 char* _end;
140 public:
141 ArgumentIterator(char* arg_buffer, size_t arg_size) {
142 _pos = arg_buffer;
143 _end = _pos + arg_size - 1;
144 }
145 char* next() {
146 if (*_pos == '\0') {
147 if (_pos < _end) {
148 _pos += 1;
149 }
150
151 return NULL;
152 }
153 char* res = _pos;
154 char* next_pos = strchr(_pos, '\0');
155 if (next_pos < _end) {
156 next_pos++;
157 }
158 _pos = next_pos;
159 return res;
160 }
161 };
162
163 // On AIX if sockets block until all data has been transmitted
164 // successfully in some communication domains a socket "close" may
165 // never complete. We have to take care that after the socket shutdown
166 // the listener never enters accept state.
167
168 // atexit hook to stop listener and unlink the file that it is
169 // bound too.
170
201 // register function to cleanup
202 ::atexit(listener_cleanup);
203
204 int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
205 os::get_temp_directory(), os::current_process_id());
206 if (n < (int)UNIX_PATH_MAX) {
207 n = snprintf(initial_path, UNIX_PATH_MAX, "%s.tmp", path);
208 }
209 if (n >= (int)UNIX_PATH_MAX) {
210 return -1;
211 }
212
213 // create the listener socket
214 listener = ::socket(PF_UNIX, SOCK_STREAM, 0);
215 if (listener == -1) {
216 return -1;
217 }
218
219 // bind socket
220 struct sockaddr_un addr;
221 memset((void *)&addr, 0, sizeof(addr));
222 addr.sun_family = AF_UNIX;
223 strcpy(addr.sun_path, initial_path);
224 ::unlink(initial_path);
225 // We must call bind with the actual socketaddr length. This is obligatory for AS400.
226 int res = ::bind(listener, (struct sockaddr*)&addr, SUN_LEN(&addr));
227 if (res == -1) {
228 RESTARTABLE(::close(listener), res);
229 return -1;
230 }
231
232 // put in listen mode, set permissions, and rename into place
233 res = ::listen(listener, 5);
234 if (res == 0) {
235 RESTARTABLE(::chmod(initial_path, (S_IREAD|S_IWRITE) & ~(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)), res);
236 if (res == 0) {
237 res = ::rename(initial_path, path);
238 }
239 }
240 if (res == -1) {
241 RESTARTABLE(::close(listener), res);
|