8325621: Improve jspawnhelper version checks
Reviewed-by: erikj, shade, rriggs, ihse
This commit is contained in:
parent
c879627dbd
commit
a232e8fb4e
@ -78,7 +78,8 @@ ifeq ($(call isTargetOsType, unix), true)
|
|||||||
NAME := jspawnhelper, \
|
NAME := jspawnhelper, \
|
||||||
SRC := $(TOPDIR)/src/$(MODULE)/unix/native/jspawnhelper, \
|
SRC := $(TOPDIR)/src/$(MODULE)/unix/native/jspawnhelper, \
|
||||||
OPTIMIZATION := LOW, \
|
OPTIMIZATION := LOW, \
|
||||||
CFLAGS := $(CFLAGS_JDKEXE) -I$(TOPDIR)/src/$(MODULE)/unix/native/libjava, \
|
CFLAGS := $(CFLAGS_JDKEXE) $(VERSION_CFLAGS) \
|
||||||
|
-I$(TOPDIR)/src/$(MODULE)/unix/native/libjava, \
|
||||||
EXTRA_OBJECT_FILES := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjava/childproc$(OBJ_SUFFIX), \
|
EXTRA_OBJECT_FILES := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjava/childproc$(OBJ_SUFFIX), \
|
||||||
LDFLAGS := $(LDFLAGS_JDKEXE), \
|
LDFLAGS := $(LDFLAGS_JDKEXE), \
|
||||||
OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
|
OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
|
||||||
|
@ -59,6 +59,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
|
|||||||
CFLAGS := $(CFLAGS_JDKLIB) \
|
CFLAGS := $(CFLAGS_JDKLIB) \
|
||||||
$(LIBJAVA_CFLAGS), \
|
$(LIBJAVA_CFLAGS), \
|
||||||
jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \
|
jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \
|
||||||
|
ProcessImpl_md.c_CFLAGS := $(VERSION_CFLAGS), \
|
||||||
DISABLED_WARNINGS_gcc_ProcessImpl_md.c := unused-result, \
|
DISABLED_WARNINGS_gcc_ProcessImpl_md.c := unused-result, \
|
||||||
LDFLAGS := $(LDFLAGS_JDKLIB) \
|
LDFLAGS := $(LDFLAGS_JDKLIB) \
|
||||||
$(call SET_SHARED_LIBRARY_ORIGIN), \
|
$(call SET_SHARED_LIBRARY_ORIGIN), \
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -50,6 +51,10 @@ extern int errno;
|
|||||||
#define ERR_PIPE 2
|
#define ERR_PIPE 2
|
||||||
#define ERR_ARGS 3
|
#define ERR_ARGS 3
|
||||||
|
|
||||||
|
#ifndef VERSION_STRING
|
||||||
|
#error VERSION_STRING must be defined
|
||||||
|
#endif
|
||||||
|
|
||||||
void error (int fd, int err) {
|
void error (int fd, int err) {
|
||||||
if (write (fd, &err, sizeof(err)) != sizeof(err)) {
|
if (write (fd, &err, sizeof(err)) != sizeof(err)) {
|
||||||
/* Not sure what to do here. I have no one to speak to. */
|
/* Not sure what to do here. I have no one to speak to. */
|
||||||
@ -59,6 +64,7 @@ void error (int fd, int err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void shutItDown() {
|
void shutItDown() {
|
||||||
|
fprintf(stdout, "jspawnhelper version %s\n", VERSION_STRING);
|
||||||
fprintf(stdout, "This command is not for general use and should ");
|
fprintf(stdout, "This command is not for general use and should ");
|
||||||
fprintf(stdout, "only be run as the result of a call to\n");
|
fprintf(stdout, "only be run as the result of a call to\n");
|
||||||
fprintf(stdout, "ProcessBuilder.start() or Runtime.exec() in a java ");
|
fprintf(stdout, "ProcessBuilder.start() or Runtime.exec() in a java ");
|
||||||
@ -141,19 +147,29 @@ int main(int argc, char *argv[]) {
|
|||||||
int r, fdinr, fdinw, fdout;
|
int r, fdinr, fdinw, fdout;
|
||||||
sigset_t unblock_signals;
|
sigset_t unblock_signals;
|
||||||
|
|
||||||
if (argc != 2) {
|
|
||||||
shutItDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
jtregSimulateCrash(0, 4);
|
jtregSimulateCrash(0, 4);
|
||||||
#endif
|
#endif
|
||||||
r = sscanf (argv[1], "%d:%d:%d", &fdinr, &fdinw, &fdout);
|
|
||||||
|
if (argc != 3) {
|
||||||
|
fprintf(stdout, "Incorrect number of arguments: %d\n", argc);
|
||||||
|
shutItDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(argv[1], VERSION_STRING) != 0) {
|
||||||
|
fprintf(stdout, "Incorrect Java version: %s\n", argv[1]);
|
||||||
|
shutItDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
r = sscanf (argv[2], "%d:%d:%d", &fdinr, &fdinw, &fdout);
|
||||||
if (r == 3 && fcntl(fdinr, F_GETFD) != -1 && fcntl(fdinw, F_GETFD) != -1) {
|
if (r == 3 && fcntl(fdinr, F_GETFD) != -1 && fcntl(fdinw, F_GETFD) != -1) {
|
||||||
fstat(fdinr, &buf);
|
fstat(fdinr, &buf);
|
||||||
if (!S_ISFIFO(buf.st_mode))
|
if (!S_ISFIFO(buf.st_mode)) {
|
||||||
|
fprintf(stdout, "Incorrect input pipe\n");
|
||||||
shutItDown();
|
shutItDown();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
fprintf(stdout, "Incorrect FD array data: %s\n", argv[2]);
|
||||||
shutItDown();
|
shutItDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,6 +300,10 @@ Java_java_lang_ProcessImpl_init(JNIEnv *env, jclass clazz)
|
|||||||
#define WTERMSIG(status) ((status)&0x7F)
|
#define WTERMSIG(status) ((status)&0x7F)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef VERSION_STRING
|
||||||
|
#error VERSION_STRING must be defined
|
||||||
|
#endif
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
getBytes(JNIEnv *env, jbyteArray arr)
|
getBytes(JNIEnv *env, jbyteArray arr)
|
||||||
{
|
{
|
||||||
@ -488,7 +492,7 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
|
|||||||
pid_t resultPid;
|
pid_t resultPid;
|
||||||
int i, offset, rval, bufsize, magic;
|
int i, offset, rval, bufsize, magic;
|
||||||
char *buf, buf1[(3 * 11) + 3]; // "%d:%d:%d\0"
|
char *buf, buf1[(3 * 11) + 3]; // "%d:%d:%d\0"
|
||||||
char *hlpargs[3];
|
char *hlpargs[4];
|
||||||
SpawnInfo sp;
|
SpawnInfo sp;
|
||||||
|
|
||||||
/* need to tell helper which fd is for receiving the childstuff
|
/* need to tell helper which fd is for receiving the childstuff
|
||||||
@ -497,11 +501,13 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
|
|||||||
snprintf(buf1, sizeof(buf1), "%d:%d:%d", c->childenv[0], c->childenv[1], c->fail[1]);
|
snprintf(buf1, sizeof(buf1), "%d:%d:%d", c->childenv[0], c->childenv[1], c->fail[1]);
|
||||||
/* NULL-terminated argv array.
|
/* NULL-terminated argv array.
|
||||||
* argv[0] contains path to jspawnhelper, to follow conventions.
|
* argv[0] contains path to jspawnhelper, to follow conventions.
|
||||||
* argv[1] contains the fd string as argument to jspawnhelper
|
* argv[1] contains the version string as argument to jspawnhelper
|
||||||
|
* argv[2] contains the fd string as argument to jspawnhelper
|
||||||
*/
|
*/
|
||||||
hlpargs[0] = (char*)helperpath;
|
hlpargs[0] = (char*)helperpath;
|
||||||
hlpargs[1] = buf1;
|
hlpargs[1] = VERSION_STRING;
|
||||||
hlpargs[2] = NULL;
|
hlpargs[2] = buf1;
|
||||||
|
hlpargs[3] = NULL;
|
||||||
|
|
||||||
/* Following items are sent down the pipe to the helper
|
/* Following items are sent down the pipe to the helper
|
||||||
* after it is spawned.
|
* after it is spawned.
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8325567
|
* @bug 8325567 8325621
|
||||||
* @requires (os.family == "linux") | (os.family == "aix") | (os.family == "mac")
|
* @requires (os.family == "linux") | (os.family == "aix") | (os.family == "mac")
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @run driver JspawnhelperWarnings
|
* @run driver JspawnhelperWarnings
|
||||||
@ -47,11 +47,30 @@ public class JspawnhelperWarnings {
|
|||||||
OutputAnalyzer oa = new OutputAnalyzer(p);
|
OutputAnalyzer oa = new OutputAnalyzer(p);
|
||||||
oa.shouldHaveExitValue(1);
|
oa.shouldHaveExitValue(1);
|
||||||
oa.shouldContain("This command is not for general use");
|
oa.shouldContain("This command is not for general use");
|
||||||
|
if (nArgs != 2) {
|
||||||
|
oa.shouldContain("Incorrect number of arguments");
|
||||||
|
} else {
|
||||||
|
oa.shouldContain("Incorrect Java version");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void testVersion() throws Exception {
|
||||||
|
String[] args = new String[3];
|
||||||
|
args[0] = Paths.get(System.getProperty("java.home"), "lib", "jspawnhelper").toString();
|
||||||
|
args[1] = "wrongVersion";
|
||||||
|
args[2] = "1:1:1";
|
||||||
|
Process p = ProcessTools.startProcess("jspawnhelper", new ProcessBuilder(args));
|
||||||
|
OutputAnalyzer oa = new OutputAnalyzer(p);
|
||||||
|
oa.shouldHaveExitValue(1);
|
||||||
|
oa.shouldContain("This command is not for general use");
|
||||||
|
oa.shouldContain("Incorrect Java version: wrongVersion");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
for (int nArgs = 0; nArgs < 10; nArgs++) {
|
for (int nArgs = 0; nArgs < 10; nArgs++) {
|
||||||
tryWithNArgs(nArgs);
|
tryWithNArgs(nArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user