diff --git a/src/hotspot/os/aix/attachListener_aix.cpp b/src/hotspot/os/aix/attachListener_aix.cpp index 5e018c86fc2..ee57dcb6bfb 100644 --- a/src/hotspot/os/aix/attachListener_aix.cpp +++ b/src/hotspot/os/aix/attachListener_aix.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2016 SAP SE. All rights reserved. + * Copyright (c) 2012, 2018 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,12 +30,12 @@ #include "services/attachListener.hpp" #include "services/dtraceAttacher.hpp" -#include #include -#include #include -#include #include +#include +#include +#include #ifndef UNIX_PATH_MAX #define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)0)->sun_path) @@ -145,10 +145,10 @@ class ArgumentIterator : public StackObj { } char* next() { if (*_pos == '\0') { + // advance the iterator if possible (null arguments) if (_pos < _end) { _pos += 1; } - return NULL; } char* res = _pos; @@ -233,10 +233,10 @@ int AixAttachListener::init() { // put in listen mode, set permissions, and rename into place res = ::listen(listener, 5); if (res == 0) { - RESTARTABLE(::chmod(initial_path, (S_IREAD|S_IWRITE) & ~(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)), res); - if (res == 0) { - res = ::rename(initial_path, path); - } + RESTARTABLE(::chmod(initial_path, S_IREAD|S_IWRITE), res); + if (res == 0) { + res = ::rename(initial_path, path); + } } if (res == -1) { ::close(listener); @@ -284,10 +284,12 @@ AixAttachOperation* AixAttachListener::read_request(int s) { // Don't block on interrupts because this will // hang in the clean-up when shutting down. n = read(s, buf+off, left); + assert(n <= left, "buffer was too small, impossible!"); + buf[max_len - 1] = '\0'; if (n == -1) { return NULL; // reset by peer or other error } - if (n == 0) { // end of file reached + if (n == 0) { break; } for (int i=0; ibase(), (int)(result_stream->size())); + fSuccess = write_pipe(hPipe, (char*)result_stream->base(), (int)(result_stream->size())); } // Need to flush buffers FlushFileBuffers(hPipe); CloseHandle(hPipe); + + if (fSuccess) { + log_debug(attach)("wrote result of attach operation %s to pipe %s", name(), pipe()); + } else { + log_error(attach)("failure writing result of operation %s to pipe %s", name(), pipe()); + } + } else { + log_error(attach)("could not open pipe %s to send result of operation %s", pipe(), name()); } DWORD res = ::WaitForSingleObject(Win32AttachListener::mutex(), INFINITE); diff --git a/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java index d860048cd16..aba13752d80 100644 --- a/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java @@ -1,6 +1,6 @@ /* - * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2015 SAP SE. All rights reserved. + * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,8 +34,6 @@ import java.io.InputStream; import java.io.IOException; import java.io.File; -// Based on linux/classes/sun/tools/attach/VirtualMachineImpl.java. - /* * Aix implementation of HotSpotVirtualMachine */ @@ -140,7 +138,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { * Execute the given command in the target VM. */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { - assert args.length <= 3; // includes null + assert args.length <= 3; // includes null // did we detach? synchronized (this) { @@ -261,7 +259,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { } } - // On Solaris/Linux/Aix a simple handshake is used to start the attach mechanism + // On Aix a simple handshake is used to start the attach mechanism // if not already started. The client creates a .attach_pid file in the // target VM's working directory (or temp directory), and the SIGQUIT handler // checks for the file. diff --git a/src/jdk.attach/aix/native/libattach/VirtualMachineImpl.c b/src/jdk.attach/aix/native/libattach/VirtualMachineImpl.c index 6acecf96e9b..705ec9a06ed 100644 --- a/src/jdk.attach/aix/native/libattach/VirtualMachineImpl.c +++ b/src/jdk.attach/aix/native/libattach/VirtualMachineImpl.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2015 SAP SE. All rights reserved. + * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,27 +24,18 @@ * questions. */ -#include "jni.h" #include "jni_util.h" -#include "jvm.h" +#include +#include +#include +#include +#include +#include #include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include - -/* - * Based on 'LinuxVirtualMachine.c'. Non-relevant code has been removed and all - * occurrences of the string "Linux" have been replaced by "Aix". - */ #include "sun_tools_attach_VirtualMachineImpl.h" @@ -67,15 +58,6 @@ JNIEXPORT jint JNICALL Java_sun_tools_attach_VirtualMachineImpl_socket if (fd == -1) { JNU_ThrowIOExceptionWithLastError(env, "socket"); } - /* added time out values */ - else { - struct timeval tv; - tv.tv_sec = 2 * 60; - tv.tv_usec = 0; - - setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(tv)); - setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&tv, sizeof(tv)); - } return (jint)fd; } @@ -125,23 +107,6 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_connect } } - -/* - * Structure and callback function used to send a QUIT signal to all - * children of a given process - */ -typedef struct { - pid_t ppid; -} SendQuitContext; - -static void SendQuitCallback(const pid_t pid, void* user_data) { - SendQuitContext* context = (SendQuitContext*)user_data; - pid_t parent = getParent(pid); - if (parent == context->ppid) { - kill(pid, SIGQUIT); - } -} - /* * Class: sun_tools_attach_VirtualMachineImpl * Method: sendQuitTo @@ -169,7 +134,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions struct stat64 sb; uid_t uid, gid; int res; - /* added missing initialization of the stat64 buffer */ + memset(&sb, 0, sizeof(struct stat64)); /* @@ -189,21 +154,21 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions char msg[100]; jboolean isError = JNI_FALSE; if (sb.st_uid != uid) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file should be owned by the current user (which is %d) but is owned by %d", uid, sb.st_uid); isError = JNI_TRUE; } else if (sb.st_gid != gid) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file's group should be the current group (which is %d) but the group is %d", gid, sb.st_gid); isError = JNI_TRUE; } else if ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file should only be readable and writable by the owner but has 0%03o access", sb.st_mode & 0777); isError = JNI_TRUE; } if (isError) { char buf[256]; - jio_snprintf(buf, sizeof(buf)-1, "well-known file %s is not secure: %s", p, msg); + snprintf(buf, sizeof(buf), "well-known file %s is not secure: %s", p, msg); JNU_ThrowIOException(env, buf); } } else { @@ -229,11 +194,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_close (JNIEnv *env, jclass cls, jint fd) { int res; - /* Fixed deadlock when this call of close by the client is not seen by the attach server - * which has accepted the (very short) connection already and is waiting for the request. But read don't get a byte, - * because the close is lost without shutdown. - */ - shutdown(fd, 2); + shutdown(fd, SHUT_RDWR); RESTARTABLE(close(fd), res); } diff --git a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java index 5579d108fab..fa5ad22b5b9 100644 --- a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -105,7 +105,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { } finally { f.delete(); } - } + } // Check that the file owner/permission to avoid attaching to // bogus process @@ -274,7 +274,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { return new File(root, ".java_pid" + ns_pid); } - // On Solaris/Linux a simple handshake is used to start the attach mechanism + // On Linux a simple handshake is used to start the attach mechanism // if not already started. The client creates a .attach_pid file in the // target VM's working directory (or temp directory), and the SIGQUIT handler // checks for the file. @@ -356,8 +356,6 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { //-- native methods - static native void sendQuitToChildrenOf(int pid) throws IOException; - static native void sendQuitTo(int pid) throws IOException; static native void checkPermissions(String path) throws IOException; diff --git a/src/jdk.attach/linux/native/libattach/VirtualMachineImpl.c b/src/jdk.attach/linux/native/libattach/VirtualMachineImpl.c index 85d355a1e6a..a6cdf0a67ea 100644 --- a/src/jdk.attach/linux/native/libattach/VirtualMachineImpl.c +++ b/src/jdk.attach/linux/native/libattach/VirtualMachineImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,23 +23,18 @@ * questions. */ -#include "jni.h" #include "jni_util.h" -#include "jvm.h" +#include +#include +#include +#include +#include +#include #include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include #include "sun_tools_attach_VirtualMachineImpl.h" @@ -54,85 +49,6 @@ */ DEF_STATIC_JNI_OnLoad -/* - * Defines a callback that is invoked for each process - */ -typedef void (*ProcessCallback)(const pid_t pid, void* user_data); - -/* - * Invokes the callback function for each process - */ -static void forEachProcess(ProcessCallback f, void* user_data) { - DIR* dir; - struct dirent* ptr; - - /* - * To locate the children we scan /proc looking for files that have a - * position integer as a filename. - */ - if ((dir = opendir("/proc")) == NULL) { - return; - } - while ((ptr = readdir(dir)) != NULL) { - pid_t pid; - - /* skip current/parent directories */ - if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) { - continue; - } - - /* skip files that aren't numbers */ - pid = (pid_t)atoi(ptr->d_name); - if ((int)pid <= 0) { - continue; - } - - /* invoke the callback */ - (*f)(pid, user_data); - } - closedir(dir); -} - - -/* - * Returns the parent pid of a given pid, or -1 if not found - */ -static pid_t getParent(pid_t pid) { - char state; - FILE* fp; - char stat[2048]; - int statlen; - char fn[32]; - int i, p; - char* s; - - /* - * try to open /proc/%d/stat - */ - sprintf(fn, "/proc/%d/stat", pid); - fp = fopen(fn, "r"); - if (fp == NULL) { - return -1; - } - - /* - * The format is: pid (command) state ppid ... - * As the command could be anything we must find the right most - * ")" and then skip the white spaces that follow it. - */ - statlen = fread(stat, 1, 2047, fp); - stat[statlen] = '\0'; - fclose(fp); - s = strrchr(stat, ')'); - if (s == NULL) { - return -1; - } - do s++; while (isspace(*s)); - i = sscanf(s, "%c %d", &state, &p); - return (pid_t)p; -} - - /* * Class: sun_tools_attach_VirtualMachineImpl * Method: socket @@ -194,39 +110,6 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_connect } } -/* - * Structure and callback function used to send a QUIT signal to all - * children of a given process - */ -typedef struct { - pid_t ppid; -} SendQuitContext; - -static void SendQuitCallback(const pid_t pid, void* user_data) { - SendQuitContext* context = (SendQuitContext*)user_data; - pid_t parent = getParent(pid); - if (parent == context->ppid) { - kill(pid, SIGQUIT); - } -} - -/* - * Class: sun_tools_attach_VirtualMachineImpl - * Method: sendQuitToChildrenOf - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_sendQuitToChildrenOf - (JNIEnv *env, jclass cls, jint pid) -{ - SendQuitContext context; - context.ppid = (pid_t)pid; - - /* - * Iterate over all children of 'pid' and send a QUIT signal to each. - */ - forEachProcess(SendQuitCallback, (void*)&context); -} - /* * Class: sun_tools_attach_VirtualMachineImpl * Method: sendQuitTo @@ -255,6 +138,8 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions uid_t uid, gid; int res; + memset(&sb, 0, sizeof(struct stat64)); + /* * Check that the path is owned by the effective uid/gid of this * process. Also check that group/other access is not allowed. @@ -272,21 +157,21 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions char msg[100]; jboolean isError = JNI_FALSE; if (sb.st_uid != uid) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file should be owned by the current user (which is %d) but is owned by %d", uid, sb.st_uid); isError = JNI_TRUE; } else if (sb.st_gid != gid) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file's group should be the current group (which is %d) but the group is %d", gid, sb.st_gid); isError = JNI_TRUE; } else if ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file should only be readable and writable by the owner but has 0%03o access", sb.st_mode & 0777); isError = JNI_TRUE; } if (isError) { char buf[256]; - jio_snprintf(buf, sizeof(buf)-1, "well-known file %s is not secure: %s", p, msg); + snprintf(buf, sizeof(buf), "well-known file %s is not secure: %s", p, msg); JNU_ThrowIOException(env, buf); } } else { @@ -312,6 +197,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_close (JNIEnv *env, jclass cls, jint fd) { int res; + shutdown(fd, SHUT_RDWR); RESTARTABLE(close(fd), res); } @@ -366,8 +252,8 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_write RESTARTABLE(write(fd, buf, len), n); if (n > 0) { - off += n; - remaining -= n; + off += n; + remaining -= n; } else { JNU_ThrowIOExceptionWithLastError(env, "write"); return; diff --git a/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java index 5d866f57c43..0ca39214e4d 100644 --- a/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -281,8 +281,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { } private File createAttachFile(int pid) throws IOException { - String fn = ".attach_pid" + pid; - File f = new File(tmpdir, fn); + File f = new File(tmpdir, ".attach_pid" + pid); createAttachFile0(f.getPath()); return f; } diff --git a/src/jdk.attach/macosx/native/libattach/VirtualMachineImpl.c b/src/jdk.attach/macosx/native/libattach/VirtualMachineImpl.c index 42c4a256601..02a214691b0 100644 --- a/src/jdk.attach/macosx/native/libattach/VirtualMachineImpl.c +++ b/src/jdk.attach/macosx/native/libattach/VirtualMachineImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,24 +23,20 @@ * questions. */ -#include "jni.h" #include "jni_util.h" -#include "jvm.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include +#include #include +#include #include +#include +#include +#include +#include +#include #include "sun_tools_attach_VirtualMachineImpl.h" @@ -144,6 +140,8 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions uid_t uid, gid; int res; + memset(&sb, 0, sizeof(struct stat)); + /* * Check that the path is owned by the effective uid/gid of this * process. Also check that group/other access is not allowed. @@ -161,21 +159,21 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions char msg[100]; jboolean isError = JNI_FALSE; if (sb.st_uid != uid) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file should be owned by the current user (which is %d) but is owned by %d", uid, sb.st_uid); isError = JNI_TRUE; } else if (sb.st_gid != gid) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file's group should be the current group (which is %d) but the group is %d", gid, sb.st_gid); isError = JNI_TRUE; } else if ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file should only be readable and writable by the owner but has 0%03o access", sb.st_mode & 0777); isError = JNI_TRUE; } if (isError) { char buf[256]; - jio_snprintf(buf, sizeof(buf)-1, "well-known file %s is not secure: %s", p, msg); + snprintf(buf, sizeof(buf), "well-known file %s is not secure: %s", p, msg); JNU_ThrowIOException(env, buf); } } else { @@ -201,6 +199,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_close (JNIEnv *env, jclass cls, jint fd) { int res; + shutdown(fd, SHUT_RDWR); RESTARTABLE(close(fd), res); } @@ -255,8 +254,8 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_write RESTARTABLE(write(fd, buf, len), n); if (n > 0) { - off += n; - remaining -= n; + off += n; + remaining -= n; } else { JNU_ThrowIOExceptionWithLastError(env, "write"); return; diff --git a/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java index bd76097f079..62ebf4c8585 100644 --- a/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -225,7 +225,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { return fd; } - // On Solaris/Linux a simple handshake is used to start the attach mechanism + // On Solaris a simple handshake is used to start the attach mechanism // if not already started. The client creates a .attach_pid file in the // target VM's working directory (or temporary directory), and the SIGQUIT // handler checks for the file. diff --git a/src/jdk.attach/solaris/native/libattach/VirtualMachineImpl.c b/src/jdk.attach/solaris/native/libattach/VirtualMachineImpl.c index f72bdeb3833..67164a517bd 100644 --- a/src/jdk.attach/solaris/native/libattach/VirtualMachineImpl.c +++ b/src/jdk.attach/solaris/native/libattach/VirtualMachineImpl.c @@ -22,20 +22,19 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "jni.h" #include "jni_util.h" -#include "jvm.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "sun_tools_attach_VirtualMachineImpl.h" @@ -105,6 +104,8 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions uid_t uid, gid; int res; + memset(&sb, 0, sizeof(struct stat64)); + /* * Check that the path is owned by the effective uid/gid of this * process. Also check that group/other access is not allowed. @@ -122,21 +123,21 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions char msg[100]; jboolean isError = JNI_FALSE; if (sb.st_uid != uid) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file should be owned by the current user (which is %d) but is owned by %d", uid, sb.st_uid); isError = JNI_TRUE; } else if (sb.st_gid != gid) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file's group should be the current group (which is %d) but the group is %d", gid, sb.st_gid); isError = JNI_TRUE; } else if ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) { - jio_snprintf(msg, sizeof(msg)-1, + snprintf(msg, sizeof(msg), "file should only be readable and writable by the owner but has 0%03o access", sb.st_mode & 0777); isError = JNI_TRUE; } if (isError) { char buf[256]; - jio_snprintf(buf, sizeof(buf)-1, "well-known file %s is not secure: %s", p, msg); + snprintf(buf, sizeof(buf), "well-known file %s is not secure: %s", p, msg); JNU_ThrowIOException(env, buf); } } else { diff --git a/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c b/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c index d7bdcc12fcb..ea89e42f8b5 100644 --- a/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c +++ b/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,16 +22,15 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + +#include "jni_util.h" + #include #include #include -#include "jni.h" -#include "jni_util.h" - #include "sun_tools_attach_VirtualMachineImpl.h" - /* kernel32 */ typedef HINSTANCE (WINAPI* GetModuleHandleFunc) (LPCTSTR); typedef FARPROC (WINAPI* GetProcAddressFunc)(HMODULE, LPCSTR); @@ -303,9 +302,7 @@ JNIEXPORT jlong JNICALL Java_sun_tools_attach_VirtualMachineImpl_createPipe LocalFree(sa.lpSecurityDescriptor); if (hPipe == INVALID_HANDLE_VALUE) { - char msg[256]; - _snprintf(msg, sizeof(msg), "CreateNamedPipe failed: %d", GetLastError()); - JNU_ThrowIOExceptionWithLastError(env, msg); + JNU_ThrowIOExceptionWithLastError(env, "CreateNamedPipe failed"); } return (jlong)hPipe; } @@ -318,7 +315,7 @@ JNIEXPORT jlong JNICALL Java_sun_tools_attach_VirtualMachineImpl_createPipe JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_closePipe (JNIEnv *env, jclass cls, jlong hPipe) { - CloseHandle( (HANDLE)hPipe ); + CloseHandle((HANDLE)hPipe); } /* @@ -430,7 +427,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_enqueue if ((*env)->ExceptionOccurred(env)) return; } } - for (i=argsLen; i