src/os/linux/vm/attachListener_linux.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "runtime/interfaceSupport.hpp"
aoqi@0 27 #include "runtime/os.hpp"
aoqi@0 28 #include "services/attachListener.hpp"
aoqi@0 29 #include "services/dtraceAttacher.hpp"
aoqi@0 30
aoqi@0 31 #include <unistd.h>
aoqi@0 32 #include <signal.h>
aoqi@0 33 #include <sys/types.h>
aoqi@0 34 #include <sys/socket.h>
aoqi@0 35 #include <sys/un.h>
aoqi@0 36 #include <sys/stat.h>
aoqi@0 37
aoqi@0 38 #ifndef UNIX_PATH_MAX
aoqi@0 39 #define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)0)->sun_path)
aoqi@0 40 #endif
aoqi@0 41
aoqi@0 42 // The attach mechanism on Linux uses a UNIX domain socket. An attach listener
aoqi@0 43 // thread is created at startup or is created on-demand via a signal from
aoqi@0 44 // the client tool. The attach listener creates a socket and binds it to a file
aoqi@0 45 // in the filesystem. The attach listener then acts as a simple (single-
aoqi@0 46 // threaded) server - it waits for a client to connect, reads the request,
aoqi@0 47 // executes it, and returns the response to the client via the socket
aoqi@0 48 // connection.
aoqi@0 49 //
aoqi@0 50 // As the socket is a UNIX domain socket it means that only clients on the
aoqi@0 51 // local machine can connect. In addition there are two other aspects to
aoqi@0 52 // the security:
aoqi@0 53 // 1. The well known file that the socket is bound to has permission 400
aoqi@0 54 // 2. When a client connect, the SO_PEERCRED socket option is used to
aoqi@0 55 // obtain the credentials of client. We check that the effective uid
aoqi@0 56 // of the client matches this process.
aoqi@0 57
aoqi@0 58 // forward reference
aoqi@0 59 class LinuxAttachOperation;
aoqi@0 60
aoqi@0 61 class LinuxAttachListener: AllStatic {
aoqi@0 62 private:
aoqi@0 63 // the path to which we bind the UNIX domain socket
aoqi@0 64 static char _path[UNIX_PATH_MAX];
aoqi@0 65 static bool _has_path;
aoqi@0 66
aoqi@0 67 // the file descriptor for the listening socket
aoqi@0 68 static int _listener;
aoqi@0 69
aoqi@0 70 static void set_path(char* path) {
aoqi@0 71 if (path == NULL) {
aoqi@0 72 _has_path = false;
aoqi@0 73 } else {
aoqi@0 74 strncpy(_path, path, UNIX_PATH_MAX);
aoqi@0 75 _path[UNIX_PATH_MAX-1] = '\0';
aoqi@0 76 _has_path = true;
aoqi@0 77 }
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 static void set_listener(int s) { _listener = s; }
aoqi@0 81
aoqi@0 82 // reads a request from the given connected socket
aoqi@0 83 static LinuxAttachOperation* read_request(int s);
aoqi@0 84
aoqi@0 85 public:
aoqi@0 86 enum {
aoqi@0 87 ATTACH_PROTOCOL_VER = 1 // protocol version
aoqi@0 88 };
aoqi@0 89 enum {
aoqi@0 90 ATTACH_ERROR_BADVERSION = 101 // error codes
aoqi@0 91 };
aoqi@0 92
aoqi@0 93 // initialize the listener, returns 0 if okay
aoqi@0 94 static int init();
aoqi@0 95
aoqi@0 96 static char* path() { return _path; }
aoqi@0 97 static bool has_path() { return _has_path; }
aoqi@0 98 static int listener() { return _listener; }
aoqi@0 99
aoqi@0 100 // write the given buffer to a socket
aoqi@0 101 static int write_fully(int s, char* buf, int len);
aoqi@0 102
aoqi@0 103 static LinuxAttachOperation* dequeue();
aoqi@0 104 };
aoqi@0 105
aoqi@0 106 class LinuxAttachOperation: public AttachOperation {
aoqi@0 107 private:
aoqi@0 108 // the connection to the client
aoqi@0 109 int _socket;
aoqi@0 110
aoqi@0 111 public:
aoqi@0 112 void complete(jint res, bufferedStream* st);
aoqi@0 113
aoqi@0 114 void set_socket(int s) { _socket = s; }
aoqi@0 115 int socket() const { return _socket; }
aoqi@0 116
aoqi@0 117 LinuxAttachOperation(char* name) : AttachOperation(name) {
aoqi@0 118 set_socket(-1);
aoqi@0 119 }
aoqi@0 120 };
aoqi@0 121
aoqi@0 122 // statics
aoqi@0 123 char LinuxAttachListener::_path[UNIX_PATH_MAX];
aoqi@0 124 bool LinuxAttachListener::_has_path;
aoqi@0 125 int LinuxAttachListener::_listener = -1;
aoqi@0 126
aoqi@0 127 // Supporting class to help split a buffer into individual components
aoqi@0 128 class ArgumentIterator : public StackObj {
aoqi@0 129 private:
aoqi@0 130 char* _pos;
aoqi@0 131 char* _end;
aoqi@0 132 public:
aoqi@0 133 ArgumentIterator(char* arg_buffer, size_t arg_size) {
aoqi@0 134 _pos = arg_buffer;
aoqi@0 135 _end = _pos + arg_size - 1;
aoqi@0 136 }
aoqi@0 137 char* next() {
aoqi@0 138 if (*_pos == '\0') {
aoqi@0 139 return NULL;
aoqi@0 140 }
aoqi@0 141 char* res = _pos;
aoqi@0 142 char* next_pos = strchr(_pos, '\0');
aoqi@0 143 if (next_pos < _end) {
aoqi@0 144 next_pos++;
aoqi@0 145 }
aoqi@0 146 _pos = next_pos;
aoqi@0 147 return res;
aoqi@0 148 }
aoqi@0 149 };
aoqi@0 150
aoqi@0 151
aoqi@0 152 // atexit hook to stop listener and unlink the file that it is
aoqi@0 153 // bound too.
aoqi@0 154 extern "C" {
aoqi@0 155 static void listener_cleanup() {
aoqi@0 156 static int cleanup_done;
aoqi@0 157 if (!cleanup_done) {
aoqi@0 158 cleanup_done = 1;
aoqi@0 159 int s = LinuxAttachListener::listener();
aoqi@0 160 if (s != -1) {
aoqi@0 161 ::close(s);
aoqi@0 162 }
aoqi@0 163 if (LinuxAttachListener::has_path()) {
aoqi@0 164 ::unlink(LinuxAttachListener::path());
aoqi@0 165 }
aoqi@0 166 }
aoqi@0 167 }
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 // Initialization - create a listener socket and bind it to a file
aoqi@0 171
aoqi@0 172 int LinuxAttachListener::init() {
aoqi@0 173 char path[UNIX_PATH_MAX]; // socket file
aoqi@0 174 char initial_path[UNIX_PATH_MAX]; // socket file during setup
aoqi@0 175 int listener; // listener socket (file descriptor)
aoqi@0 176
aoqi@0 177 // register function to cleanup
aoqi@0 178 ::atexit(listener_cleanup);
aoqi@0 179
aoqi@0 180 int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
aoqi@0 181 os::get_temp_directory(), os::current_process_id());
aoqi@0 182 if (n < (int)UNIX_PATH_MAX) {
aoqi@0 183 n = snprintf(initial_path, UNIX_PATH_MAX, "%s.tmp", path);
aoqi@0 184 }
aoqi@0 185 if (n >= (int)UNIX_PATH_MAX) {
aoqi@0 186 return -1;
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 // create the listener socket
aoqi@0 190 listener = ::socket(PF_UNIX, SOCK_STREAM, 0);
aoqi@0 191 if (listener == -1) {
aoqi@0 192 return -1;
aoqi@0 193 }
aoqi@0 194
aoqi@0 195 // bind socket
aoqi@0 196 struct sockaddr_un addr;
aoqi@0 197 addr.sun_family = AF_UNIX;
aoqi@0 198 strcpy(addr.sun_path, initial_path);
aoqi@0 199 ::unlink(initial_path);
aoqi@0 200 int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr));
aoqi@0 201 if (res == -1) {
aoqi@0 202 ::close(listener);
aoqi@0 203 return -1;
aoqi@0 204 }
aoqi@0 205
aoqi@0 206 // put in listen mode, set permissions, and rename into place
aoqi@0 207 res = ::listen(listener, 5);
aoqi@0 208 if (res == 0) {
aoqi@0 209 RESTARTABLE(::chmod(initial_path, S_IREAD|S_IWRITE), res);
aoqi@0 210 if (res == 0) {
aoqi@0 211 res = ::rename(initial_path, path);
aoqi@0 212 }
aoqi@0 213 }
aoqi@0 214 if (res == -1) {
aoqi@0 215 ::close(listener);
aoqi@0 216 ::unlink(initial_path);
aoqi@0 217 return -1;
aoqi@0 218 }
aoqi@0 219 set_path(path);
aoqi@0 220 set_listener(listener);
aoqi@0 221
aoqi@0 222 return 0;
aoqi@0 223 }
aoqi@0 224
aoqi@0 225 // Given a socket that is connected to a peer we read the request and
aoqi@0 226 // create an AttachOperation. As the socket is blocking there is potential
aoqi@0 227 // for a denial-of-service if the peer does not response. However this happens
aoqi@0 228 // after the peer credentials have been checked and in the worst case it just
aoqi@0 229 // means that the attach listener thread is blocked.
aoqi@0 230 //
aoqi@0 231 LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
aoqi@0 232 char ver_str[8];
aoqi@0 233 sprintf(ver_str, "%d", ATTACH_PROTOCOL_VER);
aoqi@0 234
aoqi@0 235 // The request is a sequence of strings so we first figure out the
aoqi@0 236 // expected count and the maximum possible length of the request.
aoqi@0 237 // The request is:
aoqi@0 238 // <ver>0<cmd>0<arg>0<arg>0<arg>0
aoqi@0 239 // where <ver> is the protocol version (1), <cmd> is the command
aoqi@0 240 // name ("load", "datadump", ...), and <arg> is an argument
aoqi@0 241 int expected_str_count = 2 + AttachOperation::arg_count_max;
aoqi@0 242 const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
aoqi@0 243 AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);
aoqi@0 244
aoqi@0 245 char buf[max_len];
aoqi@0 246 int str_count = 0;
aoqi@0 247
aoqi@0 248 // Read until all (expected) strings have been read, the buffer is
aoqi@0 249 // full, or EOF.
aoqi@0 250
aoqi@0 251 int off = 0;
aoqi@0 252 int left = max_len;
aoqi@0 253
aoqi@0 254 do {
aoqi@0 255 int n;
aoqi@0 256 RESTARTABLE(read(s, buf+off, left), n);
aoqi@0 257 if (n == -1) {
aoqi@0 258 return NULL; // reset by peer or other error
aoqi@0 259 }
aoqi@0 260 if (n == 0) {
aoqi@0 261 break;
aoqi@0 262 }
aoqi@0 263 for (int i=0; i<n; i++) {
aoqi@0 264 if (buf[off+i] == 0) {
aoqi@0 265 // EOS found
aoqi@0 266 str_count++;
aoqi@0 267
aoqi@0 268 // The first string is <ver> so check it now to
aoqi@0 269 // check for protocol mis-match
aoqi@0 270 if (str_count == 1) {
aoqi@0 271 if ((strlen(buf) != strlen(ver_str)) ||
aoqi@0 272 (atoi(buf) != ATTACH_PROTOCOL_VER)) {
aoqi@0 273 char msg[32];
aoqi@0 274 sprintf(msg, "%d\n", ATTACH_ERROR_BADVERSION);
aoqi@0 275 write_fully(s, msg, strlen(msg));
aoqi@0 276 return NULL;
aoqi@0 277 }
aoqi@0 278 }
aoqi@0 279 }
aoqi@0 280 }
aoqi@0 281 off += n;
aoqi@0 282 left -= n;
aoqi@0 283 } while (left > 0 && str_count < expected_str_count);
aoqi@0 284
aoqi@0 285 if (str_count != expected_str_count) {
aoqi@0 286 return NULL; // incomplete request
aoqi@0 287 }
aoqi@0 288
aoqi@0 289 // parse request
aoqi@0 290
aoqi@0 291 ArgumentIterator args(buf, (max_len)-left);
aoqi@0 292
aoqi@0 293 // version already checked
aoqi@0 294 char* v = args.next();
aoqi@0 295
aoqi@0 296 char* name = args.next();
aoqi@0 297 if (name == NULL || strlen(name) > AttachOperation::name_length_max) {
aoqi@0 298 return NULL;
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 LinuxAttachOperation* op = new LinuxAttachOperation(name);
aoqi@0 302
aoqi@0 303 for (int i=0; i<AttachOperation::arg_count_max; i++) {
aoqi@0 304 char* arg = args.next();
aoqi@0 305 if (arg == NULL) {
aoqi@0 306 op->set_arg(i, NULL);
aoqi@0 307 } else {
aoqi@0 308 if (strlen(arg) > AttachOperation::arg_length_max) {
aoqi@0 309 delete op;
aoqi@0 310 return NULL;
aoqi@0 311 }
aoqi@0 312 op->set_arg(i, arg);
aoqi@0 313 }
aoqi@0 314 }
aoqi@0 315
aoqi@0 316 op->set_socket(s);
aoqi@0 317 return op;
aoqi@0 318 }
aoqi@0 319
aoqi@0 320
aoqi@0 321 // Dequeue an operation
aoqi@0 322 //
aoqi@0 323 // In the Linux implementation there is only a single operation and clients
aoqi@0 324 // cannot queue commands (except at the socket level).
aoqi@0 325 //
aoqi@0 326 LinuxAttachOperation* LinuxAttachListener::dequeue() {
aoqi@0 327 for (;;) {
aoqi@0 328 int s;
aoqi@0 329
aoqi@0 330 // wait for client to connect
aoqi@0 331 struct sockaddr addr;
aoqi@0 332 socklen_t len = sizeof(addr);
aoqi@0 333 RESTARTABLE(::accept(listener(), &addr, &len), s);
aoqi@0 334 if (s == -1) {
aoqi@0 335 return NULL; // log a warning?
aoqi@0 336 }
aoqi@0 337
aoqi@0 338 // get the credentials of the peer and check the effective uid/guid
aoqi@0 339 // - check with jeff on this.
aoqi@0 340 struct ucred cred_info;
aoqi@0 341 socklen_t optlen = sizeof(cred_info);
aoqi@0 342 if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) {
aoqi@0 343 ::close(s);
aoqi@0 344 continue;
aoqi@0 345 }
aoqi@0 346 uid_t euid = geteuid();
aoqi@0 347 gid_t egid = getegid();
aoqi@0 348
aoqi@0 349 if (cred_info.uid != euid || cred_info.gid != egid) {
aoqi@0 350 ::close(s);
aoqi@0 351 continue;
aoqi@0 352 }
aoqi@0 353
aoqi@0 354 // peer credential look okay so we read the request
aoqi@0 355 LinuxAttachOperation* op = read_request(s);
aoqi@0 356 if (op == NULL) {
aoqi@0 357 ::close(s);
aoqi@0 358 continue;
aoqi@0 359 } else {
aoqi@0 360 return op;
aoqi@0 361 }
aoqi@0 362 }
aoqi@0 363 }
aoqi@0 364
aoqi@0 365 // write the given buffer to the socket
aoqi@0 366 int LinuxAttachListener::write_fully(int s, char* buf, int len) {
aoqi@0 367 do {
aoqi@0 368 int n = ::write(s, buf, len);
aoqi@0 369 if (n == -1) {
aoqi@0 370 if (errno != EINTR) return -1;
aoqi@0 371 } else {
aoqi@0 372 buf += n;
aoqi@0 373 len -= n;
aoqi@0 374 }
aoqi@0 375 }
aoqi@0 376 while (len > 0);
aoqi@0 377 return 0;
aoqi@0 378 }
aoqi@0 379
aoqi@0 380 // Complete an operation by sending the operation result and any result
aoqi@0 381 // output to the client. At this time the socket is in blocking mode so
aoqi@0 382 // potentially we can block if there is a lot of data and the client is
aoqi@0 383 // non-responsive. For most operations this is a non-issue because the
aoqi@0 384 // default send buffer is sufficient to buffer everything. In the future
aoqi@0 385 // if there are operations that involves a very big reply then it the
aoqi@0 386 // socket could be made non-blocking and a timeout could be used.
aoqi@0 387
aoqi@0 388 void LinuxAttachOperation::complete(jint result, bufferedStream* st) {
aoqi@0 389 JavaThread* thread = JavaThread::current();
aoqi@0 390 ThreadBlockInVM tbivm(thread);
aoqi@0 391
aoqi@0 392 thread->set_suspend_equivalent();
aoqi@0 393 // cleared by handle_special_suspend_equivalent_condition() or
aoqi@0 394 // java_suspend_self() via check_and_wait_while_suspended()
aoqi@0 395
aoqi@0 396 // write operation result
aoqi@0 397 char msg[32];
aoqi@0 398 sprintf(msg, "%d\n", result);
aoqi@0 399 int rc = LinuxAttachListener::write_fully(this->socket(), msg, strlen(msg));
aoqi@0 400
aoqi@0 401 // write any result data
aoqi@0 402 if (rc == 0) {
aoqi@0 403 LinuxAttachListener::write_fully(this->socket(), (char*) st->base(), st->size());
aoqi@0 404 ::shutdown(this->socket(), 2);
aoqi@0 405 }
aoqi@0 406
aoqi@0 407 // done
aoqi@0 408 ::close(this->socket());
aoqi@0 409
aoqi@0 410 // were we externally suspended while we were waiting?
aoqi@0 411 thread->check_and_wait_while_suspended();
aoqi@0 412
aoqi@0 413 delete this;
aoqi@0 414 }
aoqi@0 415
aoqi@0 416
aoqi@0 417 // AttachListener functions
aoqi@0 418
aoqi@0 419 AttachOperation* AttachListener::dequeue() {
aoqi@0 420 JavaThread* thread = JavaThread::current();
aoqi@0 421 ThreadBlockInVM tbivm(thread);
aoqi@0 422
aoqi@0 423 thread->set_suspend_equivalent();
aoqi@0 424 // cleared by handle_special_suspend_equivalent_condition() or
aoqi@0 425 // java_suspend_self() via check_and_wait_while_suspended()
aoqi@0 426
aoqi@0 427 AttachOperation* op = LinuxAttachListener::dequeue();
aoqi@0 428
aoqi@0 429 // were we externally suspended while we were waiting?
aoqi@0 430 thread->check_and_wait_while_suspended();
aoqi@0 431
aoqi@0 432 return op;
aoqi@0 433 }
aoqi@0 434
aoqi@0 435
aoqi@0 436 // Performs initialization at vm startup
aoqi@0 437 // For Linux we remove any stale .java_pid file which could cause
aoqi@0 438 // an attaching process to think we are ready to receive on the
aoqi@0 439 // domain socket before we are properly initialized
aoqi@0 440
aoqi@0 441 void AttachListener::vm_start() {
aoqi@0 442 char fn[UNIX_PATH_MAX];
aoqi@0 443 struct stat64 st;
aoqi@0 444 int ret;
aoqi@0 445
aoqi@0 446 int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
aoqi@0 447 os::get_temp_directory(), os::current_process_id());
aoqi@0 448 assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
aoqi@0 449
aoqi@0 450 RESTARTABLE(::stat64(fn, &st), ret);
aoqi@0 451 if (ret == 0) {
aoqi@0 452 ret = ::unlink(fn);
aoqi@0 453 if (ret == -1) {
aoqi@0 454 debug_only(warning("failed to remove stale attach pid file at %s", fn));
aoqi@0 455 }
aoqi@0 456 }
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 int AttachListener::pd_init() {
aoqi@0 460 JavaThread* thread = JavaThread::current();
aoqi@0 461 ThreadBlockInVM tbivm(thread);
aoqi@0 462
aoqi@0 463 thread->set_suspend_equivalent();
aoqi@0 464 // cleared by handle_special_suspend_equivalent_condition() or
aoqi@0 465 // java_suspend_self() via check_and_wait_while_suspended()
aoqi@0 466
aoqi@0 467 int ret_code = LinuxAttachListener::init();
aoqi@0 468
aoqi@0 469 // were we externally suspended while we were waiting?
aoqi@0 470 thread->check_and_wait_while_suspended();
aoqi@0 471
aoqi@0 472 return ret_code;
aoqi@0 473 }
aoqi@0 474
aoqi@0 475 // Attach Listener is started lazily except in the case when
aoqi@0 476 // +ReduseSignalUsage is used
aoqi@0 477 bool AttachListener::init_at_startup() {
aoqi@0 478 if (ReduceSignalUsage) {
aoqi@0 479 return true;
aoqi@0 480 } else {
aoqi@0 481 return false;
aoqi@0 482 }
aoqi@0 483 }
aoqi@0 484
aoqi@0 485 // If the file .attach_pid<pid> exists in the working directory
aoqi@0 486 // or /tmp then this is the trigger to start the attach mechanism
aoqi@0 487 bool AttachListener::is_init_trigger() {
aoqi@0 488 if (init_at_startup() || is_initialized()) {
aoqi@0 489 return false; // initialized at startup or already initialized
aoqi@0 490 }
aoqi@0 491 char fn[PATH_MAX+1];
aoqi@0 492 sprintf(fn, ".attach_pid%d", os::current_process_id());
aoqi@0 493 int ret;
aoqi@0 494 struct stat64 st;
aoqi@0 495 RESTARTABLE(::stat64(fn, &st), ret);
aoqi@0 496 if (ret == -1) {
aoqi@0 497 snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
aoqi@0 498 os::get_temp_directory(), os::current_process_id());
aoqi@0 499 RESTARTABLE(::stat64(fn, &st), ret);
aoqi@0 500 }
aoqi@0 501 if (ret == 0) {
aoqi@0 502 // simple check to avoid starting the attach mechanism when
aoqi@0 503 // a bogus user creates the file
aoqi@0 504 if (st.st_uid == geteuid()) {
aoqi@0 505 init();
aoqi@0 506 return true;
aoqi@0 507 }
aoqi@0 508 }
aoqi@0 509 return false;
aoqi@0 510 }
aoqi@0 511
aoqi@0 512 // if VM aborts then remove listener
aoqi@0 513 void AttachListener::abort() {
aoqi@0 514 listener_cleanup();
aoqi@0 515 }
aoqi@0 516
aoqi@0 517 void AttachListener::pd_data_dump() {
aoqi@0 518 os::signal_notify(SIGQUIT);
aoqi@0 519 }
aoqi@0 520
aoqi@0 521 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
aoqi@0 522 return NULL;
aoqi@0 523 }
aoqi@0 524
aoqi@0 525 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
aoqi@0 526 out->print_cr("flag '%s' cannot be changed", op->arg(0));
aoqi@0 527 return JNI_ERR;
aoqi@0 528 }
aoqi@0 529
aoqi@0 530 void AttachListener::pd_detachall() {
aoqi@0 531 // do nothing for now
aoqi@0 532 }

mercurial