Mercurial > hg > graal-jvmci-8
comparison src/os/linux/vm/attachListener_linux.cpp @ 11173:6b0fd0964b87
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 31 Jul 2013 11:00:54 +0200 |
parents | 2e8f19c2feef |
children |
comparison
equal
deleted
inserted
replaced
10912:4ea54634f03e | 11173:6b0fd0964b87 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
197 addr.sun_family = AF_UNIX; | 197 addr.sun_family = AF_UNIX; |
198 strcpy(addr.sun_path, initial_path); | 198 strcpy(addr.sun_path, initial_path); |
199 ::unlink(initial_path); | 199 ::unlink(initial_path); |
200 int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr)); | 200 int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr)); |
201 if (res == -1) { | 201 if (res == -1) { |
202 RESTARTABLE(::close(listener), res); | 202 ::close(listener); |
203 return -1; | 203 return -1; |
204 } | 204 } |
205 | 205 |
206 // put in listen mode, set permissions, and rename into place | 206 // put in listen mode, set permissions, and rename into place |
207 res = ::listen(listener, 5); | 207 res = ::listen(listener, 5); |
210 if (res == 0) { | 210 if (res == 0) { |
211 res = ::rename(initial_path, path); | 211 res = ::rename(initial_path, path); |
212 } | 212 } |
213 } | 213 } |
214 if (res == -1) { | 214 if (res == -1) { |
215 RESTARTABLE(::close(listener), res); | 215 ::close(listener); |
216 ::unlink(initial_path); | 216 ::unlink(initial_path); |
217 return -1; | 217 return -1; |
218 } | 218 } |
219 set_path(path); | 219 set_path(path); |
220 set_listener(listener); | 220 set_listener(listener); |
338 // get the credentials of the peer and check the effective uid/guid | 338 // get the credentials of the peer and check the effective uid/guid |
339 // - check with jeff on this. | 339 // - check with jeff on this. |
340 struct ucred cred_info; | 340 struct ucred cred_info; |
341 socklen_t optlen = sizeof(cred_info); | 341 socklen_t optlen = sizeof(cred_info); |
342 if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) { | 342 if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) { |
343 int res; | 343 ::close(s); |
344 RESTARTABLE(::close(s), res); | |
345 continue; | 344 continue; |
346 } | 345 } |
347 uid_t euid = geteuid(); | 346 uid_t euid = geteuid(); |
348 gid_t egid = getegid(); | 347 gid_t egid = getegid(); |
349 | 348 |
350 if (cred_info.uid != euid || cred_info.gid != egid) { | 349 if (cred_info.uid != euid || cred_info.gid != egid) { |
351 int res; | 350 ::close(s); |
352 RESTARTABLE(::close(s), res); | |
353 continue; | 351 continue; |
354 } | 352 } |
355 | 353 |
356 // peer credential look okay so we read the request | 354 // peer credential look okay so we read the request |
357 LinuxAttachOperation* op = read_request(s); | 355 LinuxAttachOperation* op = read_request(s); |
358 if (op == NULL) { | 356 if (op == NULL) { |
359 int res; | 357 ::close(s); |
360 RESTARTABLE(::close(s), res); | |
361 continue; | 358 continue; |
362 } else { | 359 } else { |
363 return op; | 360 return op; |
364 } | 361 } |
365 } | 362 } |
406 LinuxAttachListener::write_fully(this->socket(), (char*) st->base(), st->size()); | 403 LinuxAttachListener::write_fully(this->socket(), (char*) st->base(), st->size()); |
407 ::shutdown(this->socket(), 2); | 404 ::shutdown(this->socket(), 2); |
408 } | 405 } |
409 | 406 |
410 // done | 407 // done |
411 RESTARTABLE(::close(this->socket()), rc); | 408 ::close(this->socket()); |
412 | 409 |
413 // were we externally suspended while we were waiting? | 410 // were we externally suspended while we were waiting? |
414 thread->check_and_wait_while_suspended(); | 411 thread->check_and_wait_while_suspended(); |
415 | 412 |
416 delete this; | 413 delete this; |
431 | 428 |
432 // were we externally suspended while we were waiting? | 429 // were we externally suspended while we were waiting? |
433 thread->check_and_wait_while_suspended(); | 430 thread->check_and_wait_while_suspended(); |
434 | 431 |
435 return op; | 432 return op; |
433 } | |
434 | |
435 | |
436 // Performs initialization at vm startup | |
437 // For Linux we remove any stale .java_pid file which could cause | |
438 // an attaching process to think we are ready to receive on the | |
439 // domain socket before we are properly initialized | |
440 | |
441 void AttachListener::vm_start() { | |
442 char fn[UNIX_PATH_MAX]; | |
443 struct stat64 st; | |
444 int ret; | |
445 | |
446 int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d", | |
447 os::get_temp_directory(), os::current_process_id()); | |
448 assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow"); | |
449 | |
450 RESTARTABLE(::stat64(fn, &st), ret); | |
451 if (ret == 0) { | |
452 ret = ::unlink(fn); | |
453 if (ret == -1) { | |
454 debug_only(warning("failed to remove stale attach pid file at %s", fn)); | |
455 } | |
456 } | |
436 } | 457 } |
437 | 458 |
438 int AttachListener::pd_init() { | 459 int AttachListener::pd_init() { |
439 JavaThread* thread = JavaThread::current(); | 460 JavaThread* thread = JavaThread::current(); |
440 ThreadBlockInVM tbivm(thread); | 461 ThreadBlockInVM tbivm(thread); |